Skip to content

Commit 6580ad0

Browse files
add multiple traces for export
1 parent d5166ba commit 6580ad0

File tree

2 files changed

+120
-60
lines changed

2 files changed

+120
-60
lines changed

PythonGUI_apps/Spectrum_analysis/Spectra_plot_fit.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def __init__(self):
9292
self.ui.fit_scan_pushButton.clicked.connect(self.fit_and_plot_scan)
9393
# self.ui.config_fit_params_pushButton.clicked.connect(self.configure_fit_params)
9494
self.ui.clear_pushButton.clicked.connect(self.clear_plot)
95+
self.ui.add_to_mem_pushButton.clicked.connect(self.add_trace_to_mem)
9596
self.ui.export_single_figure_pushButton.clicked.connect(self.pub_ready_plot_export)
9697
self.ui.export_scan_figure_pushButton.clicked.connect(self.export_window)
9798
self.ui.analyze_spectra_fits_pushButton.clicked.connect(self.analyze_spectra_fits)
@@ -133,6 +134,13 @@ def __init__(self):
133134

134135
#container for data to append to txt file
135136
self.data_list = []
137+
138+
#for adding traces to memory for plotting/exporting all at once
139+
self.x_mem = []
140+
self.y_mem = []
141+
self.best_fit_mem = []
142+
self.legend = []
143+
self.single_spec_fit_called = False
136144

137145
self.show()
138146

@@ -364,6 +372,8 @@ def plot(self):
364372
pass
365373
self.ui.plot.setLabel('left', 'Intensity', units='a.u.')
366374
self.ui.plot.setLabel('bottom', 'Wavelength (nm)')
375+
376+
self.single_spec_fit_called = False
367377

368378
def normalize(self):
369379
self.y = (self.y) / np.amax(self.y)
@@ -505,6 +515,7 @@ def fit_and_plot(self):
505515
self.ui.result_textBrowser.setText(self.result.fit_report())
506516

507517
self.data_list.append(self.ui.result_textBrowser.toPlainText())
518+
self.single_spec_fit_called = True
508519

509520
except Exception as e:
510521
self.ui.result_textBrowser.append(str(e))
@@ -546,16 +557,24 @@ def pub_ready_plot_export(self):
546557
plt.savefig(filename[0],bbox_inches='tight', dpi=300)
547558
plt.close()
548559
except:
549-
plt.figure(figsize=(8,6))
550-
plt.tick_params(direction='out', length=8, width=3.5)
551-
plt.plot(self.x, self.y)
552-
plt.plot(self.x, self.result.best_fit,'k')
553-
plt.xlabel("Wavelength (nm)", fontsize=20, fontweight='bold')
554-
plt.ylabel("Intensity (a.u.)", fontsize=20, fontweight='bold')
555-
plt.tight_layout()
556-
557-
plt.savefig(filename[0],bbox_inches='tight', dpi=300)
558-
plt.close()
560+
if self.x_mem == []:
561+
self.ui.result_textBrowser.setText("Add traces to memory first!")
562+
else:
563+
plt.figure(figsize=(8,6))
564+
plt.tick_params(direction='out', length=8, width=3.5)
565+
for i in range(len(self.x_mem)):
566+
plt.plot(self.x_mem[i], self.y_mem[i], label=str(self.legend[i]))
567+
if self.single_spec_fit_called == True:
568+
plt.plot(self.x_mem[i], self.best_fit_mem[i],'k')
569+
#plt.plot(self.x, self.y)
570+
#plt.plot(self.x, self.result.best_fit,'k')
571+
plt.xlabel("Wavelength (nm)", fontsize=20, fontweight='bold')
572+
plt.ylabel("Intensity (a.u.)", fontsize=20, fontweight='bold')
573+
plt.legend()
574+
plt.tight_layout()
575+
576+
plt.savefig(filename[0],bbox_inches='tight', dpi=300)
577+
plt.close()
559578

560579
except AttributeError:
561580
self.ui.result_textBrowser.setText("Need to fit the data first!")
@@ -580,6 +599,20 @@ def export_data(self):
580599

