Skip to content

Add concatenated to _get_data for amps and locs; use in _get_amplitudes_by_units #4029

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

Merged
merged 1 commit into from
Jul 14, 2025

Conversation

chrishalcrow
Copy link
Member

Closes #4028

PR implements a concatenated argument in get_data method for the spike_ampltiudes and spike_locations extensions. This returns the data per unit, concatenated per segment. I think this is a helpful thing to have, and was easy to implement.

Then used this new functionality in _get_amplitudes_by_units.

Benchmarked using:

import spikeinterface.full as si
from spikeinterface.qualitymetrics.misc_metrics import _get_amplitudes_by_units
from time import perf_counter
import numpy as np

# an hour-long NP2-kilosort4 analyzer
sa_path = "/Users/christopherhalcrow/Downloads/kilosort4_sa"

times = []
for _ in range(10):
    
    sa = si.load_sorting_analyzer(sa_path, load_extensions=False)
    sa.load_extension("spike_amplitudes")
    t1 = perf_counter()
    amps = _get_amplitudes_by_units(sa, unit_ids=sa.unit_ids, peak_sign="neg")
    t2 = perf_counter()
    times.append(t2-t1)
    del sa

print(np.median(times))

On main: 1.68s
This PR, without numba: 1.13s
This PR, with numba: 0.0806s

So a 20x speedup if numba is around :)

@chrishalcrow chrishalcrow added the enhancement New feature or request label Jul 4, 2025
@samuelgarcia
Copy link
Member

Merci Chris. This is perfect.
@alejoe91 : I let you have a look.

@alejoe91 alejoe91 merged commit b2396f2 into SpikeInterface:main Jul 14, 2025
15 checks passed
@chrishalcrow chrishalcrow deleted the speedup-amps-by-unit branch July 14, 2025 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor quality_metrics _get_amplitudes_by_units using sorting_tools.spike_vector_to_indices
3 participants