`analyse_residual` fails with its default arguments since `detect_peaks` changed signature

Open Beginner friendly
#5,004 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
data

Research direction

Start with benchmark/residual_analysis.py and benchmark_sorter_without_gt.py, then check the detect_peaks signature and the two skipped tests mentioned in the issue. Verify the default arguments and job kwargs work through both benchmark paths; done means the reported TypeErrors are gone and the related tests pass.

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.

analyse_residual calls detect_peaks(residual, **detect_peaks_kwargs, **job_kwargs), but since #4793 detect_peaks only accepts method, method_kwargs, pipeline_kwargs, verbose and job_kwargs. The default detect_peaks_kwargs (with peak_sign and detect_threshold) and any job kwarg now raise a TypeError.

from spikeinterface.core import generate_ground_truth_recording, create_sorting_analyzer
from spikeinterface.benchmark import analyse_residual

recording, sorting = generate_ground_truth_recording(durations=[10.0], num_channels=8, num_units=4, seed=0)
analyzer = create_sorting_analyzer(sorting, recording, sparse=True)
analyzer.compute(["random_spikes", "templates", "noise_levels"])
analyzer.compute("amplitude_scalings", handle_collisions=False)

for args, job_kwargs in (((), {}), (({"method": "locally_exclusive"},), {"n_jobs": 1})):
    try:
        analyse_residual(analyzer, *args, **job_kwargs)
    except TypeError as error:
        print(error)

# Output on current main:
# detect_peaks() got an unexpected keyword argument 'peak_sign'
# detect_peaks() got an unexpected keyword argument 'n_jobs'
# Expected: no error

Reading the code, SorterBenchmarkWithoutGroundTruth.compute_result makes the same call, so SorterStudyWithoutGroundTruth.compute_results() fails too; the two related tests are marked skip.

Fix: call detect_peaks(residual, method=..., method_kwargs=..., job_kwargs=job_kwargs), and update the default dict and the call in benchmark_sorter_without_gt.py.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SpikeInterface/spikeinterface

All issues in SpikeInterface/spikeinterface

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.