@@ -352,24 +352,24 @@ def make(self, key):
352
352
raise NotImplementedError (
353
353
f"Processing for neuropixels probe model { spikeglx_meta .probe_model } not yet implemented."
354
354
)
355
- else :
356
- probe_type = spikeglx_meta .probe_model
357
- electrode_query = probe .ProbeType .Electrode & {"probe_type" : probe_type }
358
355
359
- probe_electrodes = {
360
- (shank , shank_col , shank_row ): key
361
- for key , shank , shank_col , shank_row in zip (
362
- * electrode_query .fetch ("KEY" , "shank" , "shank_col" , "shank_row" )
363
- )
364
- } # electrode configuration
365
- electrode_group_members = [
366
- probe_electrodes [(shank , shank_col , shank_row )]
367
- for shank , shank_col , shank_row , _ in spikeglx_meta .shankmap ["data" ]
368
- ] # recording session-specific electrode configuration
369
-
370
- econfig_entry , econfig_electrodes = generate_electrode_config_entry (
371
- probe_type , electrode_group_members
356
+ probe_type = spikeglx_meta .probe_model
357
+ electrode_query = probe .ProbeType .Electrode & {"probe_type" : probe_type }
358
+
359
+ probe_electrodes = {
360
+ (shank , shank_col , shank_row ): key
361
+ for key , shank , shank_col , shank_row in zip (
362
+ * electrode_query .fetch ("KEY" , "shank" , "shank_col" , "shank_row" )
372
363
)
364
+ } # electrode configuration
365
+ electrode_group_members = [
366
+ probe_electrodes [(shank , shank_col , shank_row )]
367
+ for shank , shank_col , shank_row , _ in spikeglx_meta .shankmap ["data" ]
368
+ ] # recording session-specific electrode configuration
369
+
370
+ econfig_entry , econfig_electrodes = generate_electrode_config_entry (
371
+ probe_type , electrode_group_members
372
+ )
373
373
374
374
ephys_recording_entry = {
375
375
** key ,
@@ -398,18 +398,6 @@ def make(self, key):
398
398
399
399
# Insert channel information
400
400
# Get channel and electrode-site mapping
401
- electrode_query = (
402
- probe .ProbeType .Electrode * probe .ElectrodeConfig .Electrode
403
- & {"electrode_config_hash" : econfig_entry ["electrode_config_hash" ]}
404
- )
405
-
406
- probe_electrodes = {
407
- (shank , shank_col , shank_row ): key
408
- for key , shank , shank_col , shank_row in zip (
409
- * electrode_query .fetch ("KEY" , "shank" , "shank_col" , "shank_row" )
410
- )
411
- }
412
-
413
401
channel2electrode_map = {
414
402
recorded_site : probe_electrodes [(shank , shank_col , shank_row )]
415
403
for recorded_site , (shank , shank_col , shank_row , _ ) in enumerate (
@@ -418,7 +406,12 @@ def make(self, key):
418
406
}
419
407
420
408
ephys_channel_entries = [
421
- {** key , "channel_idx" : channel_idx , ** channel_info }
409
+ {
410
+ ** key ,
411
+ "electrode_config_hash" : econfig_entry ["electrode_config_hash" ],
412
+ "channel_idx" : channel_idx ,
413
+ ** channel_info ,
414
+ }
422
415
for channel_idx , channel_info in channel2electrode_map .items ()
423
416
]
424
417
elif acq_software == "Open Ephys" :
@@ -438,24 +431,24 @@ def make(self, key):
438
431
439
432
if probe_data .probe_model not in supported_probe_types :
440
433
raise NotImplementedError (
441
- f"Processing for neuropixels probe model { spikeglx_meta .probe_model } not yet implemented."
434
+ f"Processing for neuropixels probe model { probe_data .probe_model } not yet implemented."
442
435
)
443
- else :
444
- probe_type = probe_data .probe_model
445
- electrode_query = probe .ProbeType .Electrode & {"probe_type" : probe_type }
446
436
447
- probe_electrodes = {
448
- key ["electrode" ]: key for key in electrode_query .fetch ("KEY" )
449
- } # electrode configuration
437
+ probe_type = probe_data .probe_model
438
+ electrode_query = probe .ProbeType .Electrode & {"probe_type" : probe_type }
450
439
451
- electrode_group_members = [
452
- probe_electrodes [channel_idx ]
453
- for channel_idx in probe_data .ap_meta ["channels_indices" ]
454
- ] # recording session-specific electrode configuration
440
+ probe_electrodes = {
441
+ key ["electrode" ]: key for key in electrode_query .fetch ("KEY" )
442
+ } # electrode configuration
455
443
456
- econfig_entry , econfig_electrodes = generate_electrode_config_entry (
457
- probe_type , electrode_group_members
458
- )
444
+ electrode_group_members = [
445
+ probe_electrodes [channel_idx ]
446
+ for channel_idx in probe_data .ap_meta ["channels_indices" ]
447
+ ] # recording session-specific electrode configuration
448
+
449
+ econfig_entry , econfig_electrodes = generate_electrode_config_entry (
450
+ probe_type , electrode_group_members
451
+ )
459
452
460
453
ephys_recording_entry = {
461
454
** key ,
@@ -480,29 +473,24 @@ def make(self, key):
480
473
for fp in probe_data .recording_info ["recording_files" ]
481
474
]
482
475
483
- # Explicitly garbage collect "dataset" as these may have large memory footprint and may not be cleared fast enough
484
- del probe_data , dataset
485
- gc .collect ()
486
-
487
- probe_dataset = get_openephys_probe_data (key )
488
- electrode_query = (
489
- probe .ProbeType .Electrode
490
- * probe .ElectrodeConfig .Electrode
491
- * EphysRecording
492
- & key
493
- )
494
- probe_electrodes = {
495
- key ["electrode" ]: key for key in electrode_query .fetch ("KEY" )
496
- }
497
476
channel2electrode_map = {
498
477
channel_idx : probe_electrodes [channel_idx ]
499
- for channel_idx in probe_dataset .ap_meta ["channels_indices" ]
478
+ for channel_idx in probe_data .ap_meta ["channels_indices" ]
500
479
}
501
480
502
481
ephys_channel_entries = [
503
- {** key , "channel_idx" : channel_idx , ** channel_info }
482
+ {
483
+ ** key ,
484
+ "electrode_config_hash" : econfig_entry ["electrode_config_hash" ],
485
+ "channel_idx" : channel_idx ,
486
+ ** channel_info ,
487
+ }
504
488
for channel_idx , channel_info in channel2electrode_map .items ()
505
489
]
490
+
491
+ # Explicitly garbage collect "dataset" as these may have large memory footprint and may not be cleared fast enough
492
+ del probe_data , dataset
493
+ gc .collect ()
506
494
else :
507
495
raise NotImplementedError (
508
496
f"Processing ephys files from acquisition software of type { acq_software } is not yet implemented."
@@ -1041,10 +1029,7 @@ def make(self, key):
1041
1029
output_dir = find_full_path (get_ephys_root_data_dir (), output_dir )
1042
1030
1043
1031
# Get channel and electrode-site mapping
1044
- electrode_query = (
1045
- (EphysRecording .Channel & key )
1046
- .proj (..., "-channel_name" )
1047
- )
1032
+ electrode_query = (EphysRecording .Channel & key ).proj (..., "-channel_name" )
1048
1033
channel2electrode_map = electrode_query .fetch (as_dict = True )
1049
1034
channel2electrode_map : dict [int , dict ] = {
1050
1035
chn .pop ("channel_idx" ): chn for chn in channel2electrode_map
@@ -1058,7 +1043,9 @@ def make(self, key):
1058
1043
if si_waveform_dir .exists ():
1059
1044
1060
1045
# Read from spikeinterface outputs
1061
- we : si .WaveformExtractor = si .load_waveforms (si_waveform_dir , with_recording = False )
1046
+ we : si .WaveformExtractor = si .load_waveforms (
1047
+ si_waveform_dir , with_recording = False
1048
+ )
1062
1049
si_sorting : si .sorters .BaseSorter = si .load_extractor (
1063
1050
si_sorting_dir / "si_sorting.pkl"
1064
1051
)
@@ -1139,10 +1126,10 @@ def make(self, key):
1139
1126
"spike_count" : spike_count_dict [unit_id ],
1140
1127
"spike_sites" : new_spikes ["electrode" ][
1141
1128
new_spikes ["unit_index" ] == unit_id
1142
- ],
1129
+ ],
1143
1130
"spike_depths" : new_spikes ["depth" ][
1144
1131
new_spikes ["unit_index" ] == unit_id
1145
- ],
1132
+ ],
1146
1133
}
1147
1134
)
1148
1135
@@ -1281,23 +1268,22 @@ def make(self, key):
1281
1268
sorter_name = clustering_method .replace ("." , "_" )
1282
1269
1283
1270
# Get channel and electrode-site mapping
1284
- electrode_query = (
1285
- (EphysRecording .Channel & key )
1286
- .proj (..., "-channel_name" )
1287
- )
1271
+ electrode_query = (EphysRecording .Channel & key ).proj (..., "-channel_name" )
1288
1272
channel2electrode_map = electrode_query .fetch (as_dict = True )
1289
1273
channel2electrode_map : dict [int , dict ] = {
1290
1274
chn .pop ("channel_idx" ): chn for chn in channel2electrode_map
1291
1275
}
1292
1276
1293
1277
si_waveform_dir = output_dir / sorter_name / "waveform"
1294
1278
if si_waveform_dir .exists (): # read from spikeinterface outputs
1295
- we : si .WaveformExtractor = si .load_waveforms (si_waveform_dir , with_recording = False )
1296
- unit_id_to_peak_channel_map : dict [
1297
- int , np .ndarray
1298
- ] = si .ChannelSparsity .from_best_channels (
1299
- we , 1 , peak_sign = "neg"
1300
- ).unit_id_to_channel_indices # {unit: peak_channel_index}
1279
+ we : si .WaveformExtractor = si .load_waveforms (
1280
+ si_waveform_dir , with_recording = False
1281
+ )
1282
+ unit_id_to_peak_channel_map : dict [int , np .ndarray ] = (
1283
+ si .ChannelSparsity .from_best_channels (
1284
+ we , 1 , peak_sign = "neg"
1285
+ ).unit_id_to_channel_indices
1286
+ ) # {unit: peak_channel_index}
1301
1287
1302
1288
# reorder channel2electrode_map according to recording channel ids
1303
1289
channel2electrode_map = {
@@ -1391,6 +1377,7 @@ def yield_unit_waveforms():
1391
1377
yield unit_peak_waveform , unit_electrode_waveforms
1392
1378
1393
1379
# Spike interface mean and peak waveform extraction from we object
1380
+
1394
1381
elif len (waveforms_folder ) > 0 & (waveforms_folder [0 ]).exists ():
1395
1382
we_kilosort = si .load_waveforms (waveforms_folder [0 ].parent )
1396
1383
unit_templates = we_kilosort .get_all_templates ()
@@ -1618,7 +1605,10 @@ def make(self, key):
1618
1605
sorter_name = clustering_method .replace ("." , "_" )
1619
1606
1620
1607
# find metric_fp
1621
- for metric_fp in [output_dir / "metrics.csv" , output_dir / sorter_name / "metrics" / "metrics.csv" ]:
1608
+ for metric_fp in [
1609
+ output_dir / "metrics.csv" ,
1610
+ output_dir / sorter_name / "metrics" / "metrics.csv" ,
1611
+ ]:
1622
1612
if metric_fp .exists ():
1623
1613
break
1624
1614
else :
0 commit comments