@@ -61,7 +61,7 @@ def export_to_ibl(
6161 """
6262
6363 if find_spec ("scipy" ) is None :
64- raise ImportError ("Please install scipy to use the export_to_ibl function." )
64+ raise ImportError ("Please install scipy to use the ` export_to_ibl` function." )
6565 else :
6666 from scipy .signal import welch
6767
@@ -104,13 +104,8 @@ def export_to_ibl(
104104 # Check in case user pre-calculated a small set of qm's that aren't enough for IBL
105105 required_qms = ["amplitude_median" , "isi_violation" , "amplitude_cutoff" ]
106106 qm = analyzer .get_extension ("quality_metrics" ).get_data ()
107- for rqm in required_qms :
108- if rqm not in qm :
109- analyzer .compute (
110- "quality_metrics" ,
111- metric_names = [rqm ],
112- verbose = verbose ,
113- )
107+ qms_to_compute = [metric for metric in required_qms if metric not in qm ]
108+ analyzer .compute ("quality_metrics" , metric_names = qms_to_compute , verbose = verbose )
114109
115110 # # Start by just exporting to phy
116111 if not only_ibl_specific_steps :
@@ -157,17 +152,20 @@ def _get_rms(rec):
157152 chunk_start_times = chunk_start_times .astype (np .float32 )
158153 return chunk_rms , chunk_start_times
159154
160- # Get RMS for the AP data. We will use a window of length rms_win_length_sec seconds slid over the entire recording.
161- ap_rec = analyzer .recording
162- if ap_rec .get_num_segments () != 1 :
163- warnings .warn ("Found ap recording with more than one segment, only using initial segment." )
164- ap_rec = ap_rec [0 ]
165- chunk_rms , chunk_start_times = _get_rms (ap_rec )
166- np .save (os .path .join (output_folder , "_iblqc_ephysTimeRmsAP.rms.npy" ), chunk_rms )
167- np .save (
168- os .path .join (output_folder , "_iblqc_ephysTimeRmsAP.timestamps.npy" ),
169- chunk_start_times ,
170- )
155+ if analyzer .has_recording ():
156+ # Get RMS for the AP data. We will use a window of length rms_win_length_sec seconds slid over the entire recording.
157+ ap_rec = analyzer .recording
158+ if ap_rec .get_num_segments () != 1 :
159+ warnings .warn ("Found ap recording with more than one segment, only using initial segment." )
160+ ap_rec = ap_rec [0 ]
161+ chunk_rms , chunk_start_times = _get_rms (ap_rec )
162+ np .save (os .path .join (output_folder , "_iblqc_ephysTimeRmsAP.rms.npy" ), chunk_rms )
163+ np .save (
164+ os .path .join (output_folder , "_iblqc_ephysTimeRmsAP.timestamps.npy" ),
165+ chunk_start_times ,
166+ )
167+ elif verbose :
168+ print ("No recording data found in the SortingAnalyzer, skipping AP RMS calculation." )
171169
172170 if lfp_recording is not None :
173171 # Get RMS for the LFP data.
@@ -186,21 +184,20 @@ def _get_rms(rec):
186184 traces = lfp_recording .get_traces (start_frame = 0 , end_frame = end_frame ) # time x channels
187185 spec_density = np .zeros ((welch_win_length_samples // 2 + 1 , traces .shape [1 ]))
188186 for iCh in range (traces .shape [1 ]):
189- f , Pxx = welch (
187+ freqs , Pxx = welch (
190188 traces [:, iCh ],
191189 fs = lfp_recording .sampling_frequency ,
192190 nperseg = welch_win_length_samples ,
193191 )
194192 spec_density [:, iCh ] = Pxx
195193 spec_density = spec_density [:, channel_inds ] # only keep channels that were used for spike sorting
196194 spec_density = spec_density .astype (np .float32 )
197- f = f .astype (np .float32 )
198- assert spec_density .shape [0 ] == len (f )
195+ freqs = freqs .astype (np .float32 )
199196 np .save (
200197 os .path .join (output_folder , "_iblqc_ephysSpectralDensityLF.power.npy" ),
201198 spec_density ,
202199 )
203- np .save (os .path .join (output_folder , "_iblqc_ephysSpectralDensityLF.freqs.npy" ), f )
200+ np .save (os .path .join (output_folder , "_iblqc_ephysSpectralDensityLF.freqs.npy" ), freqs )
204201
205202 ### Save spike info ###
206203
0 commit comments