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

Implemented sd_ratio as quality metric #2146

Merged
merged 23 commits into from
Nov 22, 2023
Merged

Conversation

DradeAW
Copy link
Contributor

@DradeAW DradeAW commented Oct 31, 2023

A "new" metric I've been working on.
I hope to implement it fast enough for it to be part of v0.99

  • Implement censored period
  • Add tests
  • Add documentation

@DradeAW DradeAW changed the title Work on SD test Implemented SD test as quality metric Nov 2, 2023
@alejoe91 alejoe91 added the qualitymetrics Related to qualitymetrics module label Nov 2, 2023
@@ -1365,3 +1365,57 @@ def _compute_rp_violations_numba(nb_rp_violations, spike_trains, spike_clusters,
spike_train = spike_trains[spike_clusters == i]
n_v = _compute_nb_violations_numba(spike_train, t_r)
nb_rp_violations[i] += n_v


def compute_SD_test(
Copy link
Member

@alejoe91 alejoe91 Nov 2, 2023

Choose a reason for hiding this comment

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

Suggested change
def compute_SD_test(
def compute_sd_ratio(

I'm not super happy with the name. What abut sd_ratio?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm fine with that name!

sd_ratio or std_ratio?

@DradeAW DradeAW changed the title Implemented SD test as quality metric Implemented sd_ratio as quality metric Nov 2, 2023
Copy link
Collaborator

@zm711 zm711 left a comment

Choose a reason for hiding this comment

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

@DradeAW,

I know this is still in draft, but I tagged a couple notes. You can ignore and fix yourself if you want, but just wanted these on your radar.

doc/modules/qualitymetrics/sd_ratio.rst Outdated Show resolved Hide resolved
doc/modules/qualitymetrics/sd_ratio.rst Outdated Show resolved Hide resolved
doc/modules/qualitymetrics/sd_ratio.rst Outdated Show resolved Hide resolved
doc/modules/qualitymetrics/sd_ratio.rst Show resolved Hide resolved
doc/modules/qualitymetrics/sd_ratio.rst Outdated Show resolved Hide resolved
src/spikeinterface/qualitymetrics/misc_metrics.py Outdated Show resolved Hide resolved
src/spikeinterface/qualitymetrics/misc_metrics.py Outdated Show resolved Hide resolved
src/spikeinterface/qualitymetrics/misc_metrics.py Outdated Show resolved Hide resolved
src/spikeinterface/qualitymetrics/misc_metrics.py Outdated Show resolved Hide resolved
@DradeAW
Copy link
Contributor Author

DradeAW commented Nov 2, 2023

@zm711 Thanks for the feedback!
Useful and appreciated :)

I'll make the changes after my lunch!

@DradeAW DradeAW marked this pull request as ready for review November 2, 2023 14:37
@DradeAW
Copy link
Contributor Author

DradeAW commented Nov 2, 2023

Ok I like the state of the PR as it is now. A few things that are not perfect:

  • Computing noise outside of spikes from the unit (or subtracting the template)
  • Considering jitter
  • Here I'm accessing a private variable. Should we add a method get_param(key)?
    wvf_extractor.recording, return_scaled=amplitudes_ext._params["return_scaled"], method="std"

@zm711
Copy link
Collaborator

zm711 commented Nov 2, 2023

Could you also do a big favor with this PR and fix the order of qualitymetrics.rst. They are suppose to be in alphabetical order, but they got out of order. I can't comment on lines that you haven't touched, but it would be cool to have the docs fixed in this PR :)

Comment on lines +1410 to +1413
warnings.warn(
"The `sd_ratio` metric cannot work with a recordless WaveformExtractor object"
"SD ratio metric will be set to NaN"
)
Copy link
Member

Choose a reason for hiding this comment

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

we have to decide a global behavior for this. I would say lets raise no ?

spike_train = wvf_extractor.sorting.get_unit_spike_train(unit_id, segment_index=segment_index).astype(
np.int64
)
censored_indices = _find_duplicated_spikes_keep_first_iterative(spike_train, censored_period)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is a good idea this cross dependency in this way between curation and qualitymetrics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would you suggest as an alternative?

Copy link
Member

Choose a reason for hiding this comment

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

that's ok for now, but we can discuss higher-level hierarchy later

@samuelgarcia
Copy link
Member

Hi Aurelien.
Thanks for this.
If I understand corretly here the sd is computed only at peak amplitude but the 2002 paper is computing the sd on the entire waveform snipet. I think this make a big diffrences no ?
Would it be better to have the sd at waveforms levels with few spikes ( the one already extracted)

@DradeAW
Copy link
Contributor Author

DradeAW commented Nov 15, 2023

Yes this is different than the 2002 paper (in multiple ways), but I still cited it because it was the first one to write down the idea.

We can talk about it. I found this implementation easier, but you are right there may be more information available by using the whole waveform (although it makes drift correction and censored period trickier).

@DradeAW
Copy link
Contributor Author

DradeAW commented Nov 17, 2023

The test is failing because of a bug that is solved by #2220

@alejoe91 alejoe91 merged commit 20974b3 into SpikeInterface:main Nov 22, 2023
10 of 11 checks passed
@DradeAW DradeAW deleted the sd_test branch November 22, 2023 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qualitymetrics Related to qualitymetrics module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants