Skip to content

Commit 90c4d13

Browse files
committed
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into parralel_with_thread
2 parents 4a8e622 + dbd433d commit 90c4d13

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

src/spikeinterface/extractors/neuropixels_utils.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
11
from __future__ import annotations
22

33
import numpy as np
4+
from typing import Optional
45

56

6-
def get_neuropixels_sample_shifts(num_channels=384, num_channels_per_adc=12, num_cycles=None):
7+
def get_neuropixels_sample_shifts(
8+
num_channels: int = 384, num_channels_per_adc: int = 12, num_cycles: Optional[int] = None
9+
) -> np.ndarray:
710
"""
8-
Calculates the relative sampling phase of each channel that results
9-
from Neuropixels ADC multiplexing.
11+
Calculate the relative sampling phase (inter-sample shifts) for each channel
12+
in Neuropixels probes due to ADC multiplexing.
1013
11-
This information is needed to perform the preprocessing.phase_shift operation.
14+
Neuropixels probes sample channels sequentially through multiple ADCs,
15+
introducing slight temporal delays between channels within each sampling cycle.
16+
These inter-sample shifts are fractions of the sampling period and are crucial
17+
to consider during preprocessing steps, such as phase correction, to ensure
18+
accurate alignment of the recorded signals.
1219
13-
See https://github.com/int-brain-lab/ibllib/blob/master/ibllib/ephys/neuropixel.py
14-
15-
16-
for the original implementation.
20+
This function computes these relative phase shifts, returning an array where
21+
each value represents the fractional delay (ranging from 0 to 1) for the
22+
corresponding channel.
1723
1824
Parameters
1925
----------
2026
num_channels : int, default: 384
21-
The total number of channels in a recording.
22-
All currently available Neuropixels variants have 384 channels.
27+
Total number of channels in the recording.
28+
Neuropixels probes typically have 384 channels.
2329
num_channels_per_adc : int, default: 12
24-
The number of channels per ADC on the probe.
25-
Neuropixels 1.0 probes have 12 ADCs.
30+
Number of channels assigned to each ADC on the probe.
31+
Neuropixels 1.0 probes have 12 ADCs, each handling 32 channels.
2632
Neuropixels 2.0 probes have 16 ADCs.
27-
num_cycles: int or None, default: None
28-
The number of cycles in the ADC on the probe.
29-
Neuropixels 1.0 probes have 13 cycles for AP and 12 for LFP.
33+
num_cycles : int or None, default: None
34+
Number of cycles in the ADC sampling sequence.
35+
Neuropixels 1.0 probes have 13 cycles for AP (action potential) signals
36+
and 12 for LFP (local field potential) signals.
3037
Neuropixels 2.0 probes have 16 cycles.
31-
If None, the num_channels_per_adc is used.
38+
If None, defaults to the value of `num_channels_per_adc`.
3239
3340
Returns
3441
-------
35-
sample_shifts : ndarray
36-
The relative phase (from 0-1) of each channel
42+
sample_shifts : np.ndarray
43+
Array of relative phase shifts for each channel, with values ranging from 0 to 1,
44+
representing the fractional delay within the sampling period due to sequential ADC sampling.
3745
"""
3846
if num_cycles is None:
3947
num_cycles = num_channels_per_adc
@@ -44,9 +52,8 @@ def get_neuropixels_sample_shifts(num_channels=384, num_channels_per_adc=12, num
4452

4553
sample_shifts = np.zeros_like(adc_indices)
4654

47-
for a in adc_indices:
48-
sample_shifts[adc_indices == a] = np.arange(num_channels_per_adc) / num_cycles
49-
55+
for adc_index in adc_indices:
56+
sample_shifts[adc_indices == adc_index] = np.arange(num_channels_per_adc) / num_cycles
5057
return sample_shifts
5158

5259

0 commit comments

Comments
 (0)