Skip to content

Fix compute_amplitude_cutoffs() default num_histogram_bins left at 500 after #4415 - #4943

Open
SID-6921 wants to merge 1 commit into
SpikeInterface:mainfrom
SID-6921:fix-amplitude-cutoff-default-bins
Open

SID-6921 wants to merge 1 commit into
SpikeInterface:mainfrom
SID-6921:fix-amplitude-cutoff-default-bins

Conversation

@SID-6921

Copy link
Copy Markdown

What

compute_amplitude_cutoffs()'s own num_histogram_bins default stayed at 500, even though its own docstring claims default: 100, AmplitudeCutoff.metric_params (the default used by the standard quality-metrics pipeline) is 100, and the low-level amplitude_cutoff() helper it wraps also defaults to 100.

#4415 fixed amplitude_cutoff()'s signature and AmplitudeCutoff.metric_params back to 100 after a prior regression (#4353 had bumped it to 200), but didn't touch compute_amplitude_cutoffs()'s own signature default, which was never changed and stayed at 500.

With amplitudes_bins_min_ratio=5, this silently raises the spike-count floor a unit needs before amplitude_cutoff stops being NaN from 500 spikes (the documented/intended behavior) to 2500 spikes, for anyone calling compute_amplitude_cutoffs(sorting_analyzer) directly without an explicit num_histogram_bins override. I suspect this is part of what's going on in #3605 ("much of the data I get is NaN"), though that thread settled on a different (also real) cause.

Repro

from spikeinterface.metrics.quality.misc_metrics import amplitude_cutoff
import numpy as np

rng = np.random.default_rng(0)
amps = rng.normal(100, 20, 3000)
observed = amps[amps > 85][:2317]  # a realistic, moderately-sized unit

amplitude_cutoff(observed, num_histogram_bins=500)  # compute_amplitude_cutoffs()'s actual default
# -> nan (needs 2500 spikes at bins=500, amplitudes_bins_min_ratio=5)

amplitude_cutoff(observed, num_histogram_bins=100)  # the documented/intended default
# -> 0.2318 (needs only 500 spikes at bins=100)

Fix

Set compute_amplitude_cutoffs()'s num_histogram_bins default to 100, matching its own docstring, AmplitudeCutoff.metric_params, and amplitude_cutoff(). Also fixed amplitude_cutoff()'s docstring, which still said default: 500 after #4415 changed the actual signature default to 100.

Testing

Added test_amplitude_cutoff_default_num_histogram_bins_is_consistent, which asserts the three declared defaults agree on 100, and demonstrates the behavioral consequence (same spike count: NaN at the stale 500 default, finite at 100). Confirmed it fails against the pre-fix code and passes after the fix.

Ran the full metrics/quality/tests/test_metrics_functions.py suite: 32 passed (including the new test and the two pre-existing amplitude_cutoff tests), 4 pre-existing failures (test_compute_new_quality_metrics, test_metric_names_in_same_order, test_save_quality_metrics, test_unit_id_order_independence) reproduced identically on an unmodified checkout, unrelated to this change.

SpikeInterface#4415 fixed amplitude_cutoff()'s and AmplitudeCutoff.metric_params's
num_histogram_bins default back to 100 after a regression, but didn't touch
compute_amplitude_cutoffs()'s own signature default, which stayed at 500 even
though its own docstring still said 100.

With amplitudes_bins_min_ratio=5, that mismatch silently raises the spike
count a unit needs before its amplitude_cutoff stops being NaN from 500 to
2500 whenever compute_amplitude_cutoffs() is called directly without an
explicit num_histogram_bins override. Confirmed with a 2317-spike unit:
num_histogram_bins=500 returns NaN, num_histogram_bins=100 returns a real
value (0.23).

Set compute_amplitude_cutoffs()'s default to 100, matching its own docstring,
AmplitudeCutoff.metric_params, and the amplitude_cutoff() helper it wraps.
Also fixed amplitude_cutoff()'s docstring, which still claimed "default: 500"
after SpikeInterface#4415 changed the actual default to 100.

Added test_amplitude_cutoff_default_num_histogram_bins_is_consistent, which
checks the three declared defaults agree and that the same spike count is
NaN under the stale 500 default but finite under 100. Confirmed it fails
against the pre-fix code and passes after the fix.
Copilot AI balanced review requested due to automatic review settings November 14, 2026 19:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants