diff --git a/src/spikeinterface/extractors/neoextractors/spikeglx.py b/src/spikeinterface/extractors/neoextractors/spikeglx.py index 9f3df5fac0..4e900097ea 100644 --- a/src/spikeinterface/extractors/neoextractors/spikeglx.py +++ b/src/spikeinterface/extractors/neoextractors/spikeglx.py @@ -1,6 +1,7 @@ from __future__ import annotations from pathlib import Path +import warnings import probeinterface @@ -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, @@ -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") @@ -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):