Skip to content

Reuse cached noise levels only for the random slices that drew them - #4955

Open
grahamfindlay wants to merge 1 commit into
SpikeInterface:mainfrom
grahamfindlay:noise-levels-cache-params
Open

grahamfindlay wants to merge 1 commit into
SpikeInterface:mainfrom
grahamfindlay:noise-levels-cache-params

Conversation

@grahamfindlay

Copy link
Copy Markdown
Collaborator

Fixes #4928.

get_noise_levels was caching its result under a key that ignored random_slices_kwargs, so a call could get noise levels drawn with another seed or chunk layout (#4928). Now it keeps each draw's kwargs (with defaults filled in) in a private unsaved dict on the recording.

  • It reuses the cache only when a call's kwargs match them.
  • A call without a seed accepts any seed.
  • Noise levels set by hand or loaded from a folder count as an unseeded draw with the defaults, and set_property drops the stored kwargs.
  • highpass_spatial_filter now uses get_noise_levels.

While doing this I noticed that passing random_slices_kwargs an old way, as top-level keyword arguments, still works with a deprecation warning:

get_noise_levels(recording, num_chunks_per_segment=10)  # deprecated
get_noise_levels(recording, random_slices_kwargs=dict(num_chunks_per_segment=10))

Based on the comments, it appears to have been intended for removal in 0.103.0. I left it so that the code that turns the first form into the second now runs before checking the cache, so settings passed the old way are compared too. But I would like to remove this old deprecated call style in a follow-up PR, and switch anything that uses it (highpass_spatial_filter and waveform_thresholder as far as I can tell) to use random_slices_kwargs.

get_noise_levels was caching its result under a key that ignored
random_slices_kwargs, so a call could get noise levels drawn with
another seed or chunk layout (SpikeInterface#4928). Now it keeps each draw's kwargs
(with defaults filled in) in a private unsaved dict on the recording,
and reuses the cache only when a call's kwargs match them. A call
without a seed accepts any seed. Noise levels set by hand or loaded from
a folder count as an unseeded draw with the defaults, and set_property
drops the stored kwargs.

Additionally, highpass_spatial_filter now uses get_noise_levels.
@grahamfindlay grahamfindlay added bug Something isn't working core Changes to core module labels Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core Changes to core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_noise_levels returns a cached value even when the call asks for a different seed or chunks

1 participant