SpikeInterface / SpikeInterface/spikeinterface
NWBFile cannot be passed as file argument to NwbRecordingExtractor
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 847
- Forks
- 280
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 29
Description
Hi, everyone! :)
I am interested in opening a NWB file containing my acquisition traces with SpikeInterface. However, it seems that the read_file_from_backend function called during the NwbRecordingExtractor object initialization always opens the NWB recording in mode="r" (hardcoded), disabling any chance to edit the NWB file itself. Since no mode parameter is exposed by NwbRecordingExtractor, I tried to use the file argument instead of file_path, which should be able to accept an "in-memory representation of the NWB file" (according to the docstring). However, when I try to pass a pynwb.file.NWBFile object read via pynwb library and correctly opened with mode="r+", the initialization fails, as the NWBFile instance is fed as input to h5py.File(), regardless of the use_pynwb parameter.
I am not sure this is the intended behaviour and if yes, then I believe it would be important to enable the opening of NWB files in modes that enable writing. In my case, I read raw acquisitions, then I process them with SpikeInterface (e.g., LFP band isolation, downsampling, ...) and I would like to save the new time series back in the original NWB file. I am currently able to do so, but it involves:
- Saving the processed traces in a temporary file on disk
- Close and delete the SpikeInterface recording object
recording._nwbfile.get_read_io().close() recording._nwbfile.get_read_io()._file.close() del recording - Load the temporary file with SpikeInterface as a new recording object
- Reopen the same NWB file with pynwb in
r+mode - Write the traces stored on disk in the NWB file
- Delete the temporary saving file
As you can imagine, the whole processes is quite tedious.
Thank you in advance for your help and support!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with NwbRecordingExtractor initialization and the read_file_from_backend call described in the report, including the file_path, file, mode, and use_pynwb handling. Trace how a pynwb.file.NWBFile reaches h5py.File(). Done means the documented file argument works with an already opened NWBFile and writing workflows no longer require the temporary-file workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100