sam81 / pybdf

Python module to read Biosemi BDF files
GNU General Public License v3.0
9 stars 4 forks source link

unicode channel labels breaks getData() method. #3

Closed gogolama closed 6 years ago

gogolama commented 6 years ago

I received a bdf file containing eeg recordings on 32 channels. Reading the file using pybdf works fine and calling bdfRec.chanLabels gives the following output: [u'A1', u'A2', u'A3', u'A4', u'A5', u'A6', u'A7', u'A8', u'A9', u'A10', u'A11', u'A12', u'A13', u'A14', u'A15', u'A16', u'A17', u'A18', u'A19', u'A20', u'A21', u'A22', u'A23', u'A24', u'A25', u'A26', u'A27', u'A28', u'A29', u'A30', u'A31', u'A32', u'EXG1', u'EXG2', u'EXG3', u'EXG4', u'EXG5', u'EXG6', u'EXG7', u'EXG8', u'Status'] So evidently the file is using unicode labels for each channel. Next, calling rec = bdfRec.getData() breaks throwing following error:

` TypeErrorTraceback (most recent call last)

in () ` ` ----> 1 rec = bdfRec.getData() ` ` /homes/USER/.local/lib/python2.7/site-packages/pybdf.pyc in getData(self, beginning, end, channels, eventTable, trigChan, sysCodeChan) ` ` 224 chanLabels = [] ` ` 225 for i in range(len(channels)): ` ` --> 226 chanLabels.append(self.dataChanLabels[channels[i]]) ` ` 227 nChannelsToRead = len(channels) ` ` 228 ` ` TypeError: list indices must be integers, not unicode `
sam81 commented 6 years ago

Hi, thanks for reporting this. I'll look into this when I have some time, although I've moved all my EEG data processing code to Julia so I'm not really using this python code myself anymore.

I noticed you're using python2. Does the issue occur also with python3?

sam81 commented 6 years ago

I can confirm that with python2 the channel labels are returned as unicode. bdfRec.getData() called without additional arguments works fine, but the program will throw an error if you try retrieve a specific channel passing the non-unicode label (e.g. bdfRec.getData(channels=['A14'])). An easy fix for your issue would be to use bdfRec.getData(channels=[unicode('A14')]).

With python3 the issue does not occur altogether.

I hope this helps. I'm afraid I don't intend to change the code to fix this issue because 1) things work fine in python3 and python2 is already legacy 2) performing a conversion from unicode to ascii in pybdf could break things for people who might use unicode characters for channel labels.

gogolama commented 6 years ago

Thats great, thanks for the update on this. Cheers!