diff --git a/src/spikeinterface/core/baserecordingsnippets.py b/src/spikeinterface/core/baserecordingsnippets.py index c2386d0af0..48595be0c3 100644 --- a/src/spikeinterface/core/baserecordingsnippets.py +++ b/src/spikeinterface/core/baserecordingsnippets.py @@ -2,11 +2,11 @@ from pathlib import Path import numpy as np +import warnings from probeinterface import Probe, ProbeGroup, write_probeinterface, read_probeinterface, select_axes from .base import BaseExtractor -from .core_tools import check_json from .recording_tools import check_probe_do_not_overlap from warnings import warn @@ -76,7 +76,7 @@ def set_probe(self, probe, group_mode="by_probe", in_place=False): Parameters ---------- - probe_or_probegroup: Probe, list of Probe, or ProbeGroup + probe: a Probe object The probe(s) to be attached to the recording group_mode: "by_probe" | "by_shank", default: "by_probe "by_probe" or "by_shank". Adds grouping property to the recording based on the probes ("by_probe") @@ -90,6 +90,7 @@ def set_probe(self, probe, group_mode="by_probe", in_place=False): sub_recording: BaseRecording A view of the recording (ChannelSlice or clone or itself) """ + assert isinstance(probe, Probe), "must give Probe" probegroup = ProbeGroup() probegroup.add_probe(probe) @@ -173,7 +174,15 @@ def set_probes(self, probe_or_probegroup, group_mode="by_probe", in_place=False) probe_as_numpy_array = probe_as_numpy_array[order] probe_as_numpy_array["device_channel_indices"] = np.arange(probe_as_numpy_array.size, dtype="int64") - # create recording : channel slice or clone or self + deprecation_msg = ( + "in_place will change its default to True in version 0.103 and stop returning a recording" + " use recording.create_with_probes(probe_or_probegroup) instead to replicate the old functionality" + ) + warnings.warn( + deprecation_msg, + DeprecationWarning, + stacklevel=2, + ) if in_place: if not np.array_equal(new_channel_ids, self.get_channel_ids()): raise Exception("set_probe(inplace=True) must have all channel indices") @@ -225,6 +234,27 @@ def set_probes(self, probe_or_probegroup, group_mode="by_probe", in_place=False) return sub_recording + def create_with_probes(self, probe_or_probegroup, group_mode="by_probe"): + """ + Creates a new recording with a probe attached. + + Parameters + ---------- + probe_or_probegroup: Probe, list of Probes, or ProbeGroup + The probe(s) to be attached to the recording + group_mode: "by_probe" | "by_shank", default: "by_probe" + "by_probe" or "by_shank". Adds grouping property to the recording based on the probes ("by_probe") + or shanks ("by_shank") + + Returns + ------- + new_recording: BaseRecording + A new recording object with the probe attached + """ + + # TODO: Once in_place is True by default in set_probes, we might re-organize the code + return self.set_probegroup(probe_or_probegroup, in_place=False) + def get_probe(self): probes = self.get_probes() assert len(probes) == 1, "there are several probe use .get_probes() or get_probegroup()"