Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 20b3f46

Browse files
author
LAKESIDE\LindaT18
committed
added bounds and initial guess to spec_plot ui, modified fit_funcs, implemented double gaussian
1 parent 01ef75e commit 20b3f46

3 files changed

Lines changed: 1146 additions & 560 deletions

File tree

PythonGUI_apps/Spectrum_analysis/Spectra_fit_funcs.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ def gaussian_model(self):
5656
result = gmodel.fit(y, pars, x=x, nan_policy='propagate')
5757
return result
5858

59-
def gaussian_model_w_lims(self, center_min=None, center_max=None):
59+
def gaussian_model_w_lims(self, center_initial_guess=None, sigma_initial_guess=None, center_min=None, center_max=None):
6060
x,y = self.background_correction()
6161
gmodel = GaussianModel(prefix = 'g1_') # calling gaussian model
6262
pars = gmodel.guess(y, x=x) # parameters - center, width, height
63-
pars['g1_center'].set(min=center_min, max=center_max)
63+
pars['g1_center'].set(center_initial_guess, min=center_min, max=center_max)
64+
pars['g1_sigma'].set(sigma_initial_guess)
6465
result = gmodel.fit(y, pars, x=x, nan_policy='propagate')
65-
return result
66+
return result #770 760 780 sigma 15
6667

6768
class Single_Lorentzian(Spectra_Fit):
6869
"""Fit a single Lorentzian to the spectrum
@@ -79,11 +80,20 @@ def lorentzian_model(self):
7980
result = lmodel.fit(y, pars, x=x, nan_policy='propagate')
8081
return result
8182

82-
def lorentzian_model_w_lims(self, center_min = None, center_max = None):
83+
# def lorentzian_model_w_lims(self, center_min = None, center_max = None):
84+
# x,y = self.background_correction()
85+
# lmodel = LorentzianModel(prefix = 'l1_') # calling lorentzian model
86+
# pars = lmodel.guess(y, x=x) # parameters - center, width, height
87+
# pars['l1_center'].set(min = center_min, max = center_max)
88+
# result = lmodel.fit(y, pars, x=x, nan_policy='propagate')
89+
# return result
90+
91+
def lorentzian_model_w_lims(self, center_initial_guess=None, sigma_initial_guess=None, center_min = None, center_max = None):
8392
x,y = self.background_correction()
8493
lmodel = LorentzianModel(prefix = 'l1_') # calling lorentzian model
8594
pars = lmodel.guess(y, x=x) # parameters - center, width, height
86-
pars['l1_center'].set(min = center_min, max = center_max)
95+
pars['l1_center'].set(center_initial_guess, min = center_min, max = center_max)
96+
pars['l1_sigma'].set(sigma_initial_guess)
8797
result = lmodel.fit(y, pars, x=x, nan_policy='propagate')
8898
return result
8999

@@ -96,18 +106,35 @@ class Double_Gaussian(Spectra_Fit):
96106
"""
97107

98108
def gaussian_model(self):
109+
110+
x,y = self.background_correction()
111+
gmodel_1 = GaussianModel(prefix='g1_') # calling gaussian model
112+
pars = gmodel_1.guess(y, x=x) # parameters - center, width, height
113+
114+
gmodel_2 = GaussianModel(prefix='g2_')
115+
pars.update(gmodel_2.make_params()) # update parameters - center, width, height
116+
117+
gmodel = gmodel_1 + gmodel_2
118+
result = gmodel.fit(y, pars, x=x, nan_policy='propagate')
119+
return result
120+
121+
def gaussian_model_w_lims(self, center_initial_guesses=None, sigma_initial_guesses=None, min_max_range=None):
122+
#center_initial_guesses - list containing initial guesses for peak centers. [center_guess1, center_guess2]
123+
#sigma_initial_guesses - list containing initial guesses for sigma. [sigma1, sigma2]
124+
#min_max_range - list containing lists of min and max for peak center. [ [min1, max1], [min2, max2] ]
125+
99126
x,y = self.background_correction()
100127
gmodel_1 = GaussianModel(prefix='g1_') # calling gaussian model
101128
pars = gmodel_1.guess(y, x=x) # parameters - center, width, height
102-
pars['g1_center'].set(800, min = 795, max = 820)
103-
pars['g1_sigma'].set(15)
129+
pars['g1_center'].set(center_initial_guesses[0], min = min_max_range[0][0], max = min_max_range[0][1])
130+
pars['g1_sigma'].set(sigma_initial_guesses[0])
104131
pars['g1_amplitude'].set(min=0)
105132

106133
gmodel_2 = GaussianModel(prefix='g2_')
107134
pars.update(gmodel_2.make_params()) # update parameters - center, width, height
108-
pars['g2_center'].set(767, min = 760, max = 775)
135+
pars['g2_center'].set(center_initial_guesses[1], min = min_max_range[1][0], max = min_max_range[1][1])
136+
pars['g2_sigma'].set(sigma_initial_guesses[1])
109137
pars['g2_amplitude'].set(min = 0)
110-
pars['g2_sigma'].set(min = pars['g1_sigma'].value)
111138

112139
gmodel = gmodel_1 + gmodel_2
113140
result = gmodel.fit(y, pars, x=x, nan_policy='propagate')
@@ -146,7 +173,7 @@ def multi_gaussian(self):
146173
else:
147174
composite_pars.update(model.make_params())
148175
composite_pars['g'+str(i+1)+'_center'].set(self.peak_pos[i],
149-
min = self.min_max_range[1][0], max = self.min_max_range[1][1])
176+
min = self.min_max_range[i][0], max = self.min_max_range[i][1])
150177
composite_pars['g'+str(i+1)+'_sigma'].set(min = composite_pars['g1_sigma'].value)
151178
composite_pars['g'+str(i+1)+'_amplitude'].set(min = 0)
152179

0 commit comments

Comments
 (0)