Skip to content

Commit

Permalink
Merge branch 'main' into channel-ids-sortingview
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoe91 authored Jul 15, 2024
2 parents fcfd519 + cfffc6c commit e580139
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 46 deletions.
20 changes: 18 additions & 2 deletions src/spikeinterface/extractors/neoextractors/alphaomega.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,30 @@ class AlphaOmegaRecordingExtractor(NeoBaseRecordingExtractor):
If there are several streams, specify the stream name you want to load.
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

NeoRawIOClass = "AlphaOmegaRawIO"

def __init__(self, folder_path, lsx_files=None, stream_id="RAW", stream_name=None, all_annotations=False):
def __init__(
self,
folder_path,
lsx_files=None,
stream_id="RAW",
stream_name=None,
all_annotations: bool = False,
use_names_as_ids: bool = False,
):
neo_kwargs = self.map_to_neo_kwargs(folder_path, lsx_files)
NeoBaseRecordingExtractor.__init__(
self, stream_id=stream_id, stream_name=stream_name, all_annotations=all_annotations, **neo_kwargs
self,
stream_id=stream_id,
stream_name=stream_name,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)
self._kwargs.update(dict(folder_path=str(Path(folder_path).absolute()), lsx_files=lsx_files))

Expand Down
12 changes: 10 additions & 2 deletions src/spikeinterface/extractors/neoextractors/axona.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ class AxonaRecordingExtractor(NeoBaseRecordingExtractor):
The file path to load the recordings from.
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

NeoRawIOClass = "AxonaRawIO"

def __init__(self, file_path, all_annotations=False):
def __init__(self, file_path: str | Path, all_annotations: bool = False, use_names_as_ids: bool = False):
neo_kwargs = self.map_to_neo_kwargs(file_path)
NeoBaseRecordingExtractor.__init__(self, all_annotations=all_annotations, **neo_kwargs)
NeoBaseRecordingExtractor.__init__(
self,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)
self._kwargs.update({"file_path": str(Path(file_path).absolute())})

@classmethod
Expand Down
13 changes: 11 additions & 2 deletions src/spikeinterface/extractors/neoextractors/biocam.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class BiocamRecordingExtractor(NeoBaseRecordingExtractor):
If there are several streams, specify the stream name you want to load.
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

NeoRawIOClass = "BiocamRawIO"
Expand All @@ -40,11 +43,17 @@ def __init__(
electrode_width=None,
stream_id=None,
stream_name=None,
all_annotations=False,
all_annotations: bool = False,
use_names_as_ids: bool = False,
):
neo_kwargs = self.map_to_neo_kwargs(file_path)
NeoBaseRecordingExtractor.__init__(
self, stream_id=stream_id, stream_name=stream_name, all_annotations=all_annotations, **neo_kwargs
self,
stream_id=stream_id,
stream_name=stream_name,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)

# load probe from probeinterface
Expand Down
7 changes: 4 additions & 3 deletions src/spikeinterface/extractors/neoextractors/blackrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class BlackrockRecordingExtractor(NeoBaseRecordingExtractor):
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
If False, use default IDs inherited from Neo. If True, use channel names as IDs.
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

Expand All @@ -38,8 +39,8 @@ def __init__(
file_path,
stream_id=None,
stream_name=None,
all_annotations=False,
use_names_as_ids=False,
all_annotations: bool = False,
use_names_as_ids: bool = False,
):
neo_kwargs = self.map_to_neo_kwargs(file_path)
neo_kwargs["load_nev"] = False # Avoid loading spikes release in neo 0.12.0
Expand Down
14 changes: 12 additions & 2 deletions src/spikeinterface/extractors/neoextractors/ced.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,24 @@ class CedRecordingExtractor(NeoBaseRecordingExtractor):
If there are several streams, specify the stream name you want to load.
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

NeoRawIOClass = "CedRawIO"

