Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/spikeinterface/qualitymetrics/misc_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,48 @@ def compute_amplitude_medians(sorting_analyzer, peak_sign="neg", unit_ids=None):
_default_params["amplitude_median"] = dict(peak_sign="neg")


def compute_waveform_ptp_medians(sorting_analyzer, unit_ids=None):
"""
Compute median of the peak-to-peak (PTP) values of the waveforms.

Parameters
----------
sorting_analyzer : SortingAnalyzer
A SortingAnalyzer object.
unit_ids : list or None
List of unit ids to compute the waveform PTP medians. If None, all units are used.

Returns
-------
all_waveform_ptp_medians : dict
Estimated waveform PTP median for each unit ID.

References
----------
Inspired by bombcell folks
"""
if unit_ids is None:
unit_ids = sorting_analyzer.unit_ids

_has_required_extensions(sorting_analyzer, metric_name="waveform_ptp_median")

wfs_ext = sorting_analyzer.get_extension("waveforms")
extremum_channel_indices = get_template_extremum_channel(sorting_analyzer, outputs="index", mode="peak_to_peak")
all_waveform_ptp_medians = {}

for unit_id in unit_ids:
waveforms = wfs_ext.get_waveforms_one_unit(unit_id, force_dense=True)
waveform_max_channel = waveforms[:, :, extremum_channel_indices[unit_id]]
ptps = np.ptp(waveform_max_channel, axis=1)
median_ptp = np.median(ptps)
all_waveform_ptp_medians[unit_id] = median_ptp

return all_waveform_ptp_medians


_default_params["waveform_ptp_median"] = dict()


def compute_drift_metrics(
sorting_analyzer,
interval_s=60,
Expand Down
5 changes: 5 additions & 0 deletions src/spikeinterface/qualitymetrics/quality_metric_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"drift": ["spike_locations"],
"sd_ratio": ["templates", "spike_amplitudes"],
"noise_cutoff": ["spike_amplitudes"],
"waveform_ptp_median": ["templates", "waveforms"],
}


Expand All @@ -30,6 +31,7 @@
compute_amplitude_cv_metrics,
compute_sd_ratio,
compute_noise_cutoffs,
compute_waveform_ptp_medians,
)

from .pca_metrics import (
Expand Down Expand Up @@ -64,6 +66,7 @@
"drift": compute_drift_metrics,
"sd_ratio": compute_sd_ratio,
"noise_cutoff": compute_noise_cutoffs,
"waveform_ptp_median": compute_waveform_ptp_medians,
}


Expand Down Expand Up @@ -96,6 +99,7 @@
"silhouette": ["silhouette"],
"silhouette_full": ["silhouette_full"],
"noise_cutoff": ["noise_cutoff", "noise_ratio"],
"waveform_ptp_median": ["waveform_ptp_median"],
}

# this dict allows us to ensure the appropriate dtype of metrics rather than allow Pandas to infer them
Expand Down Expand Up @@ -133,4 +137,5 @@
"silhouette_full": float,
"noise_cutoff": float,
"noise_ratio": float,
"waveform_ptp_median": float,
}
Loading