Skip to content

Commit e4b9d07

Browse files
committed
fix ptp deprecation and tests
1 parent d4321ed commit e4b9d07

2 files changed

Lines changed: 13 additions & 47 deletions

File tree

src/spikeinterface/core/sparsity.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
* "snr" : threshold based on template signal-to-noise ratio. Use the "threshold" argument
2222
to specify the SNR threshold (in units of noise levels) and the "amplitude_mode" argument
2323
to specify the mode to compute the amplitude of the templates.
24-
* "amplitude" : threshold based on the amplitude values on every channels. Use the "threshold" argument
25-
to specify the ptp threshold (in units of amplitude) and the "amplitude_mode" argument
24+
* "amplitude" : threshold based on the amplitude values on every channels. Use the "amplitude_mode" argument
2625
to specify the mode to compute the amplitude of the templates.
2726
* "energy" : threshold based on the expected energy that should be present on the channels,
2827
given their noise levels. Use the "threshold" argument to specify the energy threshold
@@ -38,7 +37,7 @@
3837
radius_um : float
3938
Radius in um for "radius" method.
4039
threshold : float
41-
Threshold for "snr", "energy" (in units of noise levels) and "ptp" methods (in units of amplitude).
40+
Threshold for "snr" and "energy" (in units of noise levels) (in units of amplitude).
4241
For the "snr" method, the template amplitude mode is controlled by the "amplitude_mode" argument.
4342
amplitude_mode : "extremum" | "at_index" | "peak_to_peak"
4443
Mode to compute the amplitude of the templates for the "snr", "amplitude", and "best_channels" methods.
@@ -607,9 +606,7 @@ def create_dense(cls, sorting_analyzer):
607606
def compute_sparsity(
608607
templates_or_sorting_analyzer: "Templates | SortingAnalyzer",
609608
noise_levels: np.ndarray | None = None,
610-
method: (
611-
"radius" | "best_channels" | "closest_channels" | "snr" | "amplitude" | "energy" | "by_property" | "ptp"
612-
) = "radius",
609+
method: "radius" | "best_channels" | "closest_channels" | "snr" | "amplitude" | "energy" | "by_property" = "radius",
613610
peak_sign: "neg" | "pos" | "both" = "neg",
614611
num_channels: int | None = 5,
615612
radius_um: float | None = 100.0,
@@ -644,7 +641,13 @@ def compute_sparsity(
644641
# to keep backward compatibility
645642
templates_or_sorting_analyzer = templates_or_sorting_analyzer.sorting_analyzer
646643

647-
if method in ("best_channels", "closest_channels", "radius", "snr", "amplitude", "ptp"):
644+
if method in (
645+
"best_channels",
646+
"closest_channels",
647+
"radius",
648+
"snr",
649+
"amplitude",
650+
):
648651
assert isinstance(
649652
templates_or_sorting_analyzer, (Templates, SortingAnalyzer)
650653
), f"compute_sparsity(method='{method}') need Templates or SortingAnalyzer"
@@ -687,14 +690,6 @@ def compute_sparsity(
687690
sparsity = ChannelSparsity.from_property(
688691
templates_or_sorting_analyzer.sorting, templates_or_sorting_analyzer.recording, by_property
689692
)
690-
elif method == "ptp":
691-
# TODO: remove after deprecation
692-
assert threshold is not None, "For the 'ptp' method, 'threshold' needs to be given"
693-
sparsity = ChannelSparsity.from_ptp(
694-
templates_or_sorting_analyzer,
695-
threshold,
696-
noise_levels=noise_levels,
697-
)
698693
else:
699694
raise ValueError(f"compute_sparsity() method={method} does not exists")
700695

@@ -710,7 +705,7 @@ def estimate_sparsity(
710705
num_spikes_for_sparsity: int = 100,
711706
ms_before: float = 1.0,
712707
ms_after: float = 2.5,
713-
method: "radius" | "best_channels" | "closest_channels" | "amplitude" | "snr" | "by_property" | "ptp" = "radius",
708+
method: "radius" | "best_channels" | "closest_channels" | "amplitude" | "snr" | "by_property" = "radius",
714709
peak_sign: "neg" | "pos" | "both" = "neg",
715710
radius_um: float = 100.0,
716711
num_channels: int = 5,
@@ -759,9 +754,9 @@ def estimate_sparsity(
759754
# Can't be done at module because this is a cyclic import, too bad
760755
from .template import Templates
761756

762-
assert method in ("radius", "best_channels", "closest_channels", "snr", "amplitude", "by_property", "ptp"), (
757+
assert method in ("radius", "best_channels", "closest_channels", "snr", "amplitude", "by_property"), (
763758
f"method={method} is not available for `estimate_sparsity()`. "
764-
"Available methods are 'radius', 'best_channels', 'snr', 'amplitude', 'by_property', 'ptp' (deprecated)"
759+
"Available methods are 'radius', 'best_channels', 'snr', 'amplitude', 'by_property'"
765760
)
766761

767762
if recording.get_probes() == 1:
@@ -838,14 +833,6 @@ def estimate_sparsity(
838833
sparsity = ChannelSparsity.from_amplitude(
839834
templates, threshold, amplitude_mode=amplitude_mode, peak_sign=peak_sign
840835
)
841-
elif method == "ptp":
842-
# TODO: remove after deprecation
843-
assert threshold is not None, "For the 'ptp' method, 'threshold' needs to be given"
844-
assert noise_levels is not None, (
845-
"For the 'snr' method, 'noise_levels' needs to be given. You can use the "
846-
"`get_noise_levels()` function to compute them."
847-
)
848-
sparsity = ChannelSparsity.from_ptp(templates, threshold, noise_levels=noise_levels)
849836
else:
850837
raise ValueError(f"compute_sparsity() method={method} does not exists")
851838
else:

src/spikeinterface/core/tests/test_sparsity.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,8 @@ def test_estimate_sparsity():
268268
progress_bar=True,
269269
n_jobs=1,
270270
)
271-
# ptp: just run it
272271
print(noise_levels)
273272

274-
with pytest.warns(DeprecationWarning):
275-
sparsity = estimate_sparsity(
276-
sorting,
277-
recording,
278-
num_spikes_for_sparsity=50,
279-
ms_before=1.0,
280-
ms_after=2.0,
281-
method="ptp",
282-
threshold=5,
283-
noise_levels=noise_levels,
284-
chunk_duration="1s",
285-
progress_bar=True,
286-
n_jobs=1,
287-
)
288-
289273

290274
def test_compute_sparsity():
291275
recording, sorting = get_dataset()
@@ -310,8 +294,6 @@ def test_compute_sparsity():
310294
sparsity = compute_sparsity(sorting_analyzer, method="amplitude", threshold=5, amplitude_mode="peak_to_peak")
311295
sparsity = compute_sparsity(sorting_analyzer, method="energy", threshold=5)
312296
sparsity = compute_sparsity(sorting_analyzer, method="by_property", by_property="group")
313-
with pytest.warns(DeprecationWarning):
314-
sparsity = compute_sparsity(sorting_analyzer, method="ptp", threshold=5)
315297

316298
# using object Templates
317299
templates = sorting_analyzer.get_extension("templates").get_data(outputs="Templates")
@@ -322,9 +304,6 @@ def test_compute_sparsity():
322304
sparsity = compute_sparsity(templates, method="amplitude", threshold=5, amplitude_mode="peak_to_peak")
323305
sparsity = compute_sparsity(templates, method="closest_channels", num_channels=2)
324306

325-
with pytest.warns(DeprecationWarning):
326-
sparsity = compute_sparsity(templates, method="ptp", noise_levels=noise_levels, threshold=5)
327-
328307

329308
if __name__ == "__main__":
330309
# test_ChannelSparsity()

0 commit comments

Comments
 (0)