Skip to content

Commit

Permalink
Merge pull request #1865 from yger/name_radius
Browse files Browse the repository at this point in the history
Harmonize radius_um
  • Loading branch information
samuelgarcia authored Jul 21, 2023
2 parents 3d14d1c + c35ff61 commit fecc213
Show file tree
Hide file tree
Showing 26 changed files with 108 additions and 114 deletions.
4 changes: 2 additions & 2 deletions doc/how_to/analyse_neuropixels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ Let’s use here the ``locally_exclusive`` method for detection and the
job_kwargs = dict(n_jobs=40, chunk_duration='1s', progress_bar=True)
peaks = detect_peaks(rec, method='locally_exclusive', noise_levels=noise_levels_int16,
detect_threshold=5, local_radius_um=50., **job_kwargs)
detect_threshold=5, radius_um=50., **job_kwargs)
peaks
Expand All @@ -451,7 +451,7 @@ Let’s use here the ``locally_exclusive`` method for detection and the
from spikeinterface.sortingcomponents.peak_localization import localize_peaks
peak_locations = localize_peaks(rec, peaks, method='center_of_mass', local_radius_um=50., **job_kwargs)
peak_locations = localize_peaks(rec, peaks, method='center_of_mass', radius_um=50., **job_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion doc/how_to/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ available parameters are dictionaries and can be accessed with:
'clustering': {},
'detection': {'detect_threshold': 5, 'peak_sign': 'neg'},
'filtering': {'dtype': 'float32'},
'general': {'local_radius_um': 100, 'ms_after': 2, 'ms_before': 2},
'general': {'radius_um': 100, 'ms_after': 2, 'ms_before': 2},
'job_kwargs': {},
'localization': {},
'matching': {},
Expand Down
4 changes: 2 additions & 2 deletions doc/how_to/handle_drift.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ to load them later.
'peak_sign': 'neg',
'detect_threshold': 8.0,
'exclude_sweep_ms': 0.1,
'local_radius_um': 50},
'radius_um': 50},
'select_kwargs': None,
'localize_peaks_kwargs': {'method': 'grid_convolution',
'local_radius_um': 30.0,
'radius_um': 30.0,
'upsampling_um': 3.0,
'sigma_um': array([ 5. , 12.5, 20. ]),
'sigma_ms': 0.25,
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/motion_correction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ The high-level :py:func:`~spikeinterface.preprocessing.correct_motion()` is inte
peaks = detect_peaks(rec, method="locally_exclusive", detect_threshold=8.0, **job_kwargs)
# (optional) sub-select some peaks to speed up the localization
peaks = select_peaks(peaks, ...)
peak_locations = localize_peaks(rec, peaks, method="monopolar_triangulation",local_radius_um=75.0,
peak_locations = localize_peaks(rec, peaks, method="monopolar_triangulation",radius_um=75.0,
max_distance_um=150.0, **job_kwargs)
# Step 2: motion inference
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/sortingcomponents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ follows:
peak_sign='neg',
detect_threshold=5,
exclude_sweep_ms=0.2,
local_radius_um=100,
radius_um=100,
noise_levels=None,
random_chunk_kwargs={},
outputs='numpy_compact',
Expand Down Expand Up @@ -95,7 +95,7 @@ follows:
job_kwargs = dict(chunk_duration='1s', n_jobs=8, progress_bar=True)
peak_locations = localize_peaks(recording, peaks, method='center_of_mass',
local_radius_um=70., ms_before=0.3, ms_after=0.6,
radius_um=70., ms_before=0.3, ms_after=0.6,
**job_kwargs)
Expand Down
4 changes: 2 additions & 2 deletions examples/how_to/analyse_neuropixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@

job_kwargs = dict(n_jobs=40, chunk_duration='1s', progress_bar=True)
peaks = detect_peaks(rec, method='locally_exclusive', noise_levels=noise_levels_int16,
detect_threshold=5, local_radius_um=50., **job_kwargs)
detect_threshold=5, radius_um=50., **job_kwargs)
peaks

# +
from spikeinterface.sortingcomponents.peak_localization import localize_peaks

peak_locations = localize_peaks(rec, peaks, method='center_of_mass', local_radius_um=50., **job_kwargs)
peak_locations = localize_peaks(rec, peaks, method='center_of_mass', radius_um=50., **job_kwargs)
# -

# ### Check for drift
Expand Down
2 changes: 1 addition & 1 deletion examples/modules_gallery/widgets/plot_4_peaks_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
peaks = detect_peaks(
rec_filtred, method='locally_exclusive',
peak_sign='neg', detect_threshold=6, exclude_sweep_ms=0.3,
local_radius_um=100,
radius_um=100,
noise_levels=None,
random_chunk_kwargs={},
chunk_memory='10M', n_jobs=1, progress_bar=True)
Expand Down
4 changes: 2 additions & 2 deletions src/spikeinterface/postprocessing/unit_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def enforce_decrease_shells_data(wf_data, maxchan, radial_parents, in_place=Fals


def get_grid_convolution_templates_and_weights(
contact_locations, local_radius_um=50, upsampling_um=5, sigma_um=np.linspace(10, 50.0, 5), margin_um=50
contact_locations, radius_um=50, upsampling_um=5, sigma_um=np.linspace(10, 50.0, 5), margin_um=50
):
x_min, x_max = contact_locations[:, 0].min(), contact_locations[:, 0].max()
y_min, y_max = contact_locations[:, 1].min(), contact_locations[:, 1].max()
Expand Down Expand Up @@ -597,7 +597,7 @@ def get_grid_convolution_templates_and_weights(

# mask to get nearest template given a channel
dist = sklearn.metrics.pairwise_distances(contact_locations, template_positions)
nearest_template_mask = dist < local_radius_um
nearest_template_mask = dist < radius_um

weights = np.zeros((len(sigma_um), len(contact_locations), nb_templates), dtype=np.float32)
for count, sigma in enumerate(sigma_um):
Expand Down
12 changes: 6 additions & 6 deletions src/spikeinterface/preprocessing/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
peak_sign="neg",
detect_threshold=8.0,
exclude_sweep_ms=0.1,
local_radius_um=50,
radius_um=50,
),
"select_kwargs": None,
"localize_peaks_kwargs": dict(
method="monopolar_triangulation",
local_radius_um=75.0,
radius_um=75.0,
max_distance_um=150.0,
optimizer="minimize_with_log_penality",
enforce_decrease=True,
Expand Down Expand Up @@ -81,12 +81,12 @@
peak_sign="neg",
detect_threshold=8.0,
exclude_sweep_ms=0.1,
local_radius_um=50,
radius_um=50,
),
"select_kwargs": None,
"localize_peaks_kwargs": dict(
method="center_of_mass",
local_radius_um=75.0,
radius_um=75.0,
feature="ptp",
),
"estimate_motion_kwargs": dict(
Expand All @@ -109,12 +109,12 @@
peak_sign="neg",
detect_threshold=8.0,
exclude_sweep_ms=0.1,
local_radius_um=50,
radius_um=50,
),
"select_kwargs": None,
"localize_peaks_kwargs": dict(
method="grid_convolution",
local_radius_um=40.0,
radius_um=40.0,
upsampling_um=5.0,
sigma_um=np.linspace(5.0, 25.0, 5),
sigma_ms=0.25,
Expand Down
6 changes: 3 additions & 3 deletions src/spikeinterface/sorters/internal/spyking_circus2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Spykingcircus2Sorter(ComponentsBasedSorter):
sorter_name = "spykingcircus2"

_default_params = {
"general": {"ms_before": 2, "ms_after": 2, "local_radius_um": 100},
"general": {"ms_before": 2, "ms_after": 2, "radius_um": 100},
"waveforms": {"max_spikes_per_unit": 200, "overwrite": True},
"filtering": {"dtype": "float32"},
"detection": {"peak_sign": "neg", "detect_threshold": 5},
Expand Down Expand Up @@ -75,8 +75,8 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose):
## Then, we are detecting peaks with a locally_exclusive method
detection_params = params["detection"].copy()
detection_params.update(job_kwargs)
if "local_radius_um" not in detection_params:
detection_params["local_radius_um"] = params["general"]["local_radius_um"]
if "radius_um" not in detection_params:
detection_params["radius_um"] = params["general"]["radius_um"]
if "exclude_sweep_ms" not in detection_params:
detection_params["exclude_sweep_ms"] = max(params["general"]["ms_before"], params["general"]["ms_after"])

Expand Down
8 changes: 4 additions & 4 deletions src/spikeinterface/sorters/internal/tridesclous2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Tridesclous2Sorter(ComponentsBasedSorter):

_default_params = {
"apply_preprocessing": True,
"general": {"ms_before": 2.5, "ms_after": 3.5, "local_radius_um": 100},
"general": {"ms_before": 2.5, "ms_after": 3.5, "radius_um": 100},
"filtering": {"freq_min": 300, "freq_max": 8000.0},
"detection": {"peak_sign": "neg", "detect_threshold": 5, "exclude_sweep_ms": 0.4},
"hdbscan_kwargs": {
Expand Down Expand Up @@ -68,7 +68,7 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose):

# detection
detection_params = params["detection"].copy()
detection_params["local_radius_um"] = params["general"]["local_radius_um"]
detection_params["radius_um"] = params["general"]["radius_um"]
detection_params["noise_levels"] = noise_levels
peaks = detect_peaks(recording, method="locally_exclusive", **detection_params, **job_kwargs)

Expand All @@ -89,7 +89,7 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose):

# localization
localization_params = params["localization"].copy()
localization_params["local_radius_um"] = params["general"]["local_radius_um"]
localization_params["radius_um"] = params["general"]["radius_um"]
peak_locations = localize_peaks(
recording, some_peaks, method="monopolar_triangulation", **localization_params, **job_kwargs
)
Expand Down Expand Up @@ -127,7 +127,7 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose):
matching_params["noise_levels"] = noise_levels
matching_params["peak_sign"] = params["detection"]["peak_sign"]
matching_params["detect_threshold"] = params["detection"]["detect_threshold"]
matching_params["local_radius_um"] = params["general"]["local_radius_um"]
matching_params["radius_um"] = params["general"]["radius_um"]

# TODO: route that params
# ~ 'num_closest' : 5,
Expand Down
4 changes: 2 additions & 2 deletions src/spikeinterface/sortingcomponents/clustering/circus.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CircusClustering:
},
"cleaning_kwargs": {},
"tmp_folder": None,
"local_radius_um": 100,
"radius_um": 100,
"n_pca": 10,
"max_spikes_per_unit": 200,
"ms_before": 1.5,
Expand Down Expand Up @@ -104,7 +104,7 @@ def main_function(cls, recording, peaks, params):
chan_distances = get_channel_distances(recording)

for main_chan in unit_inds:
(closest_chans,) = np.nonzero(chan_distances[main_chan, :] <= params["local_radius_um"])
(closest_chans,) = np.nonzero(chan_distances[main_chan, :] <= params["radius_um"])
sparsity_mask[main_chan, closest_chans] = True

if params["waveform_mode"] == "shared_memory":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PositionAndFeaturesClustering:
"cluster_selection_method": "leaf",
},
"cleaning_kwargs": {},
"local_radius_um": 100,
"radius_um": 100,
"max_spikes_per_unit": 200,
"selection_method": "random",
"ms_before": 1.5,
Expand Down Expand Up @@ -69,9 +69,9 @@ def main_function(cls, recording, peaks, params):

features_list = [position_method, "ptp", "energy"]
features_params = {
position_method: {"local_radius_um": params["local_radius_um"]},
"ptp": {"all_channels": False, "local_radius_um": params["local_radius_um"]},
"energy": {"local_radius_um": params["local_radius_um"]},
position_method: {"radius_um": params["radius_um"]},
"ptp": {"all_channels": False, "radius_um": params["radius_um"]},
"energy": {"radius_um": params["radius_um"]},
}

features_data = compute_features_from_peaks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RandomProjectionClustering:
"cluster_selection_method": "leaf",
},
"cleaning_kwargs": {},
"local_radius_um": 100,
"radius_um": 100,
"max_spikes_per_unit": 200,
"selection_method": "closest_to_centroid",
"nb_projections": {"ptp": 8, "energy": 2},
Expand Down Expand Up @@ -106,7 +106,7 @@ def main_function(cls, recording, peaks, params):

projections = np.random.randn(num_chans, d["nb_projections"][proj_type])
features_params[f"random_projections_{proj_type}"] = {
"local_radius_um": params["local_radius_um"],
"radius_um": params["radius_um"],
"projections": projections,
"min_values": min_values,
}
Expand Down
Loading

0 comments on commit fecc213

Please sign in to comment.