Skip to content
Open
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
9 changes: 1 addition & 8 deletions src/spikeinterface/extractors/cbin_ibl.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,7 @@ def __init__(self, folder_path=None, load_sync_channel=False, stream_name="ap",
else:
self.set_probe(probe, in_place=True)

# load num_channels_per_adc depending on probe type
ptype = probe.annotations["probe_type"]

if ptype in [21, 24]: # NP2.0
num_channels_per_adc = 16
else: # NP1.0
num_channels_per_adc = 12
sample_shifts = get_neuropixels_sample_shifts_from_probe(probe, num_channels_per_adc)
sample_shifts = get_neuropixels_sample_shifts_from_probe(probe)
self.set_property("inter_sample_shift", sample_shifts)

self._kwargs = {
Expand Down
14 changes: 14 additions & 0 deletions src/spikeinterface/metrics/quality/quality_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ def _handle_backward_compatibility_on_load(self):
if "peak_sign" in self.params["metric_params"]["amplitude_median"]:
del self.params["metric_params"]["amplitude_median"]["peak_sign"]

# TODO: update this once `main_channel_index` PR is merged
# global peak_sign used to find appropriate channels for pca metric computation
# If not found, use a "peak_sign" set by any metric
global_peak_sign_from_params = self.params.get("peak_sign")
if global_peak_sign_from_params is None:
for metric_params in self.params["metric_params"].values():
if "peak_sign" in metric_params:
global_peak_sign_from_params = metric_params["peak_sign"]
break
# If still not found, use <0.104.0 default, "neg"
if global_peak_sign_from_params is None:
global_peak_sign_from_params = "neg"
self.params["peak_sign"] = global_peak_sign_from_params

def _set_params(
self,
metric_names: list[str] | None = None,
Expand Down
15 changes: 10 additions & 5 deletions src/spikeinterface/metrics/template/template_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ def _handle_backward_compatibility_on_load(self):
if "waveform_ratios" not in self.params["metric_names"]:
self.params["metric_names"].append("waveform_ratios")

# If original analyzer doesn't have "peaks_data" or "main_channel_templates",
# then we can't save this tmp data (important for merges/splits)
if "peaks_data" not in self.data:
self.tmp_data_to_save = []

def _set_params(
self,
metric_names: list[str] | None = None,
Expand Down Expand Up @@ -234,12 +239,12 @@ def _prepare_data(self, sorting_analyzer, unit_ids):
unit_ids = sorting_analyzer.unit_ids
peak_sign = self.params["peak_sign"]
upsampling_factor = self.params["upsampling_factor"]
min_thresh_detect_peaks_troughs = self.params["min_thresh_detect_peaks_troughs"]
edge_exclusion_ms = self.params.get("edge_exclusion_ms", 0.1)
min_thresh_detect_peaks_troughs = self.params.get("min_thresh_detect_peaks_troughs", 0.3)
edge_exclusion_ms = self.params.get("edge_exclusion_ms", 0.09)
min_peak_trough_distance_ratio = self.params.get("min_peak_trough_distance_ratio", 0.2)
min_extremum_distance_samples = self.params.get("min_extremum_distance_samples", 3)
sampling_frequency = sorting_analyzer.sampling_frequency
if self.params["upsampling_factor"] > 1:
if upsampling_factor > 1:
sampling_frequency_up = upsampling_factor * sampling_frequency
else:
sampling_frequency_up = sampling_frequency
Expand All @@ -249,7 +254,7 @@ def _prepare_data(self, sorting_analyzer, unit_ids):
m in get_multi_channel_template_metric_names() for m in self.params["metrics_to_compute"]
)

operator = self.params["template_operator"]
operator = self.params.get("template_operator", "average")
extremum_channel_indices = get_template_extremum_channel(
sorting_analyzer, peak_sign=peak_sign, outputs="index", operator=operator
)
Expand Down Expand Up @@ -312,7 +317,7 @@ def _prepare_data(self, sorting_analyzer, unit_ids):
# multi_channel_templates is a list of 2D arrays of shape (n_times, n_channels)
tmp_data["multi_channel_templates"] = multi_channel_templates
tmp_data["channel_locations_multi"] = channel_locations_multi
tmp_data["depth_direction"] = self.params["depth_direction"]
tmp_data["depth_direction"] = self.params.get("depth_direction", "y")

# Add peaks_info and preprocessed templates to self.data for storage in extension
columns = []
Expand Down
17 changes: 13 additions & 4 deletions src/spikeinterface/postprocessing/tests/test_valid_unit_periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_user_defined_periods(self):
periods[idx]["unit_index"] = unit_index
period_start = num_samples // 4
period_duration = num_samples // 2
periods[idx]["start_sample_index"] = period_start
periods[idx]["end_sample_index"] = period_start + period_duration
periods[idx]["start_sample_index"] = period_start - unit_index * 10
periods[idx]["end_sample_index"] = period_start + period_duration + unit_index * 10
periods[idx]["segment_index"] = segment_index

sorting_analyzer = self._prepare_sorting_analyzer(
Expand All @@ -48,8 +48,17 @@ def test_user_defined_periods(self):
minimum_valid_period_duration=1,
)
# check that valid periods correspond to user defined periods
ext_periods = ext.get_data(outputs="numpy")
np.testing.assert_array_equal(ext_periods, periods)
ext_periods_numpy = ext.get_data(outputs="numpy")
np.testing.assert_array_equal(ext_periods_numpy, periods)

# check that `numpy` and `by_unit` outputs are the same
ext_periods_by_unit = ext.get_data(outputs="by_unit")
for segment_index in range(num_segments):
for unit_index, unit_id in enumerate(unit_ids):
periods_numpy_seg0 = ext_periods_numpy[ext_periods_numpy["segment_index"] == segment_index]
periods_numpy_unit = periods_numpy_seg0[periods_numpy_seg0["unit_index"] == unit_index]
period = [(periods_numpy_unit["start_sample_index"][0], periods_numpy_unit["end_sample_index"][0])]
assert period == ext_periods_by_unit[segment_index][unit_id]

def test_user_defined_periods_as_arrays(self):
unit_ids = self.sorting.unit_ids
Expand Down
6 changes: 3 additions & 3 deletions src/spikeinterface/postprocessing/valid_unit_periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,12 @@ def _get_data(self, outputs: str = "by_unit"):
for segment_index in range(self.sorting_analyzer.get_num_segments()):
segment_mask = good_periods_array["segment_index"] == segment_index
periods_dict = {}
for unit_index in unit_ids:
periods_dict[unit_index] = []
for unit_index, unit_id in enumerate(unit_ids):
periods_dict[unit_id] = []
unit_mask = good_periods_array["unit_index"] == unit_index
good_periods_unit_segment = good_periods_array[segment_mask & unit_mask]
for start, end in good_periods_unit_segment[["start_sample_index", "end_sample_index"]]:
periods_dict[unit_index].append((start, end))
periods_dict[unit_id].append((start, end))
good_periods.append(periods_dict)

return good_periods
Expand Down