@@ -185,8 +185,7 @@ def auto_generate_entries(cls, session_key):
185185
186186 probe_dir = meta_filepath .parent
187187 try :
188- probe_number = re .search (
189- "(imec)?\d{1}$" , probe_dir .name ).group ()
188+ probe_number = re .search ("(imec)?\d{1}$" , probe_dir .name ).group ()
190189 probe_number = int (probe_number .replace ("imec" , "" ))
191190 except AttributeError :
192191 probe_number = meta_fp_idx
@@ -215,8 +214,7 @@ def auto_generate_entries(cls, session_key):
215214 }
216215 )
217216 else :
218- raise NotImplementedError (
219- f"Unknown acquisition software: { acq_software } " )
217+ raise NotImplementedError (f"Unknown acquisition software: { acq_software } " )
220218
221219 probe .Probe .insert (probe_list , skip_duplicates = True )
222220 cls .insert (probe_insertion_list , skip_duplicates = True )
@@ -323,14 +321,12 @@ def make(self, key):
323321 break
324322 else :
325323 raise FileNotFoundError (
326- "No SpikeGLX data found for probe insertion: {}" .format (
327- key )
324+ "No SpikeGLX data found for probe insertion: {}" .format (key )
328325 )
329326
330327 if spikeglx_meta .probe_model in supported_probe_types :
331328 probe_type = spikeglx_meta .probe_model
332- electrode_query = probe .ProbeType .Electrode & {
333- "probe_type" : probe_type }
329+ electrode_query = probe .ProbeType .Electrode & {"probe_type" : probe_type }
334330
335331 probe_electrodes = {
336332 (shank , shank_col , shank_row ): key
@@ -363,11 +359,9 @@ def make(self, key):
363359 }
364360 )
365361
366- root_dir = find_root_directory (
367- get_ephys_root_data_dir (), meta_filepath )
362+ root_dir = find_root_directory (get_ephys_root_data_dir (), meta_filepath )
368363 self .EphysFile .insert1 (
369- {** key ,
370- "file_path" : meta_filepath .relative_to (root_dir ).as_posix ()}
364+ {** key , "file_path" : meta_filepath .relative_to (root_dir ).as_posix ()}
371365 )
372366 elif acq_software == "Open Ephys" :
373367 dataset = openephys .OpenEphys (session_dir )
@@ -376,8 +370,7 @@ def make(self, key):
376370 break
377371 else :
378372 raise FileNotFoundError (
379- "No Open Ephys data found for probe insertion: {}" .format (
380- key )
373+ "No Open Ephys data found for probe insertion: {}" .format (key )
381374 )
382375
383376 if not probe_data .ap_meta :
@@ -387,8 +380,7 @@ def make(self, key):
387380
388381 if probe_data .probe_model in supported_probe_types :
389382 probe_type = probe_data .probe_model
390- electrode_query = probe .ProbeType .Electrode & {
391- "probe_type" : probe_type }
383+ electrode_query = probe .ProbeType .Electrode & {"probe_type" : probe_type }
392384
393385 probe_electrodes = {
394386 key ["electrode" ]: key for key in electrode_query .fetch ("KEY" )
@@ -401,8 +393,7 @@ def make(self, key):
401393 else :
402394 raise NotImplementedError (
403395 "Processing for neuropixels"
404- " probe model {} not yet implemented" .format (
405- probe_data .probe_model )
396+ " probe model {} not yet implemented" .format (probe_data .probe_model )
406397 )
407398
408399 self .insert1 (
@@ -464,7 +455,7 @@ class LFP(dj.Imported):
464455
465456 class Electrode (dj .Part ):
466457 """Saves local field potential data for each electrode.
467-
458+
468459 Attributes:
469460 LFP (foreign key): LFP primary key.
470461 probe.ElectrodeConfig.Electrode (foreign key): probe.ElectrodeConfig.Electrode primary key.
@@ -484,27 +475,24 @@ class Electrode(dj.Part):
484475
485476 def make (self , key ):
486477 """Populates the LFP tables."""
487- acq_software = (EphysRecording * ProbeInsertion &
488- key ).fetch1 ("acq_software" )
478+ acq_software = (EphysRecording * ProbeInsertion & key ).fetch1 ("acq_software" )
489479
490480 electrode_keys , lfp = [], []
491481
492482 if acq_software == "SpikeGLX" :
493483 spikeglx_meta_filepath = get_spikeglx_meta_filepath (key )
494- spikeglx_recording = spikeglx .SpikeGLX (
495- spikeglx_meta_filepath .parent )
484+ spikeglx_recording = spikeglx .SpikeGLX (spikeglx_meta_filepath .parent )
496485
497486 lfp_channel_ind = spikeglx_recording .lfmeta .recording_channels [
498- - 1 :: - self ._skip_channel_counts
487+ - 1 :: - self ._skip_channel_counts
499488 ]
500489
501490 # Extract LFP data at specified channels and convert to uV
502491 lfp = spikeglx_recording .lf_timeseries [
503492 :, lfp_channel_ind
504493 ] # (sample x channel)
505494 lfp = (
506- lfp *
507- spikeglx_recording .get_channel_bit_volts ("lf" )[lfp_channel_ind ]
495+ lfp * spikeglx_recording .get_channel_bit_volts ("lf" )[lfp_channel_ind ]
508496 ).T # (channel x sample)
509497
510498 self .insert1 (
@@ -536,21 +524,19 @@ def make(self, key):
536524 shank , shank_col , shank_row , _ = spikeglx_recording .apmeta .shankmap [
537525 "data"
538526 ][recorded_site ]
539- electrode_keys .append (
540- probe_electrodes [(shank , shank_col , shank_row )])
527+ electrode_keys .append (probe_electrodes [(shank , shank_col , shank_row )])
541528 elif acq_software == "Open Ephys" :
542529 oe_probe = get_openephys_probe_data (key )
543530
544531 lfp_channel_ind = np .r_ [
545532 len (oe_probe .lfp_meta ["channels_indices" ])
546- - 1 : 0 : - self ._skip_channel_counts
533+ - 1 : 0 : - self ._skip_channel_counts
547534 ]
548535
549536 # (sample x channel)
550537 lfp = oe_probe .lfp_timeseries [:, lfp_channel_ind ]
551538 lfp = (
552- lfp *
553- np .array (oe_probe .lfp_meta ["channels_gains" ])[lfp_channel_ind ]
539+ lfp * np .array (oe_probe .lfp_meta ["channels_gains" ])[lfp_channel_ind ]
554540 ).T # (channel x sample)
555541 lfp_timestamps = oe_probe .lfp_timestamps
556542
@@ -778,8 +764,7 @@ def auto_generate_entries(cls, ephys_recording_key: dict, paramset_idx: int = 0)
778764 key = {** ephys_recording_key , "paramset_idx" : paramset_idx }
779765
780766 processed_dir = get_processed_root_data_dir ()
781- output_dir = ClusteringTask .infer_output_dir (
782- key , relative = False , mkdir = True )
767+ output_dir = ClusteringTask .infer_output_dir (key , relative = False , mkdir = True )
783768
784769 try :
785770 kilosort .Kilosort (
@@ -826,8 +811,7 @@ def make(self, key):
826811 )
827812
828813 if not output_dir :
829- output_dir = ClusteringTask .infer_output_dir (
830- key , relative = True , mkdir = True )
814+ output_dir = ClusteringTask .infer_output_dir (key , relative = True , mkdir = True )
831815 # update clustering_output_dir
832816 ClusteringTask .update1 (
833817 {** key , "clustering_output_dir" : output_dir .as_posix ()}
@@ -1038,8 +1022,7 @@ def make(self, key):
10381022 "acq_software" , "sampling_rate"
10391023 )
10401024
1041- sample_rate = kilosort_dataset .data ["params" ].get (
1042- "sample_rate" , sample_rate )
1025+ sample_rate = kilosort_dataset .data ["params" ].get ("sample_rate" , sample_rate )
10431026
10441027 # ---------- Unit ----------
10451028 # -- Remove 0-spike units
@@ -1051,8 +1034,7 @@ def make(self, key):
10511034 valid_units = kilosort_dataset .data ["cluster_ids" ][withspike_idx ]
10521035 valid_unit_labels = kilosort_dataset .data ["cluster_groups" ][withspike_idx ]
10531036 # -- Get channel and electrode-site mapping
1054- channel2electrodes = get_neuropixels_channel2electrode_map (
1055- key , acq_software )
1037+ channel2electrodes = get_neuropixels_channel2electrode_map (key , acq_software )
10561038
10571039 # -- Spike-times --
10581040 # spike_times_sec_adj > spike_times_sec > spike_times
@@ -1219,8 +1201,7 @@ def yield_unit_waveforms():
12191201 else :
12201202 if acq_software == "SpikeGLX" :
12211203 spikeglx_meta_filepath = get_spikeglx_meta_filepath (key )
1222- neuropixels_recording = spikeglx .SpikeGLX (
1223- spikeglx_meta_filepath .parent )
1204+ neuropixels_recording = spikeglx .SpikeGLX (spikeglx_meta_filepath .parent )
12241205 elif acq_software == "Open Ephys" :
12251206 session_dir = find_full_path (
12261207 get_ephys_root_data_dir (), get_session_directory (key )
@@ -1268,11 +1249,9 @@ def yield_unit_waveforms():
12681249 self .insert1 (key )
12691250 for unit_peak_waveform , unit_electrode_waveforms in yield_unit_waveforms ():
12701251 if unit_peak_waveform :
1271- self .PeakWaveform .insert1 (
1272- unit_peak_waveform , ignore_extra_fields = True )
1252+ self .PeakWaveform .insert1 (unit_peak_waveform , ignore_extra_fields = True )
12731253 if unit_electrode_waveforms :
1274- self .Waveform .insert (
1275- unit_electrode_waveforms , ignore_extra_fields = True )
1254+ self .Waveform .insert (unit_electrode_waveforms , ignore_extra_fields = True )
12761255
12771256
12781257@schema
@@ -1417,8 +1396,7 @@ def get_spikeglx_meta_filepath(ephys_recording_key: dict) -> str:
14171396 ProbeInsertion * probe .Probe & ephys_recording_key
14181397 ).fetch1 ("probe" )
14191398
1420- spikeglx_meta_filepaths = [
1421- fp for fp in session_dir .rglob ("*.ap.meta" )]
1399+ spikeglx_meta_filepaths = [fp for fp in session_dir .rglob ("*.ap.meta" )]
14221400 for meta_filepath in spikeglx_meta_filepaths :
14231401 spikeglx_meta = spikeglx .SpikeGLXMeta (meta_filepath )
14241402 if str (spikeglx_meta .probe_SN ) == inserted_probe_serial_number :
@@ -1458,8 +1436,7 @@ def get_neuropixels_channel2electrode_map(
14581436) -> dict :
14591437 """Get the channel map for neuropixels probe."""
14601438 if acq_software == "SpikeGLX" :
1461- spikeglx_meta_filepath = get_spikeglx_meta_filepath (
1462- ephys_recording_key )
1439+ spikeglx_meta_filepath = get_spikeglx_meta_filepath (ephys_recording_key )
14631440 spikeglx_meta = spikeglx .SpikeGLXMeta (spikeglx_meta_filepath )
14641441 electrode_config_key = (
14651442 EphysRecording * probe .ElectrodeConfig & ephys_recording_key
@@ -1514,8 +1491,7 @@ def generate_electrode_config(probe_type: str, electrode_keys: list) -> dict:
15141491 dict: representing a key of the probe.ElectrodeConfig table
15151492 """
15161493 # compute hash for the electrode config (hash of dict of all ElectrodeConfig.Electrode)
1517- electrode_config_hash = dict_to_uuid (
1518- {k ["electrode" ]: k for k in electrode_keys })
1494+ electrode_config_hash = dict_to_uuid ({k ["electrode" ]: k for k in electrode_keys })
15191495
15201496 electrode_list = sorted ([k ["electrode" ] for k in electrode_keys ])
15211497 electrode_gaps = (
@@ -1585,11 +1561,9 @@ def get_recording_channels_details(ephys_recording_key: dict) -> np.array:
15851561 channels_details ["num_channels" ] = len (channels_details ["channel_ind" ])
15861562
15871563 if acq_software == "SpikeGLX" :
1588- spikeglx_meta_filepath = get_spikeglx_meta_filepath (
1589- ephys_recording_key )
1564+ spikeglx_meta_filepath = get_spikeglx_meta_filepath (ephys_recording_key )
15901565 spikeglx_recording = spikeglx .SpikeGLX (spikeglx_meta_filepath .parent )
1591- channels_details ["uVPerBit" ] = spikeglx_recording .get_channel_bit_volts ("ap" )[
1592- 0 ]
1566+ channels_details ["uVPerBit" ] = spikeglx_recording .get_channel_bit_volts ("ap" )[0 ]
15931567 channels_details ["connected" ] = np .array (
15941568 [v for * _ , v in spikeglx_recording .apmeta .shankmap ["data" ]]
15951569 )
0 commit comments