Skip to content

Conversation

@samuelgarcia
Copy link
Member

@samuelgarcia samuelgarcia commented Jan 23, 2026

After playing a bit with the rust language, and trying to reimplement the peak detection algo using "locally_exclussive"
I discover that the actual impelmentation could be fasten a lot (at least 3X faster on my machine).

"matched_filtering" has also beeb changed in this PR.

Also the new implementation is is more accurate for corener cases :

  • when the theshold are not teh same by channel (the comparison must be done on the ratio and not teh value)
  • when value in the sweep are higher but not peak thenself

Also I change the exclude_sweep_ms=0.1 at many place in the code this was a bad value by default it has to be half on the peak waveforms or a bit more.

@yger
Copy link
Collaborator

yger commented Jan 25, 2026

Great, this is cool, looking forward to try it out ! But what about the matched filtering ?

Copy link
Collaborator

@yger yger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@alejoe91 alejoe91 added the sortingcomponents Related to sortingcomponents module label Jan 26, 2026
@samuelgarcia samuelgarcia changed the title Make peak detection with locally_exclussive faster and more accurate. Make peak detection (locally_exclussive, matched_filtering) faster and more accurate. Jan 27, 2026
templates=None,
peak_sign="neg",
exclude_sweep_ms=0.1,
exclude_sweep_ms=0.8,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're using 0.8 for all the internal sorters, but 1.0 for the defaults in detect_peaks. Is this deliberate?

# if inside spatial zone ...
if abs(samples_inds[i] - samples_inds[j]) <= exclude_sweep_size:
# ...and if inside tempral zone ...
value_i = abs(traces[samples_inds[i], chan_inds[i]]) / abs_thresholds[chan_inds[i]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here, the abs_threshold is proportional to the noise on the channel. What's the advantage of using the noise normalised value? Is this to avoid peaks on very noisy channels?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoid that a peak is eliminated even if the snr is higher.
It was not the case before. This is a marjor change in this PR when the noise_levels is different over channel.
I think this is more correct

if peak_sign == "both":
peak_mask_pos = peak_mask.copy()
if samples_inds[i] - exclude_sweep_size > samples_inds[j]:
next_start = j
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
next_start = j
next_start = j+1

shave off those nanoseconds ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure. why ?
The following j will do it if nessecary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sortingcomponents Related to sortingcomponents module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants