Skip to content

Commit 77c84ce

Browse files
committed
Avoid repeated calls to recording.get_times() and use itertuples
1 parent 7cca649 commit 77c84ce

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

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)