@@ -473,27 +473,31 @@ def explore_folder(dirname):
473473 info ['nb_segment' ] += 1
474474
475475 # order continuous file by channel number within segment
476+ # order "CH before "ADC"
476477 for seg_index , continuous_filenames in info ['continuous' ].items ():
477- chan_ids = {}
478+ chan_ids_by_type = {}
479+ filenames_by_type = {}
478480 for continuous_filename in continuous_filenames :
479481 s = continuous_filename .replace ('.continuous' , '' ).split ('_' )
480482 processor_id , ch_name = s [0 ], s [1 ]
481- chan_str = re .split (r'(\d+)' , s [1 ])[0 ]
482- chan_id = int (ch_name .replace (chan_str , '' ))
483- if chan_str in chan_ids .keys ():
484- chan_ids [chan_str ].append (chan_id )
483+ chan_type = re .split (r'(\d+)' , s [1 ])[0 ]
484+ chan_id = int (ch_name .replace (chan_type , '' ))
485+ if chan_type in chan_ids_by_type .keys ():
486+ chan_ids_by_type [chan_type ].append (chan_id )
487+ filenames_by_type [chan_type ].append (continuous_filename )
485488 else :
486- chan_ids [chan_str ] = [chan_id ]
487- order = []
488- for type in chan_ids .keys ():
489- order .append (np .argsort (chan_ids [type ]))
490- order = [list .tolist () for list in order ]
491- for i , sublist in enumerate (order ):
492- if i > 0 :
493- order [i ] = [x + max (order [i - 1 ]) + 1 for x in order [i ]]
494- order = [item for sublist in order for item in sublist ]
495- continuous_filenames = [continuous_filenames [i ] for i in order ]
496- info ['continuous' ][seg_index ] = continuous_filenames
489+ chan_ids_by_type [chan_type ] = [chan_id ]
490+ filenames_by_type [chan_type ] = [continuous_filename ]
491+ chan_types = list (chan_ids_by_type .keys ())
492+ if chan_types [0 ] == 'ADC' :
493+ # put ADC at last position
494+ chan_types = chan_types [1 :] + chan_types [0 :1 ]
495+ ordered_continuous_filenames = []
496+ for chan_type in chan_types :
497+ local_order = np .argsort (chan_ids_by_type [chan_type ])
498+ local_filenames = np .array (filenames_by_type [chan_type ])[local_order ]
499+ ordered_continuous_filenames .extend (local_filenames )
500+ info ['continuous' ][seg_index ] = ordered_continuous_filenames
497501
498502 # order spike files within segment
499503 for seg_index , spike_filenames in info ['spikes' ].items ():
0 commit comments