Skip to content

Commit 55adef6

Browse files
committed
Assertion messages, importlib, and job_kwargs docs
1 parent 81b7373 commit 55adef6

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

src/spikeinterface/postprocessing/correlograms.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import numpy as np
1414

1515
from spikeinterface.core import BaseSorting
16-
from spikeinterface.core.job_tools import fix_job_kwargs
16+
from spikeinterface.core.job_tools import fix_job_kwargs, _shared_job_kwargs_doc
1717
from spikeinterface.core.sortinganalyzer import (
1818
AnalyzerExtension,
1919
SortingAnalyzer,
@@ -272,7 +272,7 @@ def _make_bins(sorting, window_ms, bin_ms) -> tuple[np.ndarray, int, int]:
272272
bin_size = int(round(fs * bin_ms * 1e-3))
273273
window_size -= window_size % bin_size
274274
num_bins = 2 * int(window_size / bin_size)
275-
assert num_bins >= 1
275+
assert num_bins >= 1, "Number of bins must be >= 1"
276276

277277
bins = np.arange(-window_size, window_size + bin_size, bin_size) * 1e3 / fs
278278

@@ -330,7 +330,7 @@ def _compute_correlograms_on_sorting(sorting, window_ms, bin_ms, method="auto"):
330330
bins : np.array
331331
The bins edges in ms
332332
"""
333-
assert method in ("auto", "numba", "numpy")
333+
assert method in ("auto", "numba", "numpy"), "method must be 'auto', 'numba' or 'numpy'"
334334

335335
if method == "auto":
336336
method = "numba" if HAVE_NUMBA else "numpy"
@@ -771,8 +771,7 @@ def _compute_acgs_3d(
771771
The number of quantiles to use for firing rate bins.
772772
smoothing_factor : float, default: 250
773773
The width of the smoothing kernel in milliseconds.
774-
n_jobs : int, default: -1.
775-
Number of parallel jobs to spawn to compute the 3D-ACGS on different units.
774+
{}
776775
777776
Returns
778777
-------
@@ -841,7 +840,7 @@ def _compute_acgs_3d(
841840
acgs_3d[unit_index, :, :] = acg_3d
842841
firing_quantiles[unit_index, :] = firing_quantile
843842
else:
844-
# Process units in serial
843+
# Process units serially
845844
for unit_index, (
846845
sorting,
847846
unit_id,
@@ -868,6 +867,8 @@ def _compute_acgs_3d(
868867
register_result_extension(ComputeACG3D)
869868
compute_acgs_3d_sorting_analyzer = ComputeACG3D.function_factory()
870869

870+
_compute_acgs_3d.__doc__ = _compute_acgs_3d.__doc__.format(_shared_job_kwargs_doc)
871+
871872

872873
def _compute_3d_acg_one_unit(
873874
sorting: BaseSorting,
@@ -884,8 +885,8 @@ def _compute_3d_acg_one_unit(
884885
bin_size = np.clip(bin_size, 1000 * 1.0 / fs, 1e8) # in milliseconds
885886
win_size = np.clip(win_size, 1e-2, 1e8) # in milliseconds
886887
winsize_bins = 2 * int(0.5 * win_size * 1.0 / bin_size) + 1 # Both in millisecond
887-
assert winsize_bins >= 1
888-
assert winsize_bins % 2 == 1
888+
assert winsize_bins >= 1, "Number of bins must be >= 1"
889+
assert winsize_bins % 2 == 1, "Number of bins must be odd"
889890
bin_times_ms = np.linspace(-win_size / 2, win_size / 2, num=winsize_bins)
890891

891892
if firing_rate_quantiles is not None:
@@ -989,6 +990,7 @@ def compute_acgs_3d(
989990
bin_ms: float = 1.0,
990991
num_firing_rate_quantiles: int = 10,
991992
smoothing_factor: int = 250,
993+
**job_kwargs,
992994
):
993995
"""
994996
Compute 3D Autocorrelograms. See ComputeACG3D() for a detailed documentation.
@@ -1003,6 +1005,7 @@ def compute_acgs_3d(
10031005
bin_ms=bin_ms,
10041006
num_firing_rate_quantiles=num_firing_rate_quantiles,
10051007
smoothing_factor=smoothing_factor,
1008+
**job_kwargs,
10061009
)
10071010
else:
10081011
return _compute_acgs_3d(
@@ -1011,6 +1014,7 @@ def compute_acgs_3d(
10111014
bin_ms=bin_ms,
10121015
num_firing_rate_quantiles=num_firing_rate_quantiles,
10131016
smoothing_factor=smoothing_factor,
1017+
**job_kwargs,
10141018
)
10151019

10161020

src/spikeinterface/postprocessing/tests/test_correlograms.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import numpy as np
2+
import importlib
23

3-
try:
4-
import numba
5-
4+
numba_spec = importlib.util.find_spec("numba")
5+
if numba_spec is not None:
66
HAVE_NUMBA = True
7-
except ModuleNotFoundError as err:
7+
else:
88
HAVE_NUMBA = False
99

10-
try:
11-
import npyx
12-
10+
npyx_spec = importlib.util.find_spec("npyx")
11+
if npyx_spec is not None:
1312
HAVE_NPYX = True
14-
except ModuleNotFoundError:
13+
else:
1514
HAVE_NPYX = False
1615

16+
1717
import pytest
1818
from pytest import param
1919

0 commit comments

Comments
 (0)