Skip to content

Commit 8df1c17

Browse files
authored
Merge branch 'main' into parralel_with_thread
2 parents 87ed340 + 8a59f70 commit 8df1c17

5 files changed

Lines changed: 62 additions & 16 deletions

File tree

doc/how_to/benchmark_with_hybrid_recordings.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,9 +2531,8 @@ Although non of the sorters find all units perfectly, ``Kilosort2.5``,
25312531
``Kilosort4``, and ``SpyKING CIRCUS 2`` all find around 10-12 hybrid
25322532
units with accuracy greater than 80%. ``Kilosort4`` has a better overall
25332533
curve, being able to find almost all units with an accuracy above 50%.
2534-
``Kilosort2.5`` performs well when looking at precision (finding all
2535-
spikes in a hybrid unit), at the cost of lower recall (finding spikes
2536-
when it shouldn’t).
2534+
``Kilosort2.5`` performs well when looking at precision (not finding spikes
2535+
when it shouldn’t), but it has a lower recall (finding all spikes in the ground truth).
25372536

25382537
In this example, we showed how to:
25392538

examples/how_to/benchmark_with_hybrid_recordings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@
276276
# From the performance plots, we can see that there is no clear "winner", but `Kilosort3` definitely performs worse than the other options.
277277
#
278278
# Although non of the sorters find all units perfectly, `Kilosort2.5`, `Kilosort4`, and `SpyKING CIRCUS 2` all find around 10-12 hybrid units with accuracy greater than 80%.
279-
# `Kilosort4` has a better overall curve, being able to find almost all units with an accuracy above 50%. `Kilosort2.5` performs well when looking at precision (finding all spikes in a hybrid unit), at the cost of lower recall (finding spikes when it shouldn't).
279+
# `Kilosort4` has a better overall curve, being able to find almost all units with an accuracy above 50%. `Kilosort2.5` performs well when looking at precision (not finding spikes
280+
# when it shouldn’t), but it has a lower recall (finding all spikes in the ground truth).
280281
#
281282
#
282283
# In this example, we showed how to:

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/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)