Skip to content

Commit 3c9a039

Browse files
authored
Merge branch 'main' into zarr-dep
2 parents 5d54d40 + 749a349 commit 3c9a039

4 files changed

Lines changed: 86 additions & 33 deletions

File tree

src/spikeinterface/core/baserecording.py

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,9 @@ def get_duration(self, segment_index=None) -> float:
232232
float
233233
The duration in seconds
234234
"""
235-
segment_index = self._check_segment_index(segment_index)
236-
237-
if self.has_time_vector(segment_index):
238-
times = self.get_times(segment_index)
239-
segment_duration = times[-1] - times[0] + (1 / self.get_sampling_frequency())
240-
else:
241-
segment_num_samples = self.get_num_samples(segment_index=segment_index)
242-
segment_duration = segment_num_samples / self.get_sampling_frequency()
243-
235+
segment_duration = (
236+
self.get_end_time(segment_index) - self.get_start_time(segment_index) + (1 / self.get_sampling_frequency())
237+
)
244238
return segment_duration
245239

246240
def get_total_duration(self) -> float:
@@ -252,7 +246,7 @@ def get_total_duration(self) -> float:
252246
float
253247
The duration in seconds
254248
"""
255-
duration = sum([self.get_duration(idx) for idx in range(self.get_num_segments())])
249+
duration = sum([self.get_duration(segment_index) for segment_index in range(self.get_num_segments())])
256250
return duration
257251

258252
def get_memory_size(self, segment_index=None) -> int:
@@ -445,6 +439,40 @@ def get_times(self, segment_index=None) -> np.ndarray:
445439
times = rs.get_times()
446440
return times
447441

442+
def get_start_time(self, segment_index=None) -> float:
443+
"""Get the start time of the recording segment.
444+
445+
Parameters
446+
----------
447+
segment_index : int or None, default: None
448+
The segment index (required for multi-segment)
449+
450+
Returns
451+
-------
452+
float
453+
The start time in seconds
454+
"""
455+
segment_index = self._check_segment_index(segment_index)
456+
rs = self._recording_segments[segment_index]
457+
return rs.get_start_time()
458+
459+
def get_end_time(self, segment_index=None) -> float:
460+
"""Get the stop time of the recording segment.
461+
462+
Parameters
463+
----------
464+
segment_index : int or None, default: None
465+
The segment index (required for multi-segment)
466+
467+
Returns
468+
-------
469+
float
470+
The stop time in seconds
471+
"""
472+
segment_index = self._check_segment_index(segment_index)
473+
rs = self._recording_segments[segment_index]
474+
return rs.get_end_time()
475+
448476
def has_time_vector(self, segment_index=None):
449477
"""Check if the segment of the recording has a time vector.
450478
@@ -903,6 +931,21 @@ def get_times(self) -> np.ndarray:
903931
time_vector += self.t_start
904932
return time_vector
905933

934+
def get_start_time(self) -> float:
935+
if self.time_vector is not None:
936+
return self.time_vector[0]
937+
else:
938+
return self.t_start if self.t_start is not None else 0.0
939+
940+
def get_end_time(self) -> float:
941+
if self.time_vector is not None:
942+
return self.time_vector[-1]
943+
else:
944+
t_stop = (self.get_num_samples() - 1) / self.sampling_frequency
945+
if self.t_start is not None:
946+
t_stop += self.t_start
947+
return t_stop
948+
906949
def get_times_kwargs(self) -> dict:
907950
"""
908951
Retrieves the timing attributes characterizing a RecordingSegment

src/spikeinterface/core/loading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def load(file_or_folder_or_dict, base_folder=None) -> BaseExtractor:
104104
raise ValueError(error_msg)
105105
else:
106106
# remote case - zarr
107-
if str(file_path).endswith(".zarr"):
107+
if str(file_path).endswith(".zarr") or str(file_path).endswith(".zarr/"):
108108
from .zarrextractors import read_zarr
109109

110110
extractor = read_zarr(file_path)

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

src/spikeinterface/preprocessing/average_across_direction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ def get_traces(self, start_frame, end_frame, channel_indices):
132132
# now, divide by the number of channels at that position
133133
traces /= self.n_chans_each_pos
134134

135-
return traces[:, channel_indices]
135+
if channel_indices is not None:
136+
traces = traces[:, channel_indices]
137+
138+
return traces
136139

137140

138141
# function for API

0 commit comments

Comments
 (0)