Skip to content

Commit 202249f

Browse files
authored
Speedup get_sorting (#1246)
* Avoid repeated calls to recording.get_times() and use itertuples * Update changelog
1 parent 7cca649 commit 202249f

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
- Spikesorting
2323
- Fix compatibility bug between v1 pipeline and `SortedSpikesGroup` unit
2424
filtering #1238
25-
25+
- Speedup `get_sorting` on `CurationV1` #1246
2626
- Behavior
2727
- Implement pipeline for keypoint-moseq extraction of behavior syllables #1056
2828

29-
3029
## [0.5.4] (December 20, 2024)
3130

3231
### Infrastructure

src/spyglass/spikesorting/v1/curation.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,22 @@ def get_sorting(cls, key: dict) -> si.BaseSorting:
203203
analysis_file_abs_path = AnalysisNwbfile.get_abs_path(
204204
analysis_file_name
205205
)
206+
206207
with pynwb.NWBHDF5IO(
207208
analysis_file_abs_path, "r", load_namespaces=True
208209
) as io:
209210
nwbf = io.read()
210211
units = nwbf.units.to_dataframe()
211-
units_dict_list = [
212-
{
213-
unit_id: np.searchsorted(recording.get_times(), spike_times)
214-
for unit_id, spike_times in zip(
215-
units.index, units["spike_times"]
216-
)
217-
}
218-
]
219212

220-
sorting = si.NumpySorting.from_unit_dict(
221-
units_dict_list, sampling_frequency=sampling_frequency
222-
)
213+
recording_times = recording.get_times()
214+
units_dict = {
215+
unit.Index: np.searchsorted(recording_times, unit.spike_times)
216+
for unit in units.itertuples()
217+
}
223218

224-
return sorting
219+
return si.NumpySorting.from_unit_dict(
220+
[units_dict], sampling_frequency=sampling_frequency
221+
)
225222

226223
@classmethod
227224
def get_merged_sorting(cls, key: dict) -> si.BaseSorting:

0 commit comments

Comments
 (0)