From c70a1a2220274df9dbca86748c37f5a001dc4798 Mon Sep 17 00:00:00 2001 From: "Ryan@Home" Date: Thu, 7 Nov 2024 22:55:42 -0500 Subject: [PATCH] when no expData found, create a template. --- Cleopatra/FitExData.py | 10 +++++----- PyGUIQt6/PtolemyGUIPy.py | 28 ++++++++++++++++++++++++++-- PyGUIQt6/expData.txt | 25 ------------------------- 3 files changed, 31 insertions(+), 32 deletions(-) delete mode 100644 PyGUIQt6/expData.txt diff --git a/Cleopatra/FitExData.py b/Cleopatra/FitExData.py index d19cb1b..89ddc2d 100644 --- a/Cleopatra/FitExData.py +++ b/Cleopatra/FitExData.py @@ -65,16 +65,16 @@ class Fitting(): if line.startswith("$"): continue - # Check for excitation energy lines + # Check for dataSet lines if line.startswith("#="): # If there's an existing data block, save it if current_data: self.expData.append(np.array(current_data, dtype=float)) current_data = [] - # Extract excitation energy - Ex_energy = line.split()[1] - self.ExList.append(float(Ex_energy)) + # Extract dataSet Name + dataName = line.split()[1] + self.ExList.append(dataName) # Check for fit option lines elif line.startswith("fit"): @@ -206,7 +206,7 @@ class Fitting(): plt.yscale('log') # Replace plt.title() with plt.text() to position the title inside the plot - plt.text(0.05, 0.05, f'Fit for Exp Data : {self.ExList[expDataID]} MeV', transform=plt.gca().transAxes, + plt.text(0.05, 0.05, f'Fit for Exp Data : {self.ExList[expDataID]}', transform=plt.gca().transAxes, fontsize=12, verticalalignment='bottom', horizontalalignment='left', color='black') for i, _ in enumerate(para): diff --git a/PyGUIQt6/PtolemyGUIPy.py b/PyGUIQt6/PtolemyGUIPy.py index db327a7..506bef7 100755 --- a/PyGUIQt6/PtolemyGUIPy.py +++ b/PyGUIQt6/PtolemyGUIPy.py @@ -264,8 +264,23 @@ class MyWindow(QMainWindow): self.SaveLastOpenDWBASource() def LoadExpDataToTextBox(self): - self.LoadFileToTextBox(self.ExpDataFileName) - self.leFileName.setText(self.DWBAFileName) + if self.ExpDataFileName == "" : + self.text_edit.clear() + self.text_edit.append("$<-- for comment line") + self.text_edit.append("$No expData found, this is a template") + self.text_edit.append("$line start with '#=' starts a data set") + self.text_edit.append("#============== state") + self.text_edit.append("$line started with 'fit' indicate which DWBA Xsec to be fitted. ") + self.text_edit.append("$0 for the fist one, 0+1 fit both 0 and 1.") + self.text_edit.append("fit 0, 0+1") + self.text_edit.append("$angle_deg ang_err count count_err") + self.text_edit.append("10 1 100 10") + self.text_edit.append("20 1 200 14") + self.text_edit.append("30 1 80 7") + else: + self.LoadFileToTextBox(self.ExpDataFileName) + self.leFileName.setText(self.DWBAFileName) + self.bnSaveExpDataFile.setEnabled(True) self.bnSaveFile.setEnabled(False) @@ -300,9 +315,18 @@ class MyWindow(QMainWindow): def SaveExpDataFile(self): if self.bnSaveExpDataFile.isEnabled() : file_path = self.leExpDataFileName.text() + if file_path == "" : + file_path, _ = QFileDialog.getSaveFileName(self, "Save File", "", "Text Files (*.txt)") + if not file_path.lower().endswith(".txt"): + file_path += ".txt" + self.leExpDataFileName.setText(file_path) + self.ExpDataFileName = file_path + with open(file_path, 'w') as file: file.write(self.text_edit.toPlainText()) self.leStatus.setText(f"File saved to: {file_path}") + + self.SaveLastOpenDWBASource() def DeleteinOutXsecFiles(self): if os.path.exists(self.DWBAFileName + ".in"): diff --git a/PyGUIQt6/expData.txt b/PyGUIQt6/expData.txt deleted file mode 100644 index 5ac8373..0000000 --- a/PyGUIQt6/expData.txt +++ /dev/null @@ -1,25 +0,0 @@ -#================ 4.4 MeV -fit 0, 1 -#angle err count err -28.71 1.845 129 11.4 -32.74 1.62 60 7.7 -#================ 15.11 MeV -fit 2, 3, 4 -12.70 2.85 112 10.6 -22.73 2.97 68 8.2 -28.90 2.31 49 7.0 -#================ 15.11 MeV -fit 2+3 -12.70 2.85 112 10.6 -22.73 2.97 68 8.2 -28.90 2.31 49 7.0 -#================ 15.11 MeV -fit 3+4 -12.70 2.85 112 10.6 -22.73 2.97 68 8.2 -28.90 2.31 49 7.0 -#================ 15.11 MeV -fit 2+3+4 -12.70 2.85 112 10.6 -22.73 2.97 68 8.2 -28.90 2.31 49 7.0 \ No newline at end of file