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

Commit f2ded3e

Browse files
fixed background correction problem for analyzing PSF, corrected using LinearModel from lmfit as autobackground correction as part of a composite model with Gaussian Model
1 parent c9587b4 commit f2ded3e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

PythonGUI_apps/Spectrum_analysis/Spectra_plot_fit.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import matplotlib
1818
import pickle
1919
import lmfit
20-
from lmfit.models import GaussianModel
20+
from lmfit.models import GaussianModel, LinearModel
2121
from scipy import interpolate
2222
import customplotting.mscope as cpm
2323

@@ -372,6 +372,16 @@ def fit_and_plot(self):
372372
self.file = np.zeros((self.x.shape[0], 2))
373373
self.file[:,0] = self.x
374374
self.file[:,1] = self.y
375+
bck = lmfit.models.LinearModel(prefix='line_')
376+
gmodel = GaussianModel(prefix='g1_')
377+
pars = bck.make_params(intercept=self.y.min(), slope=0)
378+
pars += gmodel.guess(self.y, x=self.x)
379+
comp_model = gmodel + bck
380+
self.result = comp_model.fit(self.y, pars, x=self.x, nan_policy='propagate')
381+
self.ui.plot.plot(self.x, self.y, clear=self.clear_check(), pen='r')
382+
self.ui.plot.plot(self.x, self.result.best_fit, clear=False, pen='k')
383+
self.ui.result_textBrowser.setText(self.result.fit_report())
384+
375385

376386
if self.ui.plot_without_bck_radioButton.isChecked(): #if plot w/o bck, create dummy bck_file
377387
self.bck_file = np.zeros(shape=(self.file.shape[0], 2))
@@ -381,6 +391,8 @@ def fit_and_plot(self):
381391
# self.ui.result_textBrowser.setText("You need to check the subtract background option!")
382392
if self.check_loaded_files is None:
383393
pass
394+
elif self.opened_from_flim:
395+
pass
384396
else:
385397

386398
if fit_func == "Single Gaussian": #and self.ui.subtract_bck_radioButton.isChecked() == True:

0 commit comments

Comments
 (0)