when no expData found, create a template.

This commit is contained in:
Ryan@Home 2024-11-07 22:55:42 -05:00
parent 0183197a7f
commit c70a1a2220
3 changed files with 31 additions and 32 deletions

View File

@ -65,16 +65,16 @@ class Fitting():
if line.startswith("$"): if line.startswith("$"):
continue continue
# Check for excitation energy lines # Check for dataSet lines
if line.startswith("#="): if line.startswith("#="):
# If there's an existing data block, save it # If there's an existing data block, save it
if current_data: if current_data:
self.expData.append(np.array(current_data, dtype=float)) self.expData.append(np.array(current_data, dtype=float))
current_data = [] current_data = []
# Extract excitation energy # Extract dataSet Name
Ex_energy = line.split()[1] dataName = line.split()[1]
self.ExList.append(float(Ex_energy)) self.ExList.append(dataName)
# Check for fit option lines # Check for fit option lines
elif line.startswith("fit"): elif line.startswith("fit"):
@ -206,7 +206,7 @@ class Fitting():
plt.yscale('log') plt.yscale('log')
# Replace plt.title() with plt.text() to position the title inside the plot # 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') fontsize=12, verticalalignment='bottom', horizontalalignment='left', color='black')
for i, _ in enumerate(para): for i, _ in enumerate(para):

View File

@ -264,8 +264,23 @@ class MyWindow(QMainWindow):
self.SaveLastOpenDWBASource() self.SaveLastOpenDWBASource()
def LoadExpDataToTextBox(self): def LoadExpDataToTextBox(self):
self.LoadFileToTextBox(self.ExpDataFileName) if self.ExpDataFileName == "" :
self.leFileName.setText(self.DWBAFileName) 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.bnSaveExpDataFile.setEnabled(True)
self.bnSaveFile.setEnabled(False) self.bnSaveFile.setEnabled(False)
@ -300,9 +315,18 @@ class MyWindow(QMainWindow):
def SaveExpDataFile(self): def SaveExpDataFile(self):
if self.bnSaveExpDataFile.isEnabled() : if self.bnSaveExpDataFile.isEnabled() :
file_path = self.leExpDataFileName.text() 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: with open(file_path, 'w') as file:
file.write(self.text_edit.toPlainText()) file.write(self.text_edit.toPlainText())
self.leStatus.setText(f"File saved to: {file_path}") self.leStatus.setText(f"File saved to: {file_path}")
self.SaveLastOpenDWBASource()
def DeleteinOutXsecFiles(self): def DeleteinOutXsecFiles(self):
if os.path.exists(self.DWBAFileName + ".in"): if os.path.exists(self.DWBAFileName + ".in"):

View File

@ -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