SpikeInterface / SpikeInterface/spikeinterface

NWBFile cannot be passed as file argument to NwbRecordingExtractor

Open
#4,179 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extractors
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:

  1. Saving the processed traces in a temporary file on disk
  2. Close and delete the SpikeInterface recording object
    recording._nwbfile.get_read_io().close()
    recording._nwbfile.get_read_io()._file.close()
    del recording
    
  3. Load the temporary file with SpikeInterface as a new recording object
  4. Reopen the same NWB file with pynwb in r+ mode
  5. Write the traces stored on disk in the NWB file
  6. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.