Skip to content

Commit

Permalink
Fix open ephys probe loading and unify probeinterface imnport syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoe91 committed Oct 27, 2023
1 parent 109b5b3 commit 9a37e57
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/spikeinterface/extractors/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

import neo
from probeinterface import read_BIDS_probe
import probeinterface as pi

from .nwbextractors import read_nwb
from .neoextractors import read_nix
Expand Down Expand Up @@ -60,7 +60,7 @@ def read_bids(folder_path):


def _read_probe_group(folder, bids_name, recording_channel_ids):
probegroup = read_BIDS_probe(folder)
probegroup = pi.read_BIDS_probe(folder)

# make maps between : channel_id and contact_id using _channels.tsv
import pandas as pd
Expand Down
16 changes: 11 additions & 5 deletions src/spikeinterface/extractors/neoextractors/openephys.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""
There are two extractors for data saved by the Open Ephys GUI
* OpenEphysLegacyRecordingExtractor: reads the original "Open Ephys" data format
* OpenEphysBinaryRecordingExtractor: reads the new default "Binary" format
See https://open-ephys.github.io/gui-docs/User-Manual/Recording-data/index.html
for more info.
"""

from pathlib import Path
Expand All @@ -23,10 +21,10 @@


def drop_invalid_neo_arguments_for_version_0_12_0(neo_kwargs):
# Temporary function until neo version 0.13.0 is released
from packaging.version import Version
from importlib.metadata import version as lib_version

# Temporary function until neo version 0.13.0 is released
neo_version = lib_version("neo")
# The possibility of ignoring timestamps errors is not present in neo <= 0.12.0
if Version(neo_version) <= Version("0.12.0"):
Expand Down Expand Up @@ -187,9 +185,17 @@ def __init__(
self.set_probe(probe, in_place=True, group_mode="by_shank")
else:
self.set_probe(probe, in_place=True)
probe_name = probe.annotations["probe_name"]

# this try-except handles a breaking change in probeinterface after v0.2.18
# in the new version, the Neuropixels model name is stored in the "model_name" attribute,
# rather than in the "probe_name" annotation
try:
model_name = probe.model_name
except Exception as e:
model_name = probe.annotations["probe_name"]

# load num_channels_per_adc depending on probe type
if "2.0" in probe_name:
if "2.0" in model_name:
num_channels_per_adc = 16
num_cycles_in_adc = 16
total_channels = 384
Expand Down
6 changes: 3 additions & 3 deletions src/spikeinterface/extractors/shybridextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from probeinterface import read_prb, write_prb
import probeinterface as pi

from spikeinterface.core import BinaryRecordingExtractor, BaseRecordingSegment, BaseSorting, BaseSortingSegment
from spikeinterface.core.core_tools import write_binary_recording, define_function_from_class
Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(self, file_path):
)

# load probe file
probegroup = read_prb(params["probe"])
probegroup = pi.read_prb(params["probe"])
self.set_probegroup(probegroup, in_place=True)
self._kwargs = {"file_path": str(Path(file_path).absolute())}
self.extra_requirements.extend(["hybridizer", "pyyaml"])
Expand Down Expand Up @@ -119,7 +119,7 @@ def write_recording(recording, save_path, initial_sorting_fn, dtype="float32", *
# write probe file
probe_fn = (save_path / probe_name).absolute()
probegroup = recording.get_probegroup()
write_prb(probe_fn, probegroup, total_nb_channels=recording.get_num_channels())
pi.write_prb(probe_fn, probegroup, total_nb_channels=recording.get_num_channels())

# create parameters file
parameters = dict(
Expand Down

0 comments on commit 9a37e57

Please sign in to comment.