def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False):
def __init__(
self, file_path, stream_id=None, stream_name=None, all_annotations: bool = False, use_names_as_ids: bool = False
):
neo_kwargs = self.map_to_neo_kwargs(file_path)
NeoBaseRecordingExtractor.__init__(
self, stream_id=stream_id, stream_name=stream_name, all_annotations=all_annotations, **neo_kwargs
self,
stream_id=stream_id,
stream_name=stream_name,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)
self._kwargs.update(dict(file_path=str(Path(file_path).absolute())))
self.extra_requirements.append("neo[ced]")
Expand Down
19 changes: 17 additions & 2 deletions src/spikeinterface/extractors/neoextractors/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,29 @@ class EDFRecordingExtractor(NeoBaseRecordingExtractor):
If there are several streams, specify the stream name you want to load.
all_annotations: bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

NeoRawIOClass = "EDFRawIO"

def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False):
def __init__(
self,
file_path,
stream_id=None,
stream_name=None,
all_annotations: bool = False,
use_names_as_ids: bool = False,
):
neo_kwargs = {"filename": str(file_path)}
NeoBaseRecordingExtractor.__init__(
self, stream_id=stream_id, stream_name=stream_name, all_annotations=all_annotations, **neo_kwargs
self,
stream_id=stream_id,
stream_name=stream_name,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)
self._kwargs.update({"file_path": str(Path(file_path).absolute())})
self.extra_requirements.append("neo[edf]")
Expand Down
6 changes: 5 additions & 1 deletion src/spikeinterface/extractors/neoextractors/intan.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class IntanRecordingExtractor(NeoBaseRecordingExtractor):
check we perform is that timestamps are continuous. Setting this to True will ignore this check and set
the attribute `discontinuous_timestamps` to True in the underlying neo object.
use_names_as_ids : bool, default: False
If False, use default IDs inherited from Neo. If True, use channel names as IDs.
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
In Intan the ids provided by NeoRawIO are the hardware channel ids while the names are custom names given by
the user
"""
Expand Down
5 changes: 5 additions & 0 deletions src/spikeinterface/extractors/neoextractors/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class MaxwellRecordingExtractor(NeoBaseRecordingExtractor):
If there are several streams, specify the stream name you want to load.
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
rec_name : str, default: None
When the file contains several recordings you need to specify the one
you want to extract. (rec_name='rec0000').
Expand All @@ -50,6 +53,7 @@ def __init__(
all_annotations=False,
rec_name=None,
install_maxwell_plugin=False,
use_names_as_ids: bool = False,
):
if install_maxwell_plugin:
self.install_maxwell_plugin()
Expand All @@ -61,6 +65,7 @@ def __init__(
stream_name=stream_name,
block_index=block_index,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)

Expand Down
14 changes: 13 additions & 1 deletion src/spikeinterface/extractors/neoextractors/mcsraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,30 @@ class MCSRawRecordingExtractor(NeoBaseRecordingExtractor):
If there are several blocks, specify the block index you want to load.
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

NeoRawIOClass = "RawMCSRawIO"

def __init__(self, file_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False):
def __init__(
self,
file_path,
stream_id=None,
stream_name=None,
block_index=None,
all_annotations=False,
use_names_as_ids: bool = False,
):
neo_kwargs = self.map_to_neo_kwargs(file_path)
NeoBaseRecordingExtractor.__init__(
self,
stream_id=stream_id,
stream_name=stream_name,
block_index=block_index,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)
self._kwargs.update(dict(file_path=str(Path(file_path).absolute())))
Expand Down
12 changes: 10 additions & 2 deletions src/spikeinterface/extractors/neoextractors/mearec.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ class MEArecRecordingExtractor(NeoBaseRecordingExtractor):
The file path to load the recordings from.
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

NeoRawIOClass = "MEArecRawIO"

def __init__(self, file_path: Union[str, Path], all_annotations: bool = False):
def __init__(self, file_path: Union[str, Path], all_annotations: bool = False, use_names_as_ids: bool = False):
neo_kwargs = self.map_to_neo_kwargs(file_path)
NeoBaseRecordingExtractor.__init__(self, all_annotations=all_annotations, **neo_kwargs)
NeoBaseRecordingExtractor.__init__(
self,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)

self.extra_requirements.append("mearec")

Expand Down
31 changes: 22 additions & 9 deletions src/spikeinterface/extractors/neoextractors/neobaseextractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ def __init__(
if stream_id is None and stream_name is None:
if stream_channels.size > 1:
raise ValueError(
f"This reader have several streams: \nNames: {stream_names}\nIDs: {stream_ids}. "
f"Specify it with the 'stream_name' or 'stream_id' arguments"
f"This reader have several streams: \nNames: {stream_names}\nIDs: {stream_ids}. \n"
f"Specify it from the options above with the 'stream_name' or 'stream_id' arguments"
)
else:
stream_id = stream_ids[0]
Expand Down Expand Up @@ -276,7 +276,7 @@ def __init__(

self.set_property("gain_to_uV", final_gains)
self.set_property("offset_to_uV", final_offsets)
if not use_names_as_ids and not all_annotations:
if not use_names_as_ids:
self.set_property("channel_names", signal_channels["name"])

if all_annotations:
Expand All @@ -287,13 +287,26 @@ def __init__(
seg_ann = block_ann["segments"][0]
sig_ann = seg_ann["signals"][self.stream_index]

# scalar annotations
for k, v in sig_ann.items():
if not k.startswith("__"):
self.set_annotation(k, v)
scalar_annotations = {name: value for name, value in sig_ann.items() if not name.startswith("__")}

# name in neo corresponds to stream name
# We don't propagate the name as an annotation because that has a differnt meaning on spikeinterface
stream_name = scalar_annotations.pop("name", None)
if stream_name:
self.set_annotation(annotation_key="stream_name", value=stream_name)
for annotation_key, value in scalar_annotations.items():
self.set_annotation(annotation_key=annotation_key, value=value)

array_annotations = sig_ann["__array_annotations__"]
# We do not add this because is confusing for the user to have this repeated
array_annotations.pop("channel_ids", None)
# This is duplicated when using channel_names as ids
if use_names_as_ids:
array_annotations.pop("channel_names", None)

# vector array_annotations are channel properties
for k, values in sig_ann["__array_annotations__"].items():
self.set_property(k, values)
for key, values in array_annotations.items():
self.set_property(key=key, values=values)

nseg = self.neo_reader.segment_count(block_index=self.block_index)
for segment_index in range(nseg):
Expand Down
13 changes: 11 additions & 2 deletions src/spikeinterface/extractors/neoextractors/neuralynx.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor):
exclude_filename : list[str], default: None
List of filename to exclude from the loading.
For example, use `exclude_filename=["events.nev"]` to skip loading the event file.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
strict_gap_mode : bool, default: False
See neo documentation.
Detect gaps using strict mode or not.
Expand All @@ -44,16 +47,22 @@ class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor):

def __init__(
self,
folder_path,
folder_path: str | Path,
stream_id=None,
stream_name=None,
all_annotations=False,
exclude_filename=None,
strict_gap_mode=False,
use_names_as_ids: bool = False,
):
neo_kwargs = self.map_to_neo_kwargs(folder_path, exclude_filename, strict_gap_mode)
NeoBaseRecordingExtractor.__init__(
self, stream_id=stream_id, stream_name=stream_name, all_annotations=all_annotations, **neo_kwargs
self,
stream_id=stream_id,
stream_name=stream_name,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)
self._kwargs.update(
dict(folder_path=str(Path(folder_path).absolute()), exclude_filename=exclude_filename),
Expand Down
14 changes: 12 additions & 2 deletions src/spikeinterface/extractors/neoextractors/neuroexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,24 @@ class NeuroExplorerRecordingExtractor(NeoBaseRecordingExtractor):
If there are several streams, specify the stream name you want to load.
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
use_names_as_ids : bool, default: False
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
"""

NeoRawIOClass = "NeuroExplorerRawIO"

def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False):
def __init__(
self, file_path, stream_id=None, stream_name=None, all_annotations: bool = False, use_names_as_ids: bool = False
):
neo_kwargs = {"filename": str(file_path)}
NeoBaseRecordingExtractor.__init__(
self, stream_id=stream_id, stream_name=stream_name, all_annotations=all_annotations, **neo_kwargs
self,
stream_id=stream_id,
stream_name=stream_name,
all_annotations=all_annotations,
use_names_as_ids=use_names_as_ids,
**neo_kwargs,
)
self._kwargs.update({"file_path": str(Path(file_path).absolute())})
self.extra_requirements.append("neo[edf]")
Expand Down
Loading

0 comments on commit e580139

Please sign in to comment.