Commit ffb87982 authored by Javier Quinteros's avatar Javier Quinteros

Simplify code of __iter_data

parent 0f2a23fb
......@@ -612,43 +612,9 @@ class TDMS(object):
# Data
logs = logging.getLogger('Iterate Data')
# Data is stored with values from one channel in a continuous array
if not self.__hasInterleavedData:
# for ch in range(self.__chstart, self.__chstop + 1, self.__chstep):
for ch in self.__channels:
self.__resetcurrenttime()
while (self.__twend is None) or (self.__twstart < self.__twend):
# Loop through channels
while self.__samplecur <= self.__sampleend:
data = self.__readdata(channels=[ch])
stats = {'network': 'XX', 'station': '%05d' % ch, 'location': '',
'channel': 'FH1', 'npts': len(data[ch]),
'sampling_rate': self.sampling_rate,
'starttime': UTCDateTime(self.__twstart),
'mseed': {'byteorder': self.__endian,
'reclen': 512}}
# logs.debug('Stats: %s' % stats)
logs.debug('Data length: %d; First component: %s' % (len(data[ch]), data[ch][0]))
yield data[ch], stats
# Update the current sample number
self.__samplecur += len(data[ch])
# No more data in this file. Skip to the next one.
self.__currentfile += 1
try:
self.__search_data()
except IndexError:
break
else:
# channels = list(range(self.__chstart, self.__chstop + 1, self.__chstep))
while (self.__twend is None) or (self.__twstart < self.__twend):
# Loop through channels
while self.__samplecur <= self.__sampleend:
data = self.__readdata(channels=self.__channels)
# for ch in channels:
# Loop through channels
for ch in self.__channels:
stats = {'network': 'XX', 'station': '%05d' % ch, 'location': '',
'channel': 'FH1', 'npts': len(data[ch]),
......@@ -656,14 +622,9 @@ class TDMS(object):
'starttime': UTCDateTime(self.__twstart),
'mseed': {'byteorder': self.__endian,
'reclen': 512}}
# logs.debug('Stats: %s' % stats)
logs.debug('Data length: %d; First component: %s' % (len(data[ch]), data[ch][0]))
yield data[ch], stats
# Update the current sample number based on first channel
# We assume that all chunks of different channels have the same length
self.__samplecur += len(data[self.__channels[0]])
# No more data in this file. Skip to the next one.
self.__currentfile += 1
try:
......@@ -758,7 +719,8 @@ class TDMS(object):
return struct.unpack('%cI' % self.__endian, self.__fi.read(4))[0]
def __readdata(self, channels=None):
"""Read a chunk of data from the specified channels
"""Read a chunk of data from the specified channels.
Update the attribute __samplecur
:param channels: List of channel numbers to read data from
:type channels: list
......@@ -792,6 +754,10 @@ class TDMS(object):
# Read all selected data from the channel in one step
result[ch] = np.fromfile(self.__fi, dtype=self.__datatype, count=numsamples)
# Update the current sample number based on the number of components read
self.__samplecur += numsamples
return result
# Seek where the raw data starts and add the offset to the first
......@@ -809,5 +775,7 @@ class TDMS(object):
for ch in channels:
result[ch][sample] = allchannels[ch]
# print(result)
# Update the current sample number based on the number of components read
self.__samplecur += numsamples
return result
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