4242class MainWindow (TemplateBaseClass ):
4343
4444 def __init__ (self ):
45- TemplateBaseClass .__init__ (self )
45+ super ( TemplateBaseClass , self ) .__init__ ()
4646
4747 # Create the main window
4848 self .ui = WindowTemplate ()
@@ -58,6 +58,7 @@ def __init__(self):
5858 self .ui .importWLRef_pushButton .clicked .connect (self .open_wlref_file )
5959 self .ui .plot_pushButton .clicked .connect (self .plot )
6060 self .ui .fit_pushButton .clicked .connect (self .fit_and_plot )
61+ self .ui .config_fit_params_pushButton .clicked .connect (self .configure_fit_params )
6162 self .ui .clear_pushButton .clicked .connect (self .clear_plot )
6263 self .ui .export_fig_pushButton .clicked .connect (self .pub_ready_plot_export )
6364
@@ -68,6 +69,10 @@ def __init__(self):
6869 self .y = None
6970 self .out = None # output file after fitting
7071
72+ # Peak parameters if adjust params is selected
73+ self .center_min = None
74+ self .center_max = None
75+
7176 self .show ()
7277
7378 def open_file (self ):
@@ -129,7 +134,8 @@ def plot(self):
129134 if self .ui .norm_checkBox .isChecked ():
130135 self .normalize ()
131136
132- self .ui .plot .plot (self .x , self .y , clear = False , pen = 'r' )
137+ self .ui .plot .plot (self .x , self .y , clear = self .clear_check (), pen = 'r' )
138+ self .ui .Result_textBrowser .setText (str (self .clear_check ))
133139 except :
134140 pass
135141 self .ui .plot .setLabel ('left' , 'Intensity' , units = 'a.u.' )
@@ -142,6 +148,21 @@ def normalize(self):
142148 def clear_plot (self ):
143149 self .ui .plot .clear ()
144150# self.ui.Result_textBrowser.clear()
151+
152+ def clear_check (self ):
153+ if self .ui .clear_checkBox .isChecked () == True :
154+ return True
155+ elif self .ui .clear_checkBox .isChecked () == False :
156+ return False
157+
158+ def configure_fit_params (self ):
159+ self .param_window = ParamWindow ()
160+ self .param_window .peak_range .connect (self .peak_range )
161+
162+ def peak_range (self , peaks ):
163+ self .center_min = peaks [0 ]
164+ self .center_max = peaks [1 ]
165+
145166
146167 def fit_and_plot (self ):
147168 fit_func = self .ui .fitFunc_comboBox .currentText ()
@@ -156,24 +177,26 @@ def fit_and_plot(self):
156177 if fit_func == "Single Gaussian" and self .ui .subtract_bck_checkBox .isChecked () == True :
157178
158179 single_gauss = Single_Gaussian (self .file , self .bck_file , wlref = self .wlref_file )
159- self .result = single_gauss .gaussian_model ()
160- self .ui .plot .plot (self .x , self .y , clear = True , pen = 'r' )
180+
181+ if self .ui .adjust_param_checkBox .isChecked ():
182+ self .result = single_gauss .gaussian_model_w_lims (
183+ center_min = self .center_min , center_max = self .center_max )
184+ else :
185+ self .result = single_gauss .gaussian_model ()
186+ self .ui .plot .plot (self .x , self .y , clear = self .clear_check (), pen = 'r' )
161187 self .ui .plot .plot (self .x , self .result .best_fit , clear = False , pen = 'k' )
162188 self .ui .result_textBrowser .setText (self .result .fit_report ())
163189
164190 elif fit_func == "Single Lorentzian" and self .ui .subtract_bck_checkBox .isChecked () == True :
165191
166192 single_lorentzian = Single_Lorentzian (self .file , self .bck_file , wlref = self .wlref_file )
167- """Needs work -- adjust param not working"""
193+
168194 if self .ui .adjust_param_checkBox .isChecked ():
169- self .param_window = ParamWindow ()
170- self .param_window .show ()
171- center_min , center_max = self .param_window .done ()
172195 self .result = single_lorentzian .lorentzian_model_w_lims (
173- center_min = center_min , center_max = center_max )
196+ center_min = self . center_min , center_max = self . center_max )
174197 else :
175198 self .result = single_lorentzian .lorentzian_model ()
176- self .ui .plot .plot (self .x , self .y , clear = True , pen = 'r' )
199+ self .ui .plot .plot (self .x , self .y , clear = self . clear_check () , pen = 'r' )
177200 self .ui .plot .plot (self .x , self .result .best_fit , clear = False , pen = 'k' )
178201 self .ui .result_textBrowser .setText (self .result .fit_report ())
179202
@@ -210,35 +233,44 @@ def close_application(self):
210233 sys .exit ()
211234 else :
212235 pass
236+
237+
213238
214239param_file_path = (base_path / "peak_bounds_input.ui" ).resolve ()
215240
216- uiFile = file_path
241+ param_uiFile = param_file_path
217242
218- param_WindowTemplate , param_TemplateBaseClass = pg .Qt .loadUiType (uiFile )
243+ param_WindowTemplate , param_TemplateBaseClass = pg .Qt .loadUiType (param_uiFile )
219244
220- class ParamWindow (param_TemplateBaseClass ):
245+ class ParamWindow (param_TemplateBaseClass ):
246+
247+ peak_range = QtCore .pyqtSignal (list )
221248
222249 def __init__ (self ):
250+ # super(param_TemplateBaseClass, self).__init__()
223251 param_TemplateBaseClass .__init__ (self )
224252
225- # Create the main window
226- self .ui = param_WindowTemplate ()
227- self .ui .setupUi (self )
253+ # Create the param window
254+ self .pui = param_WindowTemplate ()
255+ self .pui .setupUi (self )
228256
229- self .ui .pushButton .clicked .connect (self .done )
257+ self .pui .pushButton .clicked .connect (self .done )
230258
231259 self .show ()
232260
233- def done (self ):
234- center_min = self .ui .cent_min_doubleSpinBox .value ()
235- center_max = self .ui .cent_max_doubleSpinBox .value ()
261+ def current_peak_range (self ):
262+ center_min = self .pui .cent_min_doubleSpinBox .value ()
263+ center_max = self .pui .cent_max_doubleSpinBox .value ()
236264 return center_min , center_max
265+
266+ def done (self ):
267+ center_min , center_max = self .current_peak_range ()
268+ self .peak_range .emit ([center_min , center_max ])
237269
238270def run ():
239271 win = MainWindow ()
240272 QtGui .QApplication .instance ().exec_ ()
241273 return win
242274
243275#Uncomment below if you want to run this as standalone
244- # run()
276+ run ()
0 commit comments