Commit 5ea4ded3 authored by Javier Quinteros's avatar Javier Quinteros

Process a whole channel first through all files

parent c838fce4
......@@ -80,6 +80,10 @@ class TDMS(object):
if self.__twstart < self.__available[0]['dt']:
self.__twstart = self.__available[0]['dt']
# Keep the values in case we need to reset them
self.__origstarttime = self.__twstart
self.__origendtime = self.__twend
# What should we iterate? D: Data; M: Metadata
self.iterate = iterate
......@@ -201,6 +205,12 @@ class TDMS(object):
self.readMetadata()
def resetcurrenttime(self):
self.__twstart = self.__origstarttime
self.__twend = self.__origendtime
self.__currentfile = None
self.__select_file()
def __enter__(self):
self.__select_file()
return self
......@@ -219,7 +229,7 @@ class TDMS(object):
for obj in range(numObjects):
# channelSize = 0
objPath = self.__readstring()
logs.debug('Object %s: %s' % (obj, objPath))
# logs.debug('Object %s: %s' % (obj, objPath))
self.metadata[obj] = {'path': objPath}
......@@ -283,6 +293,10 @@ class TDMS(object):
self.endtime = self.starttime + datetime.timedelta(seconds=(self.samples-1)/self.sampling_rate)
self.__samplestart = max(floor((self.__twstart - self.starttime).total_seconds() * self.sampling_rate), 0)
# Should I readjust __twstart to align it exactly with the time of the samples?
# print(self.__twstart, self.starttime + datetime.timedelta(seconds=self.__samplestart/self.sampling_rate))
self.__twstart = self.starttime + datetime.timedelta(seconds=self.__samplestart/self.sampling_rate)
self.__samplecur = self.__samplestart
if (self.__twend is None) or (self.__twend >= self.endtime):
......@@ -327,10 +341,12 @@ class TDMS(object):
else:
raise Exception('Encoding type not supported to export in MiniSEED!')
while (self.__twend is None) or (self.__twstart < self.__twend):
# Loop through channels
while self.__samplecur <= self.__sampleend:
for ch in range(self.__chstart, self.__chstop+1, self.__chstep):
for ch in range(self.__chstart, self.__chstop + 1, self.__chstep):
self.resetcurrenttime()
while (self.__twend is None) or (self.__twstart < self.__twend):
# Loop through channels
while self.__samplecur <= self.__sampleend:
data = self.__readdata(channel=ch)
stats = {'network': 'XX', 'station': '%05d' % ch, 'location': '',
'channel': 'FH1', 'npts': len(data),
......@@ -338,18 +354,19 @@ class TDMS(object):
'starttime': UTCDateTime(self.__twstart),
'mseed': {'byteorder': self.__endian,
'reclen': 512}}
logs.debug('Data length: %d; First component: %s' % (len(data), data[0]))
logs.info('Stats: %s' % stats)
logs.info('Data length: %d; First component: %s' % (len(data), data[0]))
yield (data, stats)
# Read data in blocks of size self.__MAXSAMPLES
self.__samplecur += self.__MAXSAMPLES
# Read data in blocks
self.__samplecur += len(data)
# No more data in this file. Skip to the next one.
self.__currentfile += 1
try:
self.__select_file()
except IndexError:
return
# No more data in this file. Skip to the next one.
self.__currentfile += 1
try:
self.__select_file()
except IndexError:
break
def __iter_metadata__(self):
# Metadata
......
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