Skip to content

Commit 3b164b5

Browse files
authored
BUGFIXES: handling filenames, reading float values, and event annotation (#6)
- handle . characters in file paths - handle floating point numbers in header fields - fix: handle fFrequency=0 case before adding fFrequency to datainfo dict - fix: wrong lines selected in annotation slice
1 parent 5645c4b commit 3b164b5

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

curryreader.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def read(inputfilename='', plotdata = 1, verbosity = 2):
8585
filename = os.path.basename(filepath)
8686

8787
try:
88-
basename, extension = filepath.split(".", maxsplit=1)
88+
basename, extension = filepath.rsplit(".", maxsplit=1)
8989
except:
9090
raise Exception("Unsupported file, choose a cdt or dat file")
9191

@@ -167,8 +167,10 @@ def read(inputfilename='', plotdata = 1, verbosity = 2):
167167
text = contents[ixstart:ixstop].strip()
168168
if text == 'ASCII' or text == 'CHAN' : # test for alphanumeric values
169169
a[i] = 1
170-
elif text.isnumeric() :
170+
try:
171171
a[i] = float(text) # assign if it was a number
172+
except ValueError:
173+
pass
172174

173175
# derived variables. numbers (1) (2) etc are the token numbers
174176
nSamples = int(a[0] + a[int(0 + nt / 2)])
@@ -179,13 +181,13 @@ def read(inputfilename='', plotdata = 1, verbosity = 2):
179181
nASCII = int(a[5] + a[int(5 + nt / 2)])
180182
nMultiplex = int(a[6] + a[int(6 + nt / 2)])
181183
fSampleTime = a[7] + a[int(7 + nt / 2)]
182-
183-
datainfo = { "samples" : nSamples, "channels" : nChannels, "trials" : nTrials, "samplingfreq" : fFrequency }
184-
log.info('Number of samples = %s, number of channels = %s, number of trials/epochs = %s, sampling frequency = %s Hz', str(nSamples), str( nChannels), str(nTrials), str(fFrequency))
185184

186185
if fFrequency == 0 or fSampleTime != 0:
187186
fFrequency = 1000000 / fSampleTime
188187

188+
datainfo = { "samples" : nSamples, "channels" : nChannels, "trials" : nTrials, "samplingfreq" : fFrequency }
189+
log.info('Number of samples = %s, number of channels = %s, number of trials/epochs = %s, sampling frequency = %s Hz', str(nSamples), str( nChannels), str(nTrials), str(fFrequency))
190+
189191
# try to guess number of samples based on datafile size
190192
if nSamples < 0:
191193
if nASCII == 1:
@@ -426,7 +428,7 @@ def read(inputfilename='', plotdata = 1, verbosity = 2):
426428
tixstop = contents.find('REMARK_LIST END_LIST')
427429

428430
if tixstart != -1 and tixstop != 1 :
429-
annotations = contents[tixstart:tixstop - 1].splitlines()
431+
annotations = contents[tixstart+1:tixstop].splitlines()
430432

431433
log.info('Found events')
432434

0 commit comments

Comments
 (0)