Skip to content

Commit 463ec52

Browse files
committed
feat(spike_sorting): handle cases when no units/spikes are found
1 parent 3ab94dd commit 463ec52

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

element_array_ephys/spike_sorting/si_spike_sorting.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,17 @@ def make(self, key):
275275

276276
analyzer_output_dir = output_dir / sorter_name / "sorting_analyzer"
277277

278+
has_units = si_sorting.unit_ids.size > 0
279+
278280
@memoized_result(
279281
uniqueness_dict=postprocessing_params,
280282
output_directory=analyzer_output_dir,
281283
)
282284
def _sorting_analyzer_compute():
285+
if not has_units:
286+
log.info("No units found in sorting object. Skipping sorting analyzer.")
287+
return
288+
283289
# Sorting Analyzer
284290
sorting_analyzer = si.create_sorting_analyzer(
285291
sorting=si_sorting,
@@ -303,6 +309,8 @@ def _sorting_analyzer_compute():
303309

304310
_sorting_analyzer_compute()
305311

312+
do_si_export = postprocessing_params.get("export_to_phy", False) or postprocessing_params.get("export_report", False)
313+
306314
self.insert1(
307315
{
308316
**key,
@@ -311,8 +319,7 @@ def _sorting_analyzer_compute():
311319
datetime.utcnow() - execution_time
312320
).total_seconds()
313321
/ 3600,
314-
"do_si_export": postprocessing_params.get("export_to_phy", False)
315-
or postprocessing_params.get("export_report", False),
322+
"do_si_export": do_si_export and has_units,
316323
}
317324
)
318325

0 commit comments

Comments
 (0)