@@ -45,12 +45,16 @@ def validate_curation_dict(curation_dict):
4545 if not removed_units_set .issubset (unit_set ):
4646 raise ValueError ("Curation format: some removed units are not in the unit list" )
4747
48+ for group in curation_dict ["merge_unit_groups" ]:
49+ if len (group ) < 2 :
50+ raise ValueError ("Curation format: 'merge_unit_groups' must be list of list with at least 2 elements" )
51+
4852 all_merging_groups = [set (group ) for group in curation_dict ["merge_unit_groups" ]]
4953 for gp_1 , gp_2 in combinations (all_merging_groups , 2 ):
5054 if len (gp_1 .intersection (gp_2 )) != 0 :
51- raise ValueError ("Some units belong to multiple merge groups" )
55+ raise ValueError ("Curation format: some units belong to multiple merge groups" )
5256 if len (removed_units_set .intersection (merged_units_set )) != 0 :
53- raise ValueError ("Some units were merged and deleted" )
57+ raise ValueError ("Curation format: some units were merged and deleted" )
5458
5559 # Check the labels exclusivity
5660 for lbl in curation_dict ["manual_labels" ]:
@@ -238,7 +242,7 @@ def apply_curation_labels(sorting, new_unit_ids, curation_dict):
238242 all_values = np .zeros (sorting .unit_ids .size , dtype = values .dtype )
239243 for unit_ind , unit_id in enumerate (sorting .unit_ids ):
240244 if unit_id not in new_unit_ids :
241- ind = curation_dict ["unit_ids" ].index (unit_id )
245+ ind = list ( curation_dict ["unit_ids" ]) .index (unit_id )
242246 all_values [unit_ind ] = values [ind ]
243247 sorting .set_property (key , all_values )
244248
@@ -253,7 +257,7 @@ def apply_curation_labels(sorting, new_unit_ids, curation_dict):
253257 group_values .append (value )
254258 if len (set (group_values )) == 1 :
255259 # all group has the same label or empty
256- sorting .set_property (key , values = group_values , ids = [new_unit_id ])
260+ sorting .set_property (key , values = group_values [: 1 ] , ids = [new_unit_id ])
257261 else :
258262
259263 for key in label_def ["label_options" ]:
@@ -339,18 +343,22 @@ def apply_curation(
339343
340344 elif isinstance (sorting_or_analyzer , SortingAnalyzer ):
341345 analyzer = sorting_or_analyzer
342- analyzer = analyzer .remove_units (curation_dict ["removed_units" ])
343- analyzer , new_unit_ids = analyzer .merge_units (
344- curation_dict ["merge_unit_groups" ],
345- censor_ms = censor_ms ,
346- merging_mode = merging_mode ,
347- sparsity_overlap = sparsity_overlap ,
348- new_id_strategy = new_id_strategy ,
349- return_new_unit_ids = True ,
350- format = "memory" ,
351- verbose = verbose ,
352- ** job_kwargs ,
353- )
346+ if len (curation_dict ["removed_units" ]) > 0 :
347+ analyzer = analyzer .remove_units (curation_dict ["removed_units" ])
348+ if len (curation_dict ["merge_unit_groups" ]) > 0 :
349+ analyzer , new_unit_ids = analyzer .merge_units (
350+ curation_dict ["merge_unit_groups" ],
351+ censor_ms = censor_ms ,
352+ merging_mode = merging_mode ,
353+ sparsity_overlap = sparsity_overlap ,
354+ new_id_strategy = new_id_strategy ,
355+ return_new_unit_ids = True ,
356+ format = "memory" ,
357+ verbose = verbose ,
358+ ** job_kwargs ,
359+ )
360+ else :
361+ new_unit_ids = []
354362 apply_curation_labels (analyzer .sorting , new_unit_ids , curation_dict )
355363 return analyzer
356364 else :
0 commit comments