24
24
25
25
from spikesorters .sorterlist import sorter_dict
26
26
27
- # TODO change this when sorters will be remove from toolkit
28
27
from spikesorters import run_sorters , iter_output_folders , iter_sorting_output
29
28
from .comparisontools import _perf_keys
30
29
from .groundtruthcomparison import compare_sorter_to_ground_truth
31
30
32
31
33
-
34
32
def setup_comparison_study (study_folder , gt_dict ):
35
33
"""
36
34
Based on a dict of (recording, sorting) create the study folder.
@@ -46,13 +44,13 @@ def setup_comparison_study(study_folder, gt_dict):
46
44
"""
47
45
48
46
study_folder = Path (study_folder )
49
- assert not os . path . exists ( study_folder ), 'study_folder already exists'
47
+ assert not study_folder . is_dir ( ), " 'study_folder' already exists. Please remove it"
50
48
51
- os . makedirs ( str ( study_folder ) )
52
- os . makedirs ( str ( study_folder / 'raw_files' ))
53
- os . makedirs ( str ( study_folder / 'ground_truth' ))
54
- os . makedirs ( str ( study_folder / 'sortings' ))
55
- os . makedirs ( str ( study_folder / 'sortings/ run_log' ))
49
+ study_folder . mkdir ( parents = True , exist_ok = True )
50
+ ( study_folder / 'raw_files' ). mkdir ( parents = True , exist_ok = True )
51
+ ( study_folder / 'ground_truth' ). mkdir ( parents = True , exist_ok = True )
52
+ ( study_folder / 'sortings' ). mkdir ( parents = True , exist_ok = True )
53
+ ( study_folder / 'sortings' / ' run_log' ). mkdir ( parents = True , exist_ok = True )
56
54
57
55
for rec_name , (recording , sorting_gt ) in gt_dict .items ():
58
56
# write recording as binary format + json + prb
@@ -123,7 +121,6 @@ def get_one_recording(study_folder, rec_name):
123
121
info = json .load (f )
124
122
rec = se .BinDatRecordingExtractor (raw_filename , info ['sample_rate' ], info ['num_chan' ],
125
123
info ['dtype' ], time_axis = info ['time_axis' ])
126
- # rec = rec.load_probe_file(prb_filename)
127
124
load_probe_file_inplace (rec , prb_filename )
128
125
129
126
return rec
@@ -250,8 +247,7 @@ def copy_sortings_to_npz(study_folder):
250
247
sorter_folders = study_folder / 'sorter_folders'
251
248
sorting_folders = study_folder / 'sortings'
252
249
253
- if not os .path .exists (sorting_folders ):
254
- os .makedirs (str (sorting_folders ))
250
+ sorting_folders .mkdir (parents = True , exist_ok = True )
255
251
256
252
for rec_name , sorter_name , output_folder in iter_output_folders (sorter_folders ):
257
253
SorterClass = sorter_dict [sorter_name ]
@@ -261,13 +257,12 @@ def copy_sortings_to_npz(study_folder):
261
257
sorting = SorterClass .get_result_from_folder (output_folder )
262
258
se .NpzSortingExtractor .write_sorting (sorting , npz_filename )
263
259
except :
264
- if os . path . exists ( npz_filename ):
265
- os . remove ( npz_filename )
266
- if os . path . exists (output_folder / 'spikeinterface_log.json' ):
260
+ if npz_filename . is_file ( ):
261
+ npz_filename . unlink ( )
262
+ if (output_folder / 'spikeinterface_log.json' ). is_file ( ):
267
263
shutil .copyfile (output_folder / 'spikeinterface_log.json' , sorting_folders / 'run_log' / (fname + '.json' ))
268
264
269
265
270
-
271
266
def iter_computed_names (study_folder ):
272
267
sorting_folder = Path (study_folder ) / 'sortings'
273
268
for filename in os .listdir (sorting_folder ):
@@ -299,8 +294,7 @@ def collect_run_times(study_folder):
299
294
log_folder = sorting_folders / 'run_log'
300
295
tables_folder = study_folder / 'tables'
301
296
302
- if not os .path .exists (tables_folder ):
303
- os .makedirs (str (tables_folder ))
297
+ tables_folder .mkdir (parents = True , exist_ok = True )
304
298
305
299
run_times = []
306
300
for filename in os .listdir (log_folder ):
@@ -441,8 +435,6 @@ def aggregate_performances_table(study_folder, exhaustive_gt=False, **karg_thres
441
435
return dataframes
442
436
443
437
444
-
445
-
446
438
def load_probe_file_inplace (recording , probe_file ):
447
439
'''
448
440
This is a locally modified version of spikeextractor.extraction_tools.load_probe_file.
0 commit comments