From 124e375746bf519c68b9f372bfdd50d64051c0b0 Mon Sep 17 00:00:00 2001 From: Julian-Hochhaus# Date: Tue, 27 Jun 2023 15:03:25 +0200 Subject: [PATCH] - removed constraint for asymmetry. negative values are now allowed too. this enables fitting using binding energy data with asymmetry - modified calculation of area and fwhm, so that the calculation takes care, if the data are present with regards to binding energy scale or kinetic energy scale - solves #73 as well as some of the topics discussed in #71 --- Python/main.py | 39 +++++++++++++++++++++++++++++---------- Python/usrmodel.py | 4 ++-- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Python/main.py b/Python/main.py index d928aaf..335adf4 100644 --- a/Python/main.py +++ b/Python/main.py @@ -83,6 +83,7 @@ def __init__(self): self.error_dialog = QtWidgets.QErrorMessage() self.displayChoosenBG = QtWidgets.QLabel() self.delegate = TableItemDelegate() + self.binding_ener=False self.initUI() def initUI(self): @@ -2403,7 +2404,7 @@ def PeakSelector(self, mod): if index == 4 or index == 5 or index == 9 or index == 10 or index == 11: if self.pre[2][5][2 * index_pk + 1] is not None and len(str(self.pre[2][5][2 * index_pk + 1])) > 0: pars[strind + str(index_pk + 1) + '_gamma'].value = float(self.pre[2][5][2 * index_pk + 1]) - pars[strind + str(index_pk + 1) + '_gamma'].min = 0 + #pars[strind + str(index_pk + 1) + '_gamma'].min = 0 pars[strind + str(index_pk + 1) + '_gamma'].max=1 if self.pre[2][5][2 * index_pk] == 2: pars[strind + str(index_pk + 1) + '_gamma'].vary = False @@ -2853,7 +2854,10 @@ def fillTabResults(self, x, y, out): strind = self.list_shape[index] strind = strind.split(":", 1)[0] y_components += out.eval_components()[strind + str(index_pk + 1) + '_'] - area_components = integrate.simps([y for y, x in zip(y_components, x)]) + if self.binding_ener: + area_components = integrate.simps([y for y, x in zip(y_components, x[::-1])],x[::-1]) + else: + area_components = integrate.simps([y for y, x in zip(y_components, x)], x) for index_pk in range(int(len(self.pre[2][0]) / 2)): index = self.pre[2][0][2 * index_pk + 1] strind = self.list_shape[index] @@ -2878,7 +2882,10 @@ def fillTabResults(self, x, y, out): str(format(out.params[strind + str(index_pk + 1) + '_height'].value, self.floating))) self.res_tab.setItem(5, index_pk, item) y_area = out.eval_components()[strind + str(index_pk + 1) + '_'] - area = abs(integrate.simps([y for y, x in zip(y_area, x)], x)) + if self.binding_ener: + area = abs(integrate.simps([y for y, x in zip(y_area, x[::-1])], x[::-1])) + else: + area= abs(integrate.simps([y for y, x in zip(y_area, x)], x)) item = QtWidgets.QTableWidgetItem(str(format(area, '.1f') + r' ({}%)'.format(format(100, '.2f')))) self.res_tab.setItem(7, index_pk, item) item = QtWidgets.QTableWidgetItem(str(format(area, '.1f') + r' ({}%)'.format(format(100, '.2f')))) @@ -2899,7 +2906,10 @@ def fillTabResults(self, x, y, out): self.res_tab.setItem(row, index_pk, item) # included area y_area = out.eval_components()[strind + str(index_pk + 1) + '_'] - area = abs(integrate.simps([y for y, x in zip(y_area, x)], x)) + if self.binding_ener: + area = abs(integrate.simps([y for y, x in zip(y_area, x[::-1])], x[::-1])) + else: + area = abs(integrate.simps([y for y, x in zip(y_area, x)], x)) item = QtWidgets.QTableWidgetItem(str(format(area, '.1f') + r' ({}%)'.format(format(100, '.2f')))) self.res_tab.setItem(7, index_pk, item) item = QtWidgets.QTableWidgetItem(str(format(area, '.1f') + r' ({}%)'.format(format(100, '.2f')))) @@ -2926,7 +2936,7 @@ def fillTabResults(self, x, y, out): if np.max(y_area) != 0: y_temp = y_area / np.max(y_area) x_ = [i for i, j in zip(x, y_temp) if j >= 0.5] - fwhm_temp = x_[-1] - x_[0] + fwhm_temp = abs(x_[-1] - x_[0]) item = QtWidgets.QTableWidgetItem(str(format(fwhm_temp, self.floating))) self.res_tab.setItem(3, index_pk, item) else: @@ -2935,7 +2945,10 @@ def fillTabResults(self, x, y, out): item = QtWidgets.QTableWidgetItem("Error in calculation") self.res_tab.setItem(3, index_pk, item) # included area - area = abs(integrate.simps([y for y, x in zip(y_area, x)], x)) + if self.binding_ener: + area= abs(integrate.simps([y for y, x in zip(y_area, x[::-1])], x[::-1])) + else: + area = abs(integrate.simps([y for y, x in zip(y_area, x)], x)) item = QtWidgets.QTableWidgetItem( str(format(area, '.1f') + r' ({}%)'.format(format(area / area_components * 100, '.2f')))) self.res_tab.setItem(7, index_pk, item) @@ -2972,12 +2985,12 @@ def fillTabResults(self, x, y, out): if np.max(y_area_p1) != 0 and np.max(y_area_p2) != 0: y_temp_p1 = y_area_p1 / np.max(y_area_p1) x_p1 = [i for i, j in zip(x, y_temp_p1) if j >= 0.5] - fwhm_temp_p1 = x_p1[-1] - x_p1[0] + fwhm_temp_p1 = abs(x_p1[-1] - x_p1[0]) item = QtWidgets.QTableWidgetItem(str(format(fwhm_temp_p1, self.floating))) self.res_tab.setItem(3, index_pk, item) y_temp_p2 = y_area_p2 / np.max(y_area_p2) x_p2 = [i for i, j in zip(x, y_temp_p2) if j >= 0.5] - fwhm_temp_p2 = x_p2[-1] - x_p2[0] + fwhm_temp_p2 = abs(x_p2[-1] - x_p2[0]) item = QtWidgets.QTableWidgetItem(str(format(fwhm_temp_p2, self.floating))) self.res_tab.setItem(4, index_pk, item) else: @@ -2989,8 +3002,12 @@ def fillTabResults(self, x, y, out): self.res_tab.setItem(4, index_pk, item) # included area - area_p1 = integrate.simps([y for y, x in zip(y_area_p1, x)]) - area_p2 = integrate.simps([y for y, x in zip(y_area_p2, x)]) + if self.binding_ener: + area_p1 = abs(integrate.simps([y for y, x in zip(y_area_p1, x[::-1])], x[::-1])) + area_p2 = abs(integrate.simps([y for y, x in zip(y_area_p2, x[::-1])], x[::-1])) + else: + area_p1 = integrate.simps([y for y, x in zip(y_area_p1, x)]) + area_p2 = integrate.simps([y for y, x in zip(y_area_p2, x)]) area_ges = area_p1 + area_p2 item = QtWidgets.QTableWidgetItem( str(format(area_p1, '.1f') + r' ({}%)'.format(format(area_p1 / area_ges * 100, '.2f')))) @@ -3042,6 +3059,8 @@ def ana(self, mode): plottitle = self.plottitle.text() # self.df = np.loadtxt(str(self.comboBox_file.currentText()), delimiter=',', skiprows=1) x0 = self.df[:, 0] + if x0[-1] < x0[0]: + self.binding_ener=True x0_corrected=np.copy(x0) if self.correct_energy is not None: x0_corrected -= self.correct_energy diff --git a/Python/usrmodel.py b/Python/usrmodel.py index a8d98f7..02356de 100644 --- a/Python/usrmodel.py +++ b/Python/usrmodel.py @@ -189,7 +189,7 @@ def __init__(self, *args, **kwargs): def _set_paramhints_prefix(self): self.set_param_hint('amplitude', value=100, min=0) self.set_param_hint('sigma', value=0.2, min=0) - self.set_param_hint('gamma', value=0.02, min=0) + self.set_param_hint('gamma', value=0.02) self.set_param_hint('gaussian_sigma', value=0.2, min=0) self.set_param_hint('center', value=100, min=0) g_fwhm_expr = '2*{pre:s}gaussian_sigma*1.1774' @@ -232,7 +232,7 @@ def __init__(self, *args, **kwargs): def _set_paramhints_prefix(self): self.set_param_hint('amplitude', value=100, min=0) self.set_param_hint('sigma', value=0.2, min=0) - self.set_param_hint('gamma', value=0.02, min=0) + self.set_param_hint('gamma', value=0.02) self.set_param_hint('gaussian_sigma', value=0.2, min=0) self.set_param_hint('center', value=285) self.set_param_hint('soc', value=2.0)