Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug when caching recording noise levels #2220

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/spikeinterface/core/baserecording.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class BaseRecording(BaseRecordingSnippets):
_main_properties = ["group", "location", "gain_to_uV", "offset_to_uV"]
_main_features = [] # recording do not handle features

_skip_properties = ["noise_level_raw", "noise_level_scaled"]
_skip_properties = [
"noise_level_std_raw",
"noise_level_std_scaled",
"noise_level_mad_raw",
"noise_level_mad_scaled",
]

def __init__(self, sampling_frequency: float, channel_ids: List, dtype):
BaseRecordingSnippets.__init__(
Expand Down
4 changes: 2 additions & 2 deletions src/spikeinterface/core/recording_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ def get_noise_levels(
"""

if return_scaled:
key = "noise_level_scaled"
key = f"noise_level_{method}_scaled"
else:
key = "noise_level_raw"
key = f"noise_level_{method}_raw"

if key in recording.get_property_keys() and not force_recompute:
noise_levels = recording.get_property(key=key)
Expand Down
18 changes: 9 additions & 9 deletions src/spikeinterface/core/tests/test_noise_levels_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ def test_skip_noise_levels_propagation():
rec = generate_recording(durations=[5.0], num_channels=4)
rec.set_property("test", ["1", "2", "3", "4"])
rec = rec.save()
noise_level_raw = get_noise_levels(rec, return_scaled=False)
assert "noise_level_raw" in rec.get_property_keys()
noise_level_raw = get_noise_levels(rec, return_scaled=False, method="mad")
assert "noise_level_mad_raw" in rec.get_property_keys()

rec_frame_slice = rec.frame_slice(start_frame=0, end_frame=1000)
assert "noise_level_raw" not in rec_frame_slice.get_property_keys()
assert "noise_level_mad_raw" not in rec_frame_slice.get_property_keys()
assert "test" in rec_frame_slice.get_property_keys()

# make scaled
rec.set_channel_gains([100] * 4)
rec.set_channel_offsets([0] * 4)
noise_level_scaled = get_noise_levels(rec, return_scaled=True)
assert "noise_level_scaled" in rec.get_property_keys()
noise_level_scaled = get_noise_levels(rec, return_scaled=True, method="std")
assert "noise_level_std_scaled" in rec.get_property_keys()

rec_frame_slice = rec.frame_slice(start_frame=0, end_frame=1000)
rec_concat = concatenate_recordings([rec] * 5)

assert "noise_level_raw" not in rec_concat.get_property_keys()
assert "noise_level_scaled" not in rec_concat.get_property_keys()
assert "noise_level_raw" not in rec_frame_slice.get_property_keys()
assert "noise_level_scaled" not in rec_frame_slice.get_property_keys()
assert "noise_level_mad_raw" not in rec_concat.get_property_keys()
assert "noise_level_std_scaled" not in rec_concat.get_property_keys()
assert "noise_level_mad_raw" not in rec_frame_slice.get_property_keys()
assert "noise_level_std_scaled" not in rec_frame_slice.get_property_keys()
assert "test" in rec_frame_slice.get_property_keys()
assert "test" in rec_concat.get_property_keys()

Expand Down