open-ephys / open-ephys-python-tools

Python code for interacting with the Open Ephys GUI
MIT License
29 stars 17 forks source link

NwbRecording parsing dataset name -- ValueError: invalid literal for int() with base 10 #30

Closed benjamin-heasly closed 5 months ago

benjamin-heasly commented 6 months ago

Greetings! I have a minor little goblin to report/share!

I'm reading events from an NWB file like this:

from open_ephys.analysis import Session
directory = './my_data/nwb'
session = Session(directory)

recording = session.recordnodes[0].recordings[0]
recording.events()

And getting this error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/x/miniconda3/envs/oe-python-plugin/lib/python3.10/site-packages/open_ephys/analysis/recording.py", line 87, in events
    self.load_events()
  File "/home/x/miniconda3/envs/oe-python-plugin/lib/python3.10/site-packages/open_ephys/analysis/formats/NwbRecording.py", line 146, in load_events
    processor_id = int(dataset.split('.')[0].split('-')[1])
ValueError: invalid literal for int() with base 10: 'DAQmx'

That DAQmx string comes from the dataset name NI-DAQmx-101.PXIe-6363.TTL. I think maybe NwbRecording is not expecting a processor name itself to contain a hyphen -, and so picking the wrong string part out of the dataset name.

A possible fix (and/or workaround) might be to look for the last string part instead of the second one?

processor_id = int(dataset.split('.')[0].split('-')[-1])

Thank you for the sweet tools!

jsiegle commented 6 months ago

Yeah, that should work! I will make that change and push an updated version to PyPI.

benjamin-heasly commented 5 months ago

I'm using 0.1.8 now, thank you!