@@ -655,63 +655,64 @@ def fit_and_plot_scan(self):
655655 print ("Starting Scan Fitting" )
656656 print ("Using Single Gaussian to Fit\n This is the only fitting functions implemented" )
657657
658- try :
659- """Define starting and stopping wavelength values here"""
660- start_nm = int (self .ui .start_nm_spinBox .value ())
661- stop_nm = int (self .ui .stop_nm_spinBox .value ())
662-
663- if self .bck_file is None :
664- print ("Load Background file!" )
665- ref = self .bck_file
666- index = (ref [:,0 ]> start_nm ) & (ref [:,0 ]< stop_nm )
667-
668- x = self .wavelengths
669- x = x [index ]
670-
671- data_array = self .intensities
672-
673- result_dict = {}
674- result_dict ["Scan Parameters" ] = self .spec_scan_file ['Scan Parameters' ]
675- result_dict ["OceanOptics Parameters" ] = self .spec_scan_file ["OceanOptics Parameters" ]
676-
677- for i in range (data_array .shape [0 ]):
658+ with pg .BusyCursor ():
659+ try :
660+ """Define starting and stopping wavelength values here"""
661+ start_nm = int (self .ui .start_nm_spinBox .value ())
662+ stop_nm = int (self .ui .stop_nm_spinBox .value ())
678663
679- y = data_array [i , index ] # intensity
680- yref = ref [index , 1 ]
664+ if self .bck_file is None :
665+ print ("Load Background file!" )
666+ ref = self .bck_file
667+ index = (ref [:,0 ]> start_nm ) & (ref [:,0 ]< stop_nm )
681668
682- y = y - yref # background correction
683- y = y - np . mean ( y [( x > start_nm ) & ( x < start_nm + 25 )]) # removing any remaining bckgrnd
669+ x = self . wavelengths
670+ x = x [ index ]
684671
685- gmodel = GaussianModel (prefix = 'g1_' ) # calling gaussian model
686- pars = gmodel .guess (y , x = x ) # parameters - center, width, height
687- result = gmodel .fit (y , pars , x = x , nan_policy = 'propagate' )
688- if self .ui .save_all_checkBox .isChecked ():
689- result_dict ["result_" + str (i )] = result
690- else :
691- result_dict ["result_" + str (i )] = result .best_values
692-
693- # self.ui.result_textBrowser.append("Scan Fitting Complete!")
694- print ("Scan Fitting Complete!" )
695-
696- filename = QtWidgets .QFileDialog .getSaveFileName (self )
697- pickle .dump (result_dict , open (filename [0 ]+ "_fit_result_dict.pkl" , "wb" ))
672+ data_array = self .intensities
673+
674+ result_dict = {}
675+ result_dict ["Scan Parameters" ] = self .spec_scan_file ['Scan Parameters' ]
676+ result_dict ["OceanOptics Parameters" ] = self .spec_scan_file ["OceanOptics Parameters" ]
677+
678+ for i in range (data_array .shape [0 ]):
679+
680+ y = data_array [i , index ] # intensity
681+ yref = ref [index , 1 ]
682+
683+ y = y - yref # background correction
684+ y = y - np .mean (y [(x > start_nm ) & (x < start_nm + 25 )]) # removing any remaining bckgrnd
685+
686+ gmodel = GaussianModel (prefix = 'g1_' ) # calling gaussian model
687+ pars = gmodel .guess (y , x = x ) # parameters - center, width, height
688+ result = gmodel .fit (y , pars , x = x , nan_policy = 'propagate' )
689+ if self .ui .save_all_checkBox .isChecked ():
690+ result_dict ["result_" + str (i )] = result
691+ else :
692+ result_dict ["result_" + str (i )] = result .best_values
693+
694+ # self.ui.result_textBrowser.append("Scan Fitting Complete!")
695+ print ("Scan Fitting Complete!" )
696+
697+ filename = QtWidgets .QFileDialog .getSaveFileName (self )
698+ pickle .dump (result_dict , open (filename [0 ]+ "_fit_result_dict.pkl" , "wb" ))
699+
700+ # self.ui.result_textBrowser.append("Data Saved!")
701+ print ("Data Saved!" )
698702
699- # self.ui.result_textBrowser.append("Data Saved!")
700- print ("Data Saved!" )
701-
702- except Exception as e :
703- self .ui .result_textBrowser2 .append (str (e ))
704- pass
705-
706- # self.ui.result_textBrowser.append("Loading Fit Data and Plotting")
707- print ("Loading Fit Data and Plotting" )
708- try :
709- self .fit_scan_file = pickle .load (open (filename [0 ]+ "_fit_result_dict.pkl" , 'rb' ))
710- self .plot_fit_scan ()
703+ except Exception as e :
704+ self .ui .result_textBrowser2 .append (str (e ))
705+ pass
711706
712- except Exception as e :
713- self .ui .result_textBrowser2 .append (str (e ))
714- pass
707+ # self.ui.result_textBrowser.append("Loading Fit Data and Plotting")
708+ print ("Loading Fit Data and Plotting" )
709+ try :
710+ self .fit_scan_file = pickle .load (open (filename [0 ]+ "_fit_result_dict.pkl" , 'rb' ))
711+ self .plot_fit_scan ()
712+
713+ except Exception as e :
714+ self .ui .result_textBrowser2 .append (str (e ))
715+ pass
715716
716717
717718 """ Pkl conversion functions """
0 commit comments