581600
def clear_export_data(self):
582601
self.data_list = []
602+
self.x_mem = []
603+
self.y_mem = []
604+
self.legend = []
605+
self.best_fit_mem = []
606+
607+
def add_trace_to_mem(self):
608+
try:
609+
self.x_mem.append(self.x)
610+
self.y_mem.append(self.y)
611+
if self.single_spec_fit_called == True:
612+
self.best_fit_mem.append(self.result.best_fit)
613+
self.legend.append(self.ui.lineEdit.text())
614+
except Exception as e:
615+
print(e)
583616

584617

585618
""" Scan spectra functions """

PythonGUI_apps/Spectrum_analysis/Spectra_plot_fit_gui.ui

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -772,124 +772,121 @@
772772
<string>Load Settings</string>
773773
</property>
774774
<layout class="QGridLayout" name="gridLayout_13">
775-
<item row="2" column="0">
776-
<widget class="QPushButton" name="importBck_pushButton">
775+
<item row="4" column="0">
776+
<widget class="QRadioButton" name="subtract_bck_radioButton">
777777
<property name="font">
778778
<font>
779779
<pointsize>10</pointsize>
780780
</font>
781781
</property>
782782
<property name="text">
783-
<string>Background
784-
File</string>
783+
<string>Subtract Background</string>
784+
</property>
785+
<property name="checked">
786+
<bool>true</bool>
785787
</property>
786788
</widget>
787789
</item>
788-
<item row="7" column="0">
789-
<widget class="QCheckBox" name="norm_checkBox">
790+
<item row="2" column="0">
791+
<widget class="QPushButton" name="importBck_pushButton">
790792
<property name="font">
791793
<font>
792794
<pointsize>10</pointsize>
793795
</font>
794796
</property>
795797
<property name="text">
796-
<string>Normalize</string>
798+
<string>Background File</string>
797799
</property>
798800
</widget>
799801
</item>
800-
<item row="9" column="0">
801-
<widget class="QCheckBox" name="clear_checkBox">
802+
<item row="6" column="0">
803+
<widget class="QCheckBox" name="WLRef_checkBox">
802804
<property name="font">
803805
<font>
804806
<pointsize>10</pointsize>
805807
</font>
806808
</property>
807809
<property name="text">
808-
<string>Clear Plots Everytime</string>
809-
</property>
810-
<property name="checked">
811-
<bool>true</bool>
810+
<string>Correct for White Light</string>
812811
</property>
813812
</widget>
814813
</item>
815-
<item row="6" column="0">
816-
<widget class="QCheckBox" name="WLRef_checkBox">
814+
<item row="3" column="0">
815+
<widget class="QPushButton" name="importWLRef_pushButton">
817816
<property name="font">
818817
<font>
819818
<pointsize>10</pointsize>
820819
</font>
821820
</property>
822821
<property name="text">
823-
<string>Correct for White Light</string>
822+
<string>White Light Ref File</string>
824823
</property>
825824
</widget>
826825
</item>
827-
<item row="0" column="0">
828-
<widget class="QLabel" name="label_2">
826+
<item row="9" column="0">
827+
<widget class="QCheckBox" name="clear_checkBox">
829828
<property name="font">
830829
<font>
831830
<pointsize>10</pointsize>
832831
</font>
833832
</property>
834833
<property name="text">
835-
<string>For Single Spectrum</string>
834+
<string>Clear Plots Everytime</string>
835+
</property>
836+
<property name="checked">
837+
<bool>true</bool>
836838
</property>
837839
</widget>
838840
</item>
839-
<item row="3" column="0">
840-
<widget class="QPushButton" name="importWLRef_pushButton">
841+
<item row="15" column="0">
842+
<widget class="QPushButton" name="export_data_pushButton">
841843
<property name="font">
842844
<font>
843845
<pointsize>10</pointsize>
844846
</font>
845847
</property>
846848
<property name="text">
847-
<string>White Light
848-
Ref File</string>
849+
<string>Export Fit Data</string>
849850
</property>
850851
</widget>
851852
</item>
852-
<item row="4" column="0">
853-
<widget class="QRadioButton" name="subtract_bck_radioButton">
853+
<item row="1" column="0">
854+
<widget class="QPushButton" name="importSpec_pushButton">
854855
<property name="font">
855856
<font>
856857
<pointsize>10</pointsize>
857858
</font>
858859
</property>
859860
<property name="text">
860-
<string>Subtract Background</string>
861-
</property>
862-
<property name="checked">
863-
<bool>true</bool>
861+
<string>Spectrum File</string>
864862
</property>
865863
</widget>
866864
</item>
867-
<item row="1" column="0">
868-
<widget class="QPushButton" name="importSpec_pushButton">
865+
<item row="7" column="0">
866+
<widget class="QCheckBox" name="norm_checkBox">
869867
<property name="font">
870868
<font>
871869
<pointsize>10</pointsize>
872870
</font>
873871
</property>
874872
<property name="text">
875-
<string>Spectrum
876-
File</string>
873+
<string>Normalize</string>
877874
</property>
878875
</widget>
879876
</item>
880-
<item row="12" column="0">
881-
<widget class="QPushButton" name="export_data_pushButton">
877+
<item row="0" column="0">
878+
<widget class="QLabel" name="label_2">
882879
<property name="font">
883880
<font>
884881
<pointsize>10</pointsize>
885882
</font>
886883
</property>
887884
<property name="text">
888-
<string>Export data</string>
885+
<string>For Single Spectrum</string>
889886
</property>
890887
</widget>
891888
</item>
892-
<item row="14" column="0">
889+
<item row="17" column="0">
893890
<widget class="QTextBrowser" name="result_textBrowser">
894891
<property name="font">
895892
<font>
@@ -898,42 +895,39 @@ File</string>
898895
</property>
899896
</widget>
900897
</item>
901-
<item row="8" column="0">
902-
<widget class="QPushButton" name="plot_pushButton">
898+
<item row="5" column="0">
899+
<widget class="QRadioButton" name="plot_without_bck_radioButton">
903900
<property name="font">
904901
<font>
905902
<pointsize>10</pointsize>
906-
<weight>50</weight>
907-
<bold>false</bold>
908903
</font>
909904
</property>
910905
<property name="text">
911-
<string>Plot</string>
906+
<string>Plot without Background</string>
912907
</property>
913908
</widget>
914909
</item>
915-
<item row="11" column="0">
910+
<item row="14" column="0">
916911
<widget class="QPushButton" name="export_single_figure_pushButton">
917912
<property name="font">
918913
<font>
919914
<pointsize>10</pointsize>
920915
</font>
921916
</property>
922917
<property name="text">
923-
<string>Export Publication
924-
Ready Figure</string>
918+
<string>Export Figure</string>
925919
</property>
926920
</widget>
927921
</item>
928-
<item row="5" column="0">
929-
<widget class="QRadioButton" name="plot_without_bck_radioButton">
922+
<item row="16" column="0">
923+
<widget class="QPushButton" name="clear_export_data_pushButton">
930924
<property name="font">
931925
<font>
932926
<pointsize>10</pointsize>
933927
</font>
934928
</property>
935929
<property name="text">
936-
<string>Plot without Background</string>
930+
<string>Clear Export Memory</string>
937931
</property>
938932
</widget>
939933
</item>
@@ -950,15 +944,48 @@ Ready Figure</string>
950944
</property>
951945
</widget>
952946
</item>
947+
<item row="8" column="0">
948+
<widget class="QPushButton" name="plot_pushButton">
949+
<property name="font">
950+
<font>
951+
<pointsize>10</pointsize>
952+
<weight>50</weight>
953+
<bold>false</bold>
954+
</font>
955+
</property>
956+
<property name="text">
957+
<string>Plot</string>
958+
</property>
959+
</widget>
960+
</item>
953961
<item row="13" column="0">
954-
<widget class="QPushButton" name="clear_export_data_pushButton">
962+
<widget class="QPushButton" name="add_to_mem_pushButton">
963+
<property name="font">
964+
<font>
965+
<pointsize>10</pointsize>
966+
</font>
967+
</property>
968+
<property name="text">
969+
<string>Add Trace to Memory</string>
970+
</property>
971+
</widget>
972+
</item>
973+
<item row="12" column="0">
974+
<widget class="QLineEdit" name="lineEdit">
955975
<property name="font">
956976
<font>
957977
<pointsize>10</pointsize>
958978
</font>
959979
</property>
960980
<property name="text">
961-
<string>Clear export data</string>
981+
<string>Enter Legend Here...</string>
982+
</property>
983+
</widget>
984+
</item>
985+
<item row="11" column="0">
986+
<widget class="QLabel" name="label_38">
987+
<property name="text">
988+
<string>Export Settings</string>
962989
</property>
963990
</widget>
964991
</item>

0 commit comments

Comments
 (0)