From ba9417a64e9da1f1462aae2f2a4fa7dcd69c0013 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Thu, 2 May 2024 19:18:56 -0600 Subject: [PATCH 1/2] move towards making set_probe in place --- .../core/baserecordingsnippets.py | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/core/baserecordingsnippets.py b/src/spikeinterface/core/baserecordingsnippets.py index c2386d0af0..464e261bd1 100644 --- a/src/spikeinterface/core/baserecordingsnippets.py +++ b/src/spikeinterface/core/baserecordingsnippets.py @@ -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" + ) + warn.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()" From 5f2d22712b0e9171364faa2679f1bb31a90f6308 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Thu, 2 May 2024 19:44:24 -0600 Subject: [PATCH 2/2] fix warning --- src/spikeinterface/core/baserecordingsnippets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/core/baserecordingsnippets.py b/src/spikeinterface/core/baserecordingsnippets.py index 464e261bd1..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 @@ -178,7 +178,7 @@ def set_probes(self, probe_or_probegroup, group_mode="by_probe", in_place=False) "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" ) - warn.warn( + warnings.warn( deprecation_msg, DeprecationWarning, stacklevel=2,