Commit 5cdd13a3 authored by Javier Quinteros's avatar Javier Quinteros
Browse files

Bugfix: Check that the channel exists before reading it

In some experiments, the number of channels was changed after a restart (see issue #25 ).
parent 7277b6a8
......@@ -956,12 +956,23 @@ class TDMS(object):
for ch in channels:
result[ch] = np.zeros((numsamples,), dtype=self.__datatype)
# Collect potential errors for later logging
problematicchannels = set()
for sample in range(numsamples):
# Read from all channels and select the specific one with an index (channel)
allchannels = np.fromfile(self.__fi, dtype=self.__datatype, count=self.numchannels)
for ch in channels:
result[ch][sample] = allchannels[ch]
for ch in channels:
# Check that the channels to read actually exists
# Some experiments were found in which after restart there are less channels than at the beginning
if ch < len(allchannels):
result[ch][sample] = allchannels[ch]
else:
problematicchannels.add(ch)
if len(problematicchannels):
logs.error('Problems with channels: %s' % ','.join(map(str, problematicchannels)))
# Update the current sample number based on the number of components read
self.__samplecur += numsamples
......
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