TheChymera / neuralynx_nwb

Neuralynx to NWB converstion scripts (ideally to be upstreamed)
0 stars 0 forks source link

Multiple streams and `spikeinterface.extractors.NeuralynxRecordingExtractor` #8

Open TheChymera opened 1 year ago

TheChymera commented 1 year ago

So for some neuralynx data directories (e.g. the one we're trying to deal with at the moment), there 2 separate streams for extracellular ephys. The warning is about 3 but the third one is the wheel which @manimoh is trying to process separately. Apparently those streams just contain different channels, because more channels were recorded than what one input card alone supports. Any idea how we can get them to be merged?

This is the error again, for reference purposes:

[deco]~/src/neuralynx_nwb ❱ python -c "from neuralynx_nwb import newconvert; newconvert.reposit_data()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/chymera/src/neuralynx_nwb/neuralynx_nwb/newconvert.py", line 23, in reposit_data
    session_dir = os.path.join(data_dir, data_selection)
  File "/usr/lib/python3.10/site-packages/neuroconv/datainterfaces/ecephys/neuralynx/neuralynxdatainterface.py", line 17, in __init__
    super().__init__(folder_path=folder_path, verbose=verbose, all_annotations=True)
  File "/usr/lib/python3.10/site-packages/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py", line 28, in __init__
    self.recording_extractor = self.Extractor(**source_data)
  File "/usr/lib/python3.10/site-packages/spikeinterface/extractors/neoextractors/neuralynx.py", line 29, in __init__
    NeoBaseRecordingExtractor.__init__(self, stream_id=stream_id,
  File "/usr/lib/python3.10/site-packages/spikeinterface/extractors/neoextractors/neobaseextractor.py", line 59, in __init__
    raise ValueError(f"This reader have several streams: \nNames: {stream_names}\nIDs: {stream_ids}. "
ValueError: This reader have several streams:
Names: ['Stream (rate,#packet,t0): (32000.0, 253845, 1626434026469696)', 'Stream (rate,#packet,t0): (32000.0, 253845, 1626434026469680)', 'Stream (rate,#packet,t0): (2000.0, 15866, 1626434026470148)']
IDs: ['0', '1', '2']. Specify it with the 'stram_name' or 'stream_id' arguments
[deco]~/src/neuralynx_nwb ❱ cat neuralynx_nwb/newconvert.py
import os
from neuroconv.datainterfaces import NeuralynxRecordingInterface
from neuroconv.tools.spikeinterface import write_recording

def reposit_data(
    data_dir='~/.local/share/datalad/',
    data_selection='vStr_phase_stim/M235/M235-2021-07-16/',
    lab_name='MVDMLab',
    institution='Dartmouth College',
    keywords=[
        'DANDI Pilot',
        ],
    experimenter='Manish Mohapatra',
    experiment_description='...',
    debug=True,
    session_description='Extracellular ephys recording in the ventral Striatum',
    keep_original_times=True,
    output_filename='neuralynx_nwb_testfile',
    ):

    data_dir = os.path.abspath(os.path.expanduser(data_dir))
    session_dir = os.path.join(data_dir, data_selection)
    interface = NeuralynxRecordingInterface(folder_path=session_dir, verbose=False)
TheChymera commented 1 year ago

@CodyCBakerPhD any ideas how we can merge the two streams?

CodyCBakerPhD commented 1 year ago

Apparently those streams just contain different channels, because more channels were recorded than what one input card alone supports.

any ideas how we can merge the two streams?

So what you're specifically asking is - you want a single ElectricalSeries that combines the main two streams from Neuralynx (not including the wheel activity) because they really ought to have been the same 'device' but were separated due to hardware reasons?

And you are able to read that data from each stream as a separate RecordingExtractor object?

For this I will rope in @alejoe91 to this conversation - if he doesn't reply here we can open an issue specific to SpikeInterface (or ask on their slack channel) - but it should be possible to create a single RecordingExtractor object by combining the other two, I just don't recall what the modern syntax for it is

TheChymera commented 1 year ago

@CodyCBakerPhD yes to the first two questions. @alejoe91 any advice on this?

CodyCBakerPhD commented 1 year ago

Or @h-mayorquin probably knows

alejoe91 commented 1 year ago

You can use the aggregate_channels function :) https://spikeinterface.readthedocs.io/en/latest/modules/core.html#manipulating-objects-slicing-aggregating

h-mayorquin commented 1 year ago

Did @alejoe91 sugestion worked for you @TheChymera ?