`make_residual_recording` subtracts templates in uV from traces in raw units
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 83/100
Research direction
Start with benchmark/residual_analysis.py and inspect make_residual_recording, then trace how analyzer templates and recording traces are represented when channel gains differ from 1. Reproduce the supplied gain cases and add a regression test showing the residual standard deviation in uV is consistent across gains. Done when the residual matches the expected 5.05 uV in all three cases.
Written by the indexing model from the issue text.
Description
I found this while reading benchmark/residual_analysis.py, not in my own analyses, so this is a "for the sake of improvement" report.
make_residual_recording takes the templates from the analyzer, in uV by default, and injects them with a negative sign into analyzer.recording, whose traces are in raw units. When the gain is not 1, the residual is wrong, without an error. In the example below the traces in uV are the same for the three gains.
from spikeinterface.core import generate_ground_truth_recording, create_sorting_analyzer
from spikeinterface.preprocessing import scale
from spikeinterface.benchmark import make_residual_recording
recording, sorting = generate_ground_truth_recording(durations=[10.0], num_channels=8, num_units=4, seed=0)
print(f"recording std {recording.get_traces(return_in_uV=True).std():.2f} uV")
for gain in (1.0, 0.195, 2.34):
# same traces in uV, stored in raw units (uV / gain)
raw = scale(recording, gain=1 / gain, dtype="float32")
raw.set_channel_gains(gain)
raw.set_channel_offsets(0.0)
analyzer = create_sorting_analyzer(sorting, raw, sparse=False)
analyzer.compute(["random_spikes", "templates", "noise_levels"])
analyzer.compute("amplitude_scalings", handle_collisions=False)
residual = make_residual_recording(analyzer)
print(f"gain {gain}: residual std {residual.get_traces(return_in_uV=True).std():.2f} uV")
# Output on current main:
# recording std 7.17 uV
# gain 1.0: residual std 5.05 uV
# gain 0.195: residual std 6.48 uV
# gain 2.34: residual std 8.91 uV
# Expected: 5.05 uV for the three gains
With create_sorting_analyzer(..., return_in_uV=False), the residual std is 5.05 uV for the three gains.
Fix: divide the templates by the channel gains before injecting them when they are in uV, or inject them into scale_to_uV(analyzer.recording). The second option changes the dtype and units of the residual, so I leave the choice to you.
I can open a PR with a test if you agree.
- Dominant language
- Python
- Stars
- 883
- Forks
- 291
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 40
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SpikeInterface/spikeinterface
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
SpikeInterface/spikeinterface#5008 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
SpikeInterface/spikeinterface#5007 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
SpikeInterface/spikeinterface#5006 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
SpikeInterface/spikeinterface#5004 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
SpikeInterface/spikeinterface#5003 ·
Maintainers usually reply within 2 days
All issues in SpikeInterface/spikeinterface
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
available bug good first issue tooling
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Nixitov/Riptide-Native#816 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
teng-lin/notebooklm-py#2593 ·
Maintainers usually reply within 1 day
-
claimed-by:collie role:small-fix status:running
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Beovulfo/herd-sdlc#325 · 1 comment ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 94/100
omarelshamy25x/shamy-arabic-nlp#267 ·
Maintainers usually reply within 1 day