1919import customplotting .mscope as cpm
2020# local modules
2121try :
22- from Spectra_fit_funcs import Spectra_Fit , Single_Gaussian , Single_Lorentzian , Double_Gaussian
22+ from Spectra_fit_funcs import Spectra_Fit , Single_Gaussian , Single_Lorentzian , Double_Gaussian , Multi_Gaussian
2323except :
24- from Spectrum_analysis .Spectra_fit_funcs import Spectra_Fit , Single_Gaussian , Single_Lorentzian , Double_Gaussian
24+ from Spectrum_analysis .Spectra_fit_funcs import Spectra_Fit , Single_Gaussian , Single_Lorentzian , Double_Gaussian , Multi_Gaussian
2525
2626
2727"""Recylce params for plotting"""
@@ -71,14 +71,15 @@ def __init__(self):
7171
7272 self .ui .fit_pushButton .clicked .connect (self .fit_and_plot )
7373 self .ui .fit_scan_pushButton .clicked .connect (self .fit_and_plot_scan )
74- self .ui .config_fit_params_pushButton .clicked .connect (self .configure_fit_params )
74+ # self.ui.config_fit_params_pushButton.clicked.connect(self.configure_fit_params)
7575 self .ui .clear_pushButton .clicked .connect (self .clear_plot )
7676 self .ui .export_fig_pushButton .clicked .connect (self .pub_ready_plot_export )
7777
7878 self .ui .import_pkl_pushButton .clicked .connect (self .open_pkl_file )
7979 self .ui .data_txt_pushButton .clicked .connect (self .pkl_data_to_txt )
8080 self .ui .scan_params_txt_pushButton .clicked .connect (self .pkl_params_to_txt )
8181
82+ self .ui .tabWidget .currentChanged .connect (self .switch_overall_tab )
8283 self .ui .fitFunc_comboBox .currentTextChanged .connect (self .switch_bounds_and_guess_tab )
8384 self .ui .adjust_param_checkBox .stateChanged .connect (self .switch_adjust_param )
8485
@@ -173,6 +174,17 @@ def save_file(self):# not used yet!
173174 except :
174175 pass
175176
177+ def switch_overall_tab (self ):
178+ if self .ui .tabWidget .currentIndex () == 0 :
179+ self .ui .fitting_settings_groupBox .setEnabled (True )
180+ self .ui .scan_fit_settings_groupBox .setEnabled (False )
181+ elif self .ui .tabWidget .currentIndex () == 1 :
182+ self .ui .fitting_settings_groupBox .setEnabled (False )
183+ self .ui .scan_fit_settings_groupBox .setEnabled (True )
184+ elif self .ui .tabWidget .currentIndex () == 2 :
185+ self .ui .fitting_settings_groupBox .setEnabled (False )
186+ self .ui .scan_fit_settings_groupBox .setEnabled (False )
187+
176188 def switch_bounds_and_guess_tab (self ):
177189 fit_func = self .ui .fitFunc_comboBox .currentText ()
178190 if fit_func == "Single Gaussian" or fit_func == "Single Lorentzian" :
@@ -345,9 +357,9 @@ def clear_check(self):
345357 return False
346358
347359 """Open param window and get peak center range values and assign it to variables to use later"""
348- def configure_fit_params (self ):
349- self .param_window = ParamWindow ()
350- self .param_window .peak_range .connect (self .peak_range )
360+ # def configure_fit_params(self):
361+ # self.param_window = ParamWindow()
362+ # self.param_window.peak_range.connect(self.peak_range)
351363
352364 def peak_range (self , peaks ):
353365 self .center_min = peaks [0 ]
@@ -373,8 +385,8 @@ def fit_and_plot(self):
373385 center1_max = self .ui .single_peakcenter1_max_spinBox .value ()
374386 center1_guess = self .ui .single_peakcenter1_guess_spinBox .value ()
375387 sigma1_guess = self .ui .single_sigma1_guess_spinBox .value ()
376- self .result = single_gauss .gaussian_model_w_lims (center_initial_guess = center1_guess , sigma_initial_guess = sigma1_guess ,
377- center_min = center1_min , center_max = center1_max )
388+ self .result = single_gauss .gaussian_model_w_lims (center1_guess , sigma1_guess ,
389+ [ center1_min , center1_max ] )
378390 else :
379391 self .result = single_gauss .gaussian_model ()
380392 self .ui .plot .plot (self .x , self .y , clear = self .clear_check (), pen = 'r' )
@@ -389,16 +401,15 @@ def fit_and_plot(self):
389401 center1_max = self .ui .single_peakcenter1_max_spinBox .value ()
390402 center1_guess = self .ui .single_peakcenter1_guess_spinBox .value ()
391403 sigma1_guess = self .ui .single_sigma1_guess_spinBox .value ()
392- self .result = single_lorentzian .lorentzian_model_w_lims (center_initial_guess = center1_guess , sigma_initial_guess = sigma1_guess ,
393- center_min = center1_min , center_max = center1_max )
404+ self .result = single_lorentzian .lorentzian_model_w_lims (center1_guess , sigma1_guess ,
405+ [ center1_min , center1_max ] )
394406 else :
395407 self .result = single_lorentzian .lorentzian_model ()
396408 self .ui .plot .plot (self .x , self .y , clear = self .clear_check (), pen = 'r' )
397409 self .ui .plot .plot (self .x , self .result .best_fit , clear = False , pen = 'k' )
398410 self .ui .result_textBrowser .setText (self .result .fit_report ())
399411
400412 elif fit_func == "Double Gaussian" and self .ui .subtract_bck_checkBox .isChecked () == True :
401- self .ui .result_textBrowser .setText ("Not Implemented Yet!" )
402413 double_gauss = Double_Gaussian (self .file , self .bck_file , wlref = self .wlref_file )
403414 if self .ui .adjust_param_checkBox .isChecked ():
404415 center1_min = self .ui .double_peakcenter1_min_spinBox .value ()
@@ -410,8 +421,10 @@ def fit_and_plot(self):
410421 center2_guess = self .ui .double_peakcenter2_guess_spinBox .value ()
411422 sigma2_guess = self .ui .double_sigma2_guess_spinBox .value ()
412423
413- self .result = double_gauss .gaussian_model_w_lims (center_initial_guesses = [center1_guess , center2_guess ],
414- sigma_initial_guesses = [sigma1_guess , sigma2_guess ], min_max_range = [ [center1_min , center1_max ], [center2_min , center2_max ]])
424+ peak_pos = [center1_guess , center2_guess ]
425+ sigma = [sigma1_guess , sigma2_guess ]
426+ min_max_range = [ [center1_min , center1_max ], [center2_min , center2_max ] ]
427+ self .result = double_gauss .gaussian_model_w_lims (peak_pos , sigma , min_max_range )
415428
416429 else :
417430 self .result = double_gauss .gaussian_model ()
@@ -426,7 +439,39 @@ def fit_and_plot(self):
426439 self .ui .result_textBrowser .setText (self .result .fit_report ())
427440
428441 elif fit_func == "Multiple Gaussians" and self .ui .subtract_bck_checkBox .isChecked () == True :
429- self .ui .result_textBrowser .setText ("Not Implemented Yet!" )
442+ #currently only works for triple gaussian (n=3)
443+ multiple_gauss = Multi_Gaussian (self .file , self .bck_file , 3 , wlref = self .wlref_file )
444+ if self .ui .adjust_param_checkBox .isChecked ():
445+ center1_min = self .ui .multi_peakcenter1_min_spinBox .value ()
446+ center1_max = self .ui .multi_peakcenter1_max_spinBox .value ()
447+ center2_min = self .ui .multi_peakcenter2_min_spinBox .value ()
448+ center2_max = self .ui .multi_peakcenter2_max_spinBox .value ()
449+ center3_min = self .ui .multi_peakcenter3_min_spinBox .value ()
450+ center3_max = self .ui .multi_peakcenter3_max_spinBox .value ()
451+ center1_guess = self .ui .multi_peakcenter1_guess_spinBox .value ()
452+ sigma1_guess = self .ui .multi_sigma1_guess_spinBox .value ()
453+ center2_guess = self .ui .multi_peakcenter2_guess_spinBox .value ()
454+ sigma2_guess = self .ui .multi_sigma2_guess_spinBox .value ()
455+ center3_guess = self .ui .multi_peakcenter3_guess_spinBox .value ()
456+ sigma3_guess = self .ui .multi_sigma3_guess_spinBox .value ()
457+ num_gaussians = 3
458+ peak_pos = [center1_guess , center2_guess , center3_guess ]
459+ sigma = [sigma1_guess , sigma2_guess , sigma3_guess ]
460+ min_max_range = [ [center1_min , center1_max ], [center2_min , center2_max ], [center3_min , center3_max ] ]
461+
462+ self .result = multiple_gauss .gaussian_model_w_lims (peak_pos , sigma , min_max_range )
463+ else :
464+ self .result = multiple_gauss .gaussian_model ()
465+
466+ self .ui .plot .plot (self .x , self .y , clear = self .clear_check (), pen = 'r' )
467+ self .ui .plot .plot (self .x , self .result .best_fit , clear = False , pen = 'k' )
468+ if self .ui .plot_components_checkBox .isChecked ():
469+ comps = self .result .eval_components (x = self .x )
470+ self .ui .plot .plot (self .x , comps ['g1_' ], pen = 'b' , clear = False )
471+ self .ui .plot .plot (self .x , comps ['g2_' ], pen = 'g' , clear = False )
472+ self .ui .plot .plot (self .x , comps ['g3_' ], pen = 'c' , clear = False )
473+ self .ui .result_textBrowser .setText (self .result .fit_report ())
474+
430475
431476 except Exception as e :
432477 self .ui .result_textBrowser .setText (str (e ))
@@ -571,37 +616,37 @@ def close_application(self):
571616
572617
573618"""Parameter Window GUI and Functions"""
574- param_file_path = (base_path / "peak_bounds_input.ui" ).resolve ()
619+ # param_file_path = (base_path / "peak_bounds_input.ui").resolve()
575620
576- param_uiFile = param_file_path
621+ # param_uiFile = param_file_path
577622
578- param_WindowTemplate , param_TemplateBaseClass = pg .Qt .loadUiType (param_uiFile )
623+ # param_WindowTemplate, param_TemplateBaseClass = pg.Qt.loadUiType(param_uiFile)
579624
580- class ParamWindow (param_TemplateBaseClass ):
625+ # class ParamWindow(param_TemplateBaseClass):
581626
582- peak_range = QtCore .pyqtSignal (list )
627+ # peak_range = QtCore.pyqtSignal(list)
583628
584- def __init__ (self ):
585- # super(param_TemplateBaseClass, self).__init__()
586- param_TemplateBaseClass .__init__ (self )
629+ # def __init__(self):
630+ # # super(param_TemplateBaseClass, self).__init__()
631+ # param_TemplateBaseClass.__init__(self)
587632
588- # Create the param window
589- self .pui = param_WindowTemplate ()
590- self .pui .setupUi (self )
633+ # # Create the param window
634+ # self.pui = param_WindowTemplate()
635+ # self.pui.setupUi(self)
591636
592- self .pui .pushButton .clicked .connect (self .done )
637+ # self.pui.pushButton.clicked.connect(self.done)
593638
594- self .show ()
639+ # self.show()
595640
596- def current_peak_range (self ):
597- center_min = self .pui .cent_min_doubleSpinBox .value ()
598- center_max = self .pui .cent_max_doubleSpinBox .value ()
599- return center_min , center_max
641+ # def current_peak_range(self):
642+ # center_min = self.pui.cent_min_doubleSpinBox.value()
643+ # center_max = self.pui.cent_max_doubleSpinBox.value()
644+ # return center_min, center_max
600645
601- def done (self ):
602- center_min , center_max = self .current_peak_range ()
603- self .peak_range .emit ([center_min , center_max ])
604- self .close ()
646+ # def done(self):
647+ # center_min, center_max = self.current_peak_range()
648+ # self.peak_range.emit([center_min, center_max])
649+ # self.close()
605650
606651"""Run the Main Window"""
607652def run ():
0 commit comments