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

Commit 0a7f669

Browse files
correct path error for ui, must select bckg correc while fitting, added run function
1 parent 615f871 commit 0a7f669

1 file changed

Lines changed: 31 additions & 29 deletions

File tree

PythonGUI_apps/Spectrum_analysis/Spectra_plot_fit.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
@author: Sarthak
66
"""
77

8+
import sys
9+
from pathlib import Path
10+
811
import pyqtgraph as pg
912
from pyqtgraph.Qt import QtCore, QtGui, QtWidgets#, QColorDialog
1013
import numpy as np
11-
import sys
14+
1215
from Spectra_fit_funcs import Spectra_Fit, Single_Gaussian
1316
import matplotlib.pyplot as plt
1417

@@ -23,7 +26,10 @@
2326
pg.mkQApp()
2427
pg.setConfigOption('background', 'w')
2528

26-
uiFile = "Spectra_plot_fit_gui.ui"
29+
base_path = Path(__file__).parent
30+
file_path = (base_path / "Spectra_plot_fit_gui.ui").resolve()
31+
32+
uiFile = file_path
2733

2834
WindowTemplate, TemplateBaseClass = pg.Qt.loadUiType(uiFile)
2935

@@ -120,19 +126,24 @@ def clear_plot(self):
120126
def fit_and_plot(self):
121127
fit_func = self.ui.fitFunc_comboBox.currentText()
122128

123-
if fit_func == "Single Gaussian" and self.ui.subtract_bck_checkBox.isChecked() == True:
129+
if self.ui.subtract_bck_checkBox.isChecked() == False:
130+
self.ui.result_textBrowser.setText("You need to check the subtract background option!")
131+
132+
else:
133+
if fit_func == "Single Gaussian" and self.ui.subtract_bck_checkBox.isChecked() == True:
134+
135+
single_gauss = Single_Gaussian(self.file, self.bck_file)
136+
self.result = single_gauss.gaussian_model()
137+
self.ui.plot.plot(self.x, self.y, clear=True, pen='r')
138+
self.ui.plot.plot(self.x, self.result.best_fit, clear=False, pen='k')
139+
self.ui.result_textBrowser.setText(self.result.fit_report())
140+
141+
elif fit_func == "Double Gaussian" and self.ui.subtract_bck_checkBox.isChecked() == True:
142+
self.ui.result_textBrowser.setText("Not Implemented Yet!")
143+
144+
elif fit_func == "Multiple Gaussians" and self.ui.subtract_bck_checkBox.isChecked() == True:
145+
self.ui.result_textBrowser.setText("Not Implemented Yet!")
124146

125-
single_gauss = Single_Gaussian(self.file, self.bck_file)
126-
self.result = single_gauss.gaussian_model()
127-
self.ui.plot.plot(self.x, self.y, clear=True, pen='r')
128-
self.ui.plot.plot(self.x, self.result.best_fit, clear=False, pen='k')
129-
self.ui.result_textBrowser.setText(self.result.fit_report())
130-
131-
elif fit_func == "Double Gaussian" and self.ui.subtract_bck_checkBox.isChecked() == True:
132-
self.ui.result_textBrowser.setText("Not Implemented Yet!")
133-
134-
elif fit_func == "Multiple Gaussians" and self.ui.subtract_bck_checkBox.isChecked() == True:
135-
self.ui.result_textBrowser.setText("Not Implemented Yet!")
136147

137148
def pub_ready_plot_export(self):
138149
filename = QtWidgets.QFileDialog.getSaveFileName(self,caption="Filename with EXTENSION")
@@ -161,19 +172,10 @@ def close_application(self):
161172
else:
162173
pass
163174

164-
165-
win = MainWindow()
166-
#def main():
167-
# app = QtGui.QApplication(sys.argv)
168-
# main = MainWindow()
169-
# main.show()
170-
# sys.exit(app.exec_())
171-
#
172-
#if __name__ == '__main__':
173-
# main()
175+
def run():
176+
win = MainWindow()
177+
QtGui.QApplication.instance().exec_()
178+
return win
174179

175-
# Start Qt event loop unless running in interactive mode or using pyside.
176-
if __name__ == '__main__':
177-
import sys
178-
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
179-
QtGui.QApplication.instance().exec_()
180+
#Uncomment below if you want to run this as standalone
181+
#run()

0 commit comments

Comments
 (0)