@@ -23,19 +23,20 @@ def calculate_mean_waveforms(args):
2323
2424 start = time .time ()
2525
26+ # regenerate the clus_Table in case there has been manual curation of the data in phy
27+ output_dir = args ['directories' ]['kilosort_output_directory' ]
28+
29+ # get version number for new clus_table file
30+ clu_path_orig = os .path .join (output_dir , 'clus_Table.npy' )
31+ clus_table_npy , clu_version = getFileVersion (clu_path_orig )
32+
33+ # version = 0 if no clu_Table exists, file = clus_Table.npy
34+ # version = 1 or higher, new clus_Table = clus_Table_version.npy
35+
2636 if args ['mean_waveform_params' ]['use_C_Waves' ]:
2737
2838 print ('Calculating mean waveforms using C_waves.' )
2939 spikeglx_bin = args ['ephys_params' ]['ap_band_file' ]
30- # regenerate the clus_Table in case there has been manual curation of the data in phy
31- output_dir = args ['directories' ]['kilosort_output_directory' ]
32-
33- # get version number for new clus_table file
34- clu_path_orig = os .path .join (output_dir , 'clus_Table.npy' )
35- clus_table_npy , clu_version = getFileVersion (clu_path_orig )
36-
37- #version = 0 if no clu_Table exists, file = clus_Table.npy
38- #version = 1 or higher, new clus_Table = clus_Table_version.npy
3940
4041 getSortResults (output_dir , clu_version )
4142
@@ -60,10 +61,6 @@ def calculate_mean_waveforms(args):
6061 new_snr = os .path .join (dest ,'cluster_snr_0.npy' )
6162 os .rename (old_snr , new_snr )
6263
63-
64-
65-
66-
6764 # path to the 'runit.bat' executable that calls C_Waves.
6865 # Essential in linux where C_Waves executable is only callable through runit
6966 if sys .platform .startswith ('win' ):
@@ -140,9 +137,6 @@ def calculate_mean_waveforms(args):
140137 site_x = np .squeeze (loadmat (chanMapMat )['xcoords' ])
141138 site_y = np .squeeze (loadmat (chanMapMat )['ycoords' ])
142139
143-
144-
145-
146140 metrics = metrics_from_file (mean_waveform_fullpath , snr_fullpath , clus_table_npy , \
147141 spike_times , \
148142 spike_clusters , \
@@ -155,15 +149,6 @@ def calculate_mean_waveforms(args):
155149 site_x , site_y , \
156150 args ['mean_waveform_params' ])
157151
158- wm_fullpath = (args ['waveform_metrics' ]['waveform_metrics_file' ])
159-
160- if clu_version > 0 :
161- # save new metrics as _version number
162- wm_fullpath = os .path .join (pathlib .Path (wm_fullpath ).parent , pathlib .Path (wm_fullpath ).stem + '_' + repr (clu_version ) + '.csv' )
163-
164- metrics .to_csv (wm_fullpath )
165-
166-
167152 else :
168153
169154 print ('Calculating mean waveforms using python.' )
@@ -194,8 +179,17 @@ def calculate_mean_waveforms(args):
194179 args ['mean_waveform_params' ])
195180
196181 writeDataAsNpy (waveforms , args ['mean_waveform_params' ]['mean_waveforms_file' ])
197- metrics .to_csv (args ['waveform_metrics' ]['waveform_metrics_file' ])
198182
183+ # save waveform metrics to csv file
184+ wm_fullpath = (args ['waveform_metrics' ]['waveform_metrics_file' ])
185+
186+ if clu_version > 0 :
187+ # save new metrics as _version number
188+ wm_fullpath = os .path .join (pathlib .Path (wm_fullpath ).parent ,
189+ pathlib .Path (wm_fullpath ).stem + '_' + repr (
190+ clu_version ) + '.csv' )
191+
192+ metrics .to_csv (wm_fullpath )
199193
200194 # if the cluster metrics have already been run, merge the waveform metrics into that file
201195 # build file path with current version
0 commit comments