Commit cdef13d0 authored by Javier Quinteros's avatar Javier Quinteros
Browse files

Filter samples returned based on time window selection.

Still working only on one file. Needs to be extended to more than one.
parent 1eb82c95
......@@ -235,9 +235,9 @@ class TDMS(object):
# Set the data type as numpy expects it
if self.__data2mask[datatype][0] == 'h':
self.datatype = 'int16'
self.datatype = '%ci2' % self.__endian
elif self.__data2mask[datatype][0] == 'f':
self.datatype = 'float32'
self.datatype = '%cf4' % self.__endian
else:
raise Exception('Data type not supported! (%s)' % self.__data2mask[datatype][0])
......@@ -361,24 +361,23 @@ class TDMS(object):
return result
def __readdata(self, channel=0):
numSamples = self.__sampleend - self.__samplestart + 1
if not self.hasInterleavedData:
# Seek where the channel starts
self.__fi.seek(self.__dataOffset + self.datatypesize*self.samples*channel, 0)
# Seek where the channel starts and add the offset to the first
# sample to read based in the time window selection
self.__fi.seek(self.__dataOffset + self.datatypesize*self.samples*channel + self.__samplestart, 0)
# Read all channel in one step
# FIXME Big/Little Endian not set!
# FIXME Start and end sample!
result = np.fromfile(self.__fi, dtype=self.datatype, count=self.samples)
# Read all selected data from the channel in one step
result = np.fromfile(self.__fi, dtype=self.datatype, count=numSamples)
else:
# Seek where the raw data starts
self.__fi.seek(self.__dataOffset, 0)
# Seek where the raw data starts and add the offset to the first
# sample to read based in the time window selection
self.__fi.seek(self.__dataOffset + self.__samplestart*self.datatypesize*self.numChannels, 0)
# Reserve the data for the result
result = np.zeros((self.samples,), dtype=self.datatype)
for ch in range(self.samples):
result = np.zeros((numSamples,), dtype=self.datatype)
for ch in range(numSamples):
# Read from all channels and select the specific one with an index (channel)
# FIXME Big/Little Endian not set!
# FIXME Start and end sample!
result[ch] = np.fromfile(self.__fi, dtype=self.datatype, count=self.numChannels)[channel]
return result
......@@ -406,7 +405,7 @@ def main():
dt = datetime.datetime(2019, 5, 8, 9, 37, 50)
td = TDMS(args.filename, directory=args.directory, iterate='D', chstart=800, chstop=801, chstep=5,
starttime=dt, endtime=dt+datetime.timedelta(seconds=10))
starttime=dt, endtime=dt+datetime.timedelta(seconds=0.01))
with td:
print(td.starttime, td.endtime)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment