Skip to content

Read spikeglx neuropixels data without ap meta #3931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/spikeinterface/extractors/neoextractors/spikeglx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from pathlib import Path
import warnings

import probeinterface

Expand Down Expand Up @@ -61,6 +62,7 @@ def __init__(
all_annotations: bool = False,
use_names_as_ids: bool = False,
):

neo_kwargs = self.map_to_neo_kwargs(folder_path, load_sync_channel=load_sync_channel)
NeoBaseRecordingExtractor.__init__(
self,
Expand All @@ -71,15 +73,18 @@ def __init__(
**neo_kwargs,
)

# open the corresponding stream probe for LF and AP
# if load_sync_channel=False
if "nidq" not in self.stream_id and not load_sync_channel:
signals_info_dict = {e["stream_name"]: e for e in self.neo_reader.signals_info_list}
meta_filename = signals_info_dict[self.stream_id]["meta_file"]
# Load probe geometry if available
if "lf" in self.stream_id:
meta_filename = meta_filename.replace(".lf", ".ap")
probe = probeinterface.read_spikeglx(meta_filename)
self._kwargs.update(dict(folder_path=str(Path(folder_path).absolute()), load_sync_channel=load_sync_channel))

# Checks if the probe information is available and adds location, shanks and sample shift if available.
signals_info_dict = {e["stream_name"]: e for e in self.neo_reader.signals_info_list}
meta_filename = signals_info_dict[self.stream_id]["meta_file"]
ap_meta_filename = meta_filename.replace(".lf", ".ap") if "lf" in self.stream_id else meta_filename
ap_meta_file_exists = Path(ap_meta_filename).exists()
stream_is_not_nidq = "nidq" not in self.stream_id
add_probe_properties = ap_meta_file_exists and stream_is_not_nidq and not load_sync_channel

if add_probe_properties:
probe = probeinterface.read_spikeglx(ap_meta_filename)

if probe.shank_ids is not None:
self.set_probe(probe, in_place=True, group_mode="by_shank")
Expand Down Expand Up @@ -111,8 +116,12 @@ def __init__(
sample_shifts = sample_shifts[chans]

self.set_property("inter_sample_shift", sample_shifts)

self._kwargs.update(dict(folder_path=str(Path(folder_path).absolute()), load_sync_channel=load_sync_channel))
else:
warning_message = (
"Unable to find a corresponding metadata file for the recording. "
"The probe information will not be loaded. "
)
warnings.warn(warning_message, UserWarning, stacklevel=2)

@classmethod
def map_to_neo_kwargs(cls, folder_path, load_sync_channel=False):
Expand Down