Commit dcb919d8 authored by Javier Quinteros's avatar Javier Quinteros

Remove chstart, chstop and chstep from the attributes of TDMS

Work only with a list "channels"
parent 3d6f80b1
......@@ -41,7 +41,8 @@ class TDMS(object):
# Create a buffer space to store the signal coefficients to be
# convoluted during the decimation
for channel in range(self.__chstart, self.__chstop + 1, self.__chstep):
# for channel in range(self.__chstart, self.__chstop + 1, self.__chstep):
for channel in self.__channels:
logging.debug('Create empty buffers')
self.__buffer[channel] = None
......@@ -88,9 +89,10 @@ class TDMS(object):
self.__decimate = decimate
# Channel from and to
self.__chstart = chstart
self.__chstop = chstop
self.__chstep = chstep
# self.__chstart = chstart
# self.__chstop = chstop
# self.__chstep = chstep
self.__channels = list(range(chstart, chstop+1, chstep))
# Time window selection
self.__twstart = starttime
......@@ -140,11 +142,6 @@ class TDMS(object):
# Keys will be channel number and the values will be np.arrays
self.__buffer = dict()
# Create a buffer space to store the signal coefficients to be
# convoluted during the decimation
# for channel in range(self.__chstart, self.__chstop + 1, self.__chstep):
# self.__buffer[channel] = None
# Datatype of each channel
self.__datatypes = dict()
......@@ -441,15 +438,21 @@ class TDMS(object):
channellength = ((self.__segmentOffset - self.__dataOffset)/numchannels/self.__data2mask[datatype][1])
logs.debug('Length of channel: %d' % channellength)
if self.__chstart >= numchannels:
logs.error('Cannot export from channel %s. Only %s channels present.' % (self.__chstart, numchannels))
raise IndexError
# Check that the list of channels include only valid IDs
for idx, chnum in reversed(list(enumerate(self.__channels))):
if chnum >= numchannels:
logs.warning('Cannot export from channel %s. Only %s channels present.' % (chnum, numchannels))
del self.__channels[idx]
# Raise an exception if there are no channels selected
if not len(self.__channels):
raise Exception('No valid channel IDs selected!')
if self.__chstop is None:
self.__chstop = numchannels-1
elif self.__chstop >= numchannels:
logs.warning('Resetting chstop to %s' % (numchannels-1))
self.__chstop = numchannels-1
# if self.__chstop is None:
# self.__chstop = numchannels-1
# elif self.__chstop >= numchannels:
# logs.warning('Resetting chstop to %s' % (numchannels-1))
# self.__chstop = numchannels-1
# New or changed objects
newObjects = struct.unpack('%cI' % self.__endian, self.__fi.read(4))[0]
......@@ -594,7 +597,8 @@ class TDMS(object):
# print(self.__currentfile, self.__twstart, self.starttime, self.__samplestart, self.__samplecur, self.__sampleend)
# 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 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):
......@@ -621,13 +625,14 @@ class TDMS(object):
except IndexError:
break
else:
channels = list(range(self.__chstart, self.__chstop + 1, self.__chstep))
# 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=channels)
for ch in channels:
data = self.__readdata(channels=self.__channels)
# for ch in channels:
for ch in self.__channels:
stats = {'network': 'XX', 'station': '%05d' % ch, 'location': '',
'channel': 'FH1', 'npts': len(data[ch]),
'sampling_rate': self.sampling_rate,
......@@ -640,7 +645,7 @@ class TDMS(object):
# 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[channels[0]])
self.__samplecur += len(data[self.__channels[0]])
# No more data in this file. Skip to the next one.
self.__currentfile += 1
......@@ -654,11 +659,12 @@ class TDMS(object):
# Metadata
# logs = logging.getLogger('Iterate Metadata')
channels = list(range(self.__chstart, self.__chstop+1, self.__chstep))
# channels = list(range(self.__chstart, self.__chstop+1, self.__chstep))
while (self.__twend is None) or (self.__twstart < self.__twend):
for obj in self.metadata:
if 'id' in self.metadata[obj] and self.metadata[obj]['id'] not in channels:
# if 'id' in self.metadata[obj] and self.metadata[obj]['id'] not in channels:
if 'id' in self.metadata[obj] and self.metadata[obj]['id'] not in self.__channels:
continue
yield self.metadata[obj]
......
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