From f7da3fbac5022e962b8aed3059f613f1891c982a Mon Sep 17 00:00:00 2001 From: Christian Grech <chrisgre23@gmail.com> Date: Tue, 22 Mar 2022 21:10:09 +0100 Subject: [PATCH 1/6] Updated DOOCS writing buttons and functionality --- .gitignore | 2 ++ calculator.py | 4 ++-- gui/.DS_Store | Bin 6148 -> 8196 bytes gui/UICalculator.py | 12 ++++++------ gui/UICalculator.ui | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index dd605d9..0bf7d76 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ correlation_2d_ss.py .DS_Store model_functions/archive.txt hirexold.py +calculator_local.py +hirex_local.py diff --git a/calculator.py b/calculator.py index 08c768e..9cc04ee 100644 --- a/calculator.py +++ b/calculator.py @@ -656,11 +656,11 @@ class UICalculator(QWidget): self.doocs_permit = True try: pydoocs.write( - "XFEL.UTIL/DYNPROP/HIREX.SA2/PIXEL_CALIBRATION", 0.0) + "XFEL.UTIL/DYNPROP/HIREX.SA2/PIXEL_CALIBRATION", self.pixel_calibration_mean) self.pixel_doocs = pydoocs.read( "XFEL.UTIL/DYNPROP/HIREX.SA2/PIXEL_CALIBRATION") pydoocs.write( - "XFEL.UTIL/DYNPROP/HIREX.SA2/CENTRAL_ENERGY", 0.0) + "XFEL.UTIL/DYNPROP/HIREX.SA2/CENTRAL_ENERGY", self.dE_mean) self.central_doocs = pydoocs.read( "XFEL.UTIL/DYNPROP/HIREX.SA2/CENTRAL_ENERGY") pydoocs.write( diff --git a/gui/.DS_Store b/gui/.DS_Store index 49f527298b3f3fe616be81b0d34eb99a4d5563a3..c1e7db959bc2b8ea8df8001f44b96e4311428282 100644 GIT binary patch delta 417 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD7rCVH}hr%jz7$c**Q2SHn1>? zPUd0BpX|yaUZ0b07@VA+TL4tgz`(SA9gyT^hzG&~hDwHHhD0FFU`Pdt<mS7$B<18M z0abu(IMsIRup>UzDa5E2gBo6tf#eKkht1_IER2&qS%p#E$6)aXXd@>>Aww|`#xrCB zU6;?0$54#wwg#`C=fG~msuI~<_*8<O#03wUhRNluHIviXL?*kko!P9+^O~7Uf*a@> gS5QE27UcNOJegm_bFx1V2L~f0gcvr*^UPre0P4YBUjP6A delta 278 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$SANeU^g?Pz+@hQ{KeXWjFV3b zRT%R#gfe(CI5Q+N<S-;Nlmf{_h7yK+h9U+%ATQH1CqFqUCqD^l)Ow%=e3SEp<tK*= zpOF*<>kVcoU`Pe(EdlDuXUGMzOC|>hOZs+$)cywppl${RoT`C3u-eA>6Jf%{!t%xJ q92|noV51lWxPi1Q$ZH!5zcWwfm+=I7lz|E2X;3&YY>wxd!wdlEa6L}| diff --git a/gui/UICalculator.py b/gui/UICalculator.py index b0de696..c4b3f2e 100644 --- a/gui/UICalculator.py +++ b/gui/UICalculator.py @@ -2,9 +2,11 @@ # Form implementation generated from reading ui file 'UICalculator.ui' # -# Created by: PyQt5 UI code generator 5.12 +# Created by: PyQt5 UI code generator 5.15.6 # -# WARNING! All changes made in this file will be lost! +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + from PyQt5 import QtCore, QtGui, QtWidgets @@ -178,8 +180,8 @@ class Ui_Form(object): item.setText(_translate("Form", "Current value")) item = self.tableWidget.horizontalHeaderItem(2) item.setText(_translate("Form", "Proposed value")) - self.pb_doocs.setText(_translate("Form", "Update DOOCS")) - self.pb_load_doocs.setText(_translate("Form", "Load from DOOCS")) + self.pb_doocs.setText(_translate("Form", "Write calibration param. to DOOCS")) + self.pb_load_doocs.setText(_translate("Form", "Load from DOOCS into pySpectrometer")) self.pb_logbook.setText(_translate("Form", "Logbook")) self.measured_title.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" @@ -194,8 +196,6 @@ class Ui_Form(object): self.tabWidgetCalculator.setTabText(self.tabWidgetCalculator.indexOf(self.tab), _translate("Form", "Calculator")) - - if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) diff --git a/gui/UICalculator.ui b/gui/UICalculator.ui index b54bdeb..688bdb6 100644 --- a/gui/UICalculator.ui +++ b/gui/UICalculator.ui @@ -236,7 +236,7 @@ <bool>false</bool> </property> <property name="text"> - <string>Update DOOCS</string> + <string>Write calibration param. to DOOCS</string> </property> </widget> </item> @@ -274,7 +274,7 @@ <item row="2" column="1"> <widget class="QPushButton" name="pb_load_doocs"> <property name="text"> - <string>Load from DOOCS</string> + <string>Load from DOOCS into pySpectrometer</string> </property> </widget> </item> -- GitLab From 3ba07e13fe48e785533b2bbc1582131334fb4ae7 Mon Sep 17 00:00:00 2001 From: Christian Grech <chrisgre23@gmail.com> Date: Fri, 1 Apr 2022 15:09:27 +0200 Subject: [PATCH 2/6] visual changes and added Eph row in table --- UICalculator.py | 8 ++ calculator.py | 78 +++++++----- gui/UICalculator.py | 192 ++++++++++++++-------------- gui/UICalculator.ui | 302 +++++++++++++++++++++++--------------------- gui/UIdaq.py | 8 ++ 5 files changed, 312 insertions(+), 276 deletions(-) create mode 100644 UICalculator.py create mode 100644 gui/UIdaq.py diff --git a/UICalculator.py b/UICalculator.py new file mode 100644 index 0000000..85b8494 --- /dev/null +++ b/UICalculator.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'UICalculator.ui' +# +# Created by: PyQt5 UI code generator 5.12 +# +# WARNING! All changes made in this file will be lost! + diff --git a/calculator.py b/calculator.py index 9cc04ee..c740041 100644 --- a/calculator.py +++ b/calculator.py @@ -197,7 +197,7 @@ class UICalculator(QWidget): self.ui.widget_calc.setLayout(self.layout) self.layout.addWidget(self.win1) self.img_corr2d = self.win1.addPlot() - self.img_corr2d.setLabel('left', "E_ph", units='eV') + self.img_corr2d.setLabel('left', "E_HIREX", units='eV') self.img_corr2d.setLabel('bottom', "Pitch angle", units='°') self.img_corr2d.getAxis('left').enableAutoSIPrefix( enable=False) # stop the auto unit scaling on y axes @@ -489,32 +489,12 @@ class UICalculator(QWidget): pixel_calib_list.append(self.scale_yaxis*pixel_cal) self.pixel_calibration_mean = np.mean(pixel_calib_list) - def hkl_roll_separator(self): - for gid_item, roll, cent_x in zip(self.df_detected['gid'], self.df_detected['roll_angle'], self.df_detected['centroid_pa']): - num = [int(s) for s in re.findall(r'-?\d+', str(gid_item))] - self.h_list.append(num[0]) - self.k_list.append(num[1]) - self.l_list.append(num[2]) - self.roll_list.append(roll) - self.centroid_list.append(cent_x-self.DTHP) - - def offset_calc_and_plot(self): - self.roll_list_fun = [self.set_roll_angle] - self.phen, self.pa, gid_list, _roll_list, self.color_list, self.linestyle_list = HXRSS_Bragg_max_generator( - self.pa_range_plot, self.hmax, self.kmax, self.lmax, self.DTHP, self.dthy, self.roll_list_fun, self.DTHR, self.alpha) - - # Get energy value at one particular pitch angle value, in order to calculate offset - pa_dE, phen_Actual, gid_list_s, model_slope_list = HXRSSsingle( - (self.h_list, self.k_list, self.l_list, self.roll_list, self.centroid_list), self.DTHP, self.dthy, self.DTHR, self.alpha) - - df_model = pd.DataFrame( - dict(E_model=phen_Actual, gid=gid_list_s, centroid_pa=pa_dE, mdl_slope=model_slope_list)) - # Merge model phen values with detected lines phen - self.df_detected = self.df_detected.merge( - df_model, on=['gid', 'centroid_pa'], how='left') + def energy_off_cal(self): # Subtract model energy and measured energy to get offset dE self.df_detected['dE'] = self.df_detected['E_model'] - \ self.df_detected['centroid_phen'] + print(self.df_detected['E_model'], self.df_detected['centroid_phen']) + self.actual_E_mean = np.mean(self.df_detected['E_model']) # Remove any dE values outside the following range btwn = self.df_detected['dE'].between(-290, 290, inclusive=False) self.df_detected = self.df_detected[btwn] @@ -522,14 +502,11 @@ class UICalculator(QWidget): for E, id in zip(self.df_detected['dE'], self.df_detected['gid']): if abs(E) > 300: self.ind = 'error' - self.add_table_row(id + ' Eoff', '-', str(np.round(E, 1))+' eV') - print(gid_list_s) + self.add_table_row( + id + ' Eoff', '-', str(np.round(E, 1))+' eV') self.dE_mean = np.mean(self.df_detected['dE']) - # Calculate pixel calibration - self.dispersion_cal() - # Calculate mean energy offset and pixel calibration - # Remove NaN values + def calculate_means(self): if np.isnan(self.dE_mean) is True: self.dE_mean = 0 if np.isnan(self.pixel_calibration_mean) is True: @@ -549,16 +526,49 @@ class UICalculator(QWidget): self.add_table_row( 'Avg. Eoff', '-', str(np.round(self.dE_mean, 1))+' eV') self.ind = 'record' # Make sure to list Eo in blue as it will be recorded - self.add_table_row('Eo', str(np.round(self.parent.ui.sb_E0.value( - ), 0)) + ' eV', str(np.round((self.parent.ui.sb_E0.value()+self.dE_mean), 0))+' eV') + self.add_table_row('HIREX Eo', str(np.round(self.parent.ui.sb_E0.value(), 0)) + ' eV', str( + np.round((self.parent.ui.sb_E0.value()+self.dE_mean), 0))+' eV') + #self.add_table_row('Actual E_ph', str( + # np.round(self.actual_E_mean, 0))+' eV', '') + for oldE, E, pa, id in zip(self.df_detected['centroid_phen'], self.df_detected['E_model'], self.df_detected['centroid_pa'], self.df_detected['gid']): + self.add_table_row( + ' Eph at ' + str(round(pa, 2)), str(np.round(oldE, 0))+' eV', str(np.round(E, 0))+' eV') self.add_table_row(' ', ' ', ' ') + + def hkl_roll_separator(self): + for gid_item, roll, cent_x in zip(self.df_detected['gid'], self.df_detected['roll_angle'], self.df_detected['centroid_pa']): + num = [int(s) for s in re.findall(r'-?\d+', str(gid_item))] + self.h_list.append(num[0]) + self.k_list.append(num[1]) + self.l_list.append(num[2]) + self.roll_list.append(roll) + self.centroid_list.append(cent_x-self.DTHP) + + def offset_calc_and_plot(self): + self.roll_list_fun = [self.set_roll_angle] + self.phen, self.pa, gid_list, _roll_list, self.color_list, self.linestyle_list = HXRSS_Bragg_max_generator( + self.pa_range_plot, self.hmax, self.kmax, self.lmax, self.DTHP, self.dthy, self.roll_list_fun, self.DTHR, self.alpha) + + # Get energy value at one particular pitch angle value, in order to calculate offset + pa_dE, phen_Actual, gid_list_s, model_slope_list = HXRSSsingle( + (self.h_list, self.k_list, self.l_list, self.roll_list, self.centroid_list), self.DTHP, self.dthy, self.DTHR, self.alpha) + + self.df_model = pd.DataFrame( + dict(E_model=phen_Actual, gid=gid_list_s, centroid_pa=pa_dE, mdl_slope=model_slope_list)) + # Merge model phen values with detected lines phen + self.df_detected = self.df_detected.merge( + self.df_model, on=['gid', 'centroid_pa'], how='left') + self.energy_off_cal() + # Calculate pixel calibration + self.dispersion_cal() + # Calculate mean energy offset and pixel calibration + self.calculate_means() + # Remove NaN values self.allow_data_storage = 1 # File will be created with all parameters calculated # Enable logbook button self.ui.pb_logbook.setEnabled(True) self.ui.pb_doocs.setEnabled(True) - # In case no match is found, plot the model in this area. - def nomatch_plot(self): self.roll_list = [self.set_roll_angle] self.phen, self.pa, self.gid_list, _roll_list, self.color_list, self.linestyle_list = HXRSS_Bragg_max_generator( diff --git a/gui/UICalculator.py b/gui/UICalculator.py index c4b3f2e..12b8804 100644 --- a/gui/UICalculator.py +++ b/gui/UICalculator.py @@ -2,11 +2,9 @@ # Form implementation generated from reading ui file 'UICalculator.ui' # -# Created by: PyQt5 UI code generator 5.15.6 +# Created by: PyQt5 UI code generator 5.12 # -# WARNING: Any manual changes made to this file will be lost when pyuic5 is -# run again. Do not edit this file unless you know what you are doing. - +# WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets @@ -14,7 +12,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") - Form.resize(1296, 640) + Form.resize(1500, 640) Form.setMinimumSize(QtCore.QSize(0, 0)) Form.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) Form.setStyleSheet("background-color: white") @@ -28,56 +26,36 @@ class Ui_Form(object): self.gridLayout_7.setContentsMargins(10, 10, 10, 10) self.gridLayout_7.setSpacing(6) self.gridLayout_7.setObjectName("gridLayout_7") - self.groupBox_5 = QtWidgets.QGroupBox(self.tab) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.groupBox_5.sizePolicy().hasHeightForWidth()) - self.groupBox_5.setSizePolicy(sizePolicy) - self.groupBox_5.setObjectName("groupBox_5") - self.gridLayout_10 = QtWidgets.QGridLayout(self.groupBox_5) - self.gridLayout_10.setContentsMargins(5, 5, 5, 5) - self.gridLayout_10.setSpacing(6) - self.gridLayout_10.setObjectName("gridLayout_10") - self.label = QtWidgets.QLabel(self.groupBox_5) - self.label.setObjectName("label") - self.gridLayout_10.addWidget(self.label, 0, 0, 1, 1) - self.label_3 = QtWidgets.QLabel(self.groupBox_5) - self.label_3.setObjectName("label_3") - self.gridLayout_10.addWidget(self.label_3, 3, 0, 1, 1) - self.roll_angle = QtWidgets.QDoubleSpinBox(self.groupBox_5) - self.roll_angle.setObjectName("roll_angle") - self.gridLayout_10.addWidget(self.roll_angle, 3, 1, 1, 2) - self.pb_start_calc = QtWidgets.QPushButton(self.groupBox_5) - self.pb_start_calc.setMinimumSize(QtCore.QSize(200, 60)) - self.pb_start_calc.setMaximumSize(QtCore.QSize(1000, 1000)) - font = QtGui.QFont() - font.setPointSize(14) - font.setBold(True) - font.setWeight(75) - self.pb_start_calc.setFont(font) - self.pb_start_calc.setStyleSheet("color: rgb(85, 255, 127);") - self.pb_start_calc.setObjectName("pb_start_calc") - self.gridLayout_10.addWidget(self.pb_start_calc, 4, 4, 1, 1) - self.file_name = QtWidgets.QLineEdit(self.groupBox_5) - self.file_name.setObjectName("file_name") - self.gridLayout_10.addWidget(self.file_name, 0, 1, 1, 3) - self.browse_button = QtWidgets.QPushButton(self.groupBox_5) - self.browse_button.setObjectName("browse_button") - self.gridLayout_10.addWidget(self.browse_button, 0, 4, 1, 1) - spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) - self.gridLayout_10.addItem(spacerItem, 4, 3, 1, 1) - self.status = QtWidgets.QLabel(self.groupBox_5) - self.status.setText("") - self.status.setObjectName("status") - self.gridLayout_10.addWidget(self.status, 4, 0, 1, 3) - self.gridLayout_7.addWidget(self.groupBox_5, 2, 0, 2, 3) self.groupBox_2 = QtWidgets.QGroupBox(self.tab) self.groupBox_2.setObjectName("groupBox_2") self.gridLayout = QtWidgets.QGridLayout(self.groupBox_2) self.gridLayout.setObjectName("gridLayout") + self.pb_doocs = QtWidgets.QPushButton(self.groupBox_2) + self.pb_doocs.setEnabled(False) + self.pb_doocs.setObjectName("pb_doocs") + self.gridLayout.addWidget(self.pb_doocs, 3, 1, 1, 1) + self.pb_load_doocs = QtWidgets.QPushButton(self.groupBox_2) + self.pb_load_doocs.setObjectName("pb_load_doocs") + self.gridLayout.addWidget(self.pb_load_doocs, 4, 1, 1, 1) + self.pb_logbook = QtWidgets.QPushButton(self.groupBox_2) + self.pb_logbook.setEnabled(False) + self.pb_logbook.setObjectName("pb_logbook") + self.gridLayout.addWidget(self.pb_logbook, 2, 1, 1, 1) + self.output = QtWidgets.QLabel(self.groupBox_2) + self.output.setMinimumSize(QtCore.QSize(200, 20)) + self.output.setMaximumSize(QtCore.QSize(300, 16777215)) + font = QtGui.QFont() + font.setBold(False) + font.setWeight(50) + self.output.setFont(font) + self.output.setText("") + self.output.setScaledContents(True) + self.output.setWordWrap(True) + self.output.setObjectName("output") + self.gridLayout.addWidget(self.output, 0, 0, 2, 2) self.tableWidget = QtWidgets.QTableWidget(self.groupBox_2) self.tableWidget.setMaximumSize(QtCore.QSize(16777215, 16777215)) + self.tableWidget.setWordWrap(True) self.tableWidget.setObjectName("tableWidget") self.tableWidget.setColumnCount(3) self.tableWidget.setRowCount(0) @@ -107,31 +85,60 @@ class Ui_Form(object): self.tableWidget.horizontalHeader().setSortIndicatorShown(True) self.tableWidget.horizontalHeader().setStretchLastSection(True) self.tableWidget.verticalHeader().setSortIndicatorShown(True) - self.gridLayout.addWidget(self.tableWidget, 0, 2, 2, 1) - self.pb_doocs = QtWidgets.QPushButton(self.groupBox_2) - self.pb_doocs.setEnabled(False) - self.pb_doocs.setObjectName("pb_doocs") - self.gridLayout.addWidget(self.pb_doocs, 1, 1, 1, 1) - self.output = QtWidgets.QLabel(self.groupBox_2) - self.output.setMinimumSize(QtCore.QSize(200, 20)) - self.output.setMaximumSize(QtCore.QSize(300, 16777215)) + self.gridLayout.addWidget(self.tableWidget, 0, 2, 5, 1) + self.gridLayout_7.addWidget(self.groupBox_2, 2, 2, 2, 4) + self.groupBox_5 = QtWidgets.QGroupBox(self.tab) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.groupBox_5.sizePolicy().hasHeightForWidth()) + self.groupBox_5.setSizePolicy(sizePolicy) + self.groupBox_5.setMaximumSize(QtCore.QSize(600, 16777215)) + self.groupBox_5.setObjectName("groupBox_5") + self.gridLayout_10 = QtWidgets.QGridLayout(self.groupBox_5) + self.gridLayout_10.setContentsMargins(5, 5, 5, 5) + self.gridLayout_10.setSpacing(6) + self.gridLayout_10.setObjectName("gridLayout_10") + self.pb_start_calc = QtWidgets.QPushButton(self.groupBox_5) + self.pb_start_calc.setMinimumSize(QtCore.QSize(200, 60)) + self.pb_start_calc.setMaximumSize(QtCore.QSize(1000, 1000)) font = QtGui.QFont() - font.setBold(False) - font.setWeight(50) - self.output.setFont(font) - self.output.setText("") - self.output.setScaledContents(True) - self.output.setWordWrap(True) - self.output.setObjectName("output") - self.gridLayout.addWidget(self.output, 0, 0, 1, 2) - self.pb_load_doocs = QtWidgets.QPushButton(self.groupBox_2) - self.pb_load_doocs.setObjectName("pb_load_doocs") - self.gridLayout.addWidget(self.pb_load_doocs, 2, 1, 1, 1) - self.pb_logbook = QtWidgets.QPushButton(self.groupBox_2) - self.pb_logbook.setEnabled(False) - self.pb_logbook.setObjectName("pb_logbook") - self.gridLayout.addWidget(self.pb_logbook, 1, 0, 2, 1) - self.gridLayout_7.addWidget(self.groupBox_2, 2, 3, 2, 3) + font.setPointSize(14) + font.setBold(True) + font.setWeight(75) + self.pb_start_calc.setFont(font) + self.pb_start_calc.setStyleSheet("color: rgb(85, 255, 127);") + self.pb_start_calc.setObjectName("pb_start_calc") + self.gridLayout_10.addWidget(self.pb_start_calc, 4, 4, 1, 1) + self.label_3 = QtWidgets.QLabel(self.groupBox_5) + self.label_3.setObjectName("label_3") + self.gridLayout_10.addWidget(self.label_3, 3, 0, 1, 1) + self.browse_button = QtWidgets.QPushButton(self.groupBox_5) + self.browse_button.setObjectName("browse_button") + self.gridLayout_10.addWidget(self.browse_button, 0, 4, 1, 1) + self.label = QtWidgets.QLabel(self.groupBox_5) + self.label.setObjectName("label") + self.gridLayout_10.addWidget(self.label, 0, 0, 1, 1) + self.roll_angle = QtWidgets.QDoubleSpinBox(self.groupBox_5) + self.roll_angle.setObjectName("roll_angle") + self.gridLayout_10.addWidget(self.roll_angle, 3, 1, 1, 2) + self.file_name = QtWidgets.QLineEdit(self.groupBox_5) + self.file_name.setObjectName("file_name") + self.gridLayout_10.addWidget(self.file_name, 0, 1, 1, 2) + self.status = QtWidgets.QLabel(self.groupBox_5) + self.status.setText("") + self.status.setObjectName("status") + self.gridLayout_10.addWidget(self.status, 4, 0, 1, 2) + self.gridLayout_7.addWidget(self.groupBox_5, 2, 0, 2, 1) + self.model_title = QtWidgets.QTextEdit(self.tab) + self.model_title.setMaximumSize(QtCore.QSize(2000, 40)) + self.model_title.setObjectName("model_title") + self.gridLayout_7.addWidget(self.model_title, 0, 3, 1, 1) + self.measured_title = QtWidgets.QTextEdit(self.tab) + self.measured_title.setMinimumSize(QtCore.QSize(0, 0)) + self.measured_title.setMaximumSize(QtCore.QSize(600, 40)) + self.measured_title.setObjectName("measured_title") + self.gridLayout_7.addWidget(self.measured_title, 0, 0, 1, 1) self.widget_calc_2 = QtWidgets.QWidget(self.tab) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) @@ -140,7 +147,7 @@ class Ui_Form(object): self.widget_calc_2.setSizePolicy(sizePolicy) self.widget_calc_2.setMinimumSize(QtCore.QSize(300, 200)) self.widget_calc_2.setObjectName("widget_calc_2") - self.gridLayout_7.addWidget(self.widget_calc_2, 1, 3, 1, 3) + self.gridLayout_7.addWidget(self.widget_calc_2, 1, 2, 1, 4) self.widget_calc = QtWidgets.QWidget(self.tab) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) @@ -148,16 +155,9 @@ class Ui_Form(object): sizePolicy.setHeightForWidth(self.widget_calc.sizePolicy().hasHeightForWidth()) self.widget_calc.setSizePolicy(sizePolicy) self.widget_calc.setMinimumSize(QtCore.QSize(300, 200)) + self.widget_calc.setMaximumSize(QtCore.QSize(600, 16777215)) self.widget_calc.setObjectName("widget_calc") - self.gridLayout_7.addWidget(self.widget_calc, 1, 0, 1, 3) - self.measured_title = QtWidgets.QTextEdit(self.tab) - self.measured_title.setMaximumSize(QtCore.QSize(16777215, 40)) - self.measured_title.setObjectName("measured_title") - self.gridLayout_7.addWidget(self.measured_title, 0, 0, 1, 1) - self.model_title = QtWidgets.QTextEdit(self.tab) - self.model_title.setMaximumSize(QtCore.QSize(608, 40)) - self.model_title.setObjectName("model_title") - self.gridLayout_7.addWidget(self.model_title, 0, 3, 1, 1) + self.gridLayout_7.addWidget(self.widget_calc, 1, 0, 1, 1) self.tabWidgetCalculator.addTab(self.tab, "") self.gridLayout_2.addWidget(self.tabWidgetCalculator, 1, 0, 1, 1) @@ -168,34 +168,36 @@ class Ui_Form(object): def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Self Seeding tools")) - self.groupBox_5.setTitle(_translate("Form", "Calculate from file")) - self.label.setText(_translate("Form", "File name:")) - self.label_3.setText(_translate("Form", "Roll angle:")) - self.pb_start_calc.setText(_translate("Form", "Calculate from npz file")) - self.browse_button.setText(_translate("Form", "Browse")) self.groupBox_2.setTitle(_translate("Form", "Logs")) + self.pb_doocs.setText(_translate("Form", "Write calibration param. to DOOCS")) + self.pb_load_doocs.setText(_translate("Form", "Load from DOOCS into pySpectrometer")) + self.pb_logbook.setText(_translate("Form", "Logbook")) item = self.tableWidget.horizontalHeaderItem(0) item.setText(_translate("Form", "Parameter")) item = self.tableWidget.horizontalHeaderItem(1) item.setText(_translate("Form", "Current value")) item = self.tableWidget.horizontalHeaderItem(2) item.setText(_translate("Form", "Proposed value")) - self.pb_doocs.setText(_translate("Form", "Write calibration param. to DOOCS")) - self.pb_load_doocs.setText(_translate("Form", "Load from DOOCS into pySpectrometer")) - self.pb_logbook.setText(_translate("Form", "Logbook")) - self.measured_title.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" + self.groupBox_5.setTitle(_translate("Form", "Calculate from file")) + self.pb_start_calc.setText(_translate("Form", "Calculate from npz file")) + self.label_3.setText(_translate("Form", "Roll angle:")) + self.browse_button.setText(_translate("Form", "Browse")) + self.label.setText(_translate("Form", "File name:")) + self.model_title.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'.AppleSystemUIFont\'; font-size:13pt; font-weight:400; font-style:normal;\">\n" -"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:18pt; font-weight:600;\">Measurement</span></p></body></html>")) - self.model_title.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" +"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:18pt; font-weight:600;\">Model</span></p></body></html>")) + self.measured_title.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'.AppleSystemUIFont\'; font-size:13pt; font-weight:400; font-style:normal;\">\n" -"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:18pt; font-weight:600;\">Model</span></p></body></html>")) +"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:18pt; font-weight:600;\">Measurement</span></p></body></html>")) self.tabWidgetCalculator.setTabText(self.tabWidgetCalculator.indexOf(self.tab), _translate("Form", "Calculator")) + + if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) diff --git a/gui/UICalculator.ui b/gui/UICalculator.ui index 688bdb6..2a16322 100644 --- a/gui/UICalculator.ui +++ b/gui/UICalculator.ui @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>1296</width> + <width>1500</width> <height>640</height> </rect> </property> @@ -51,119 +51,71 @@ <property name="spacing"> <number>6</number> </property> - <item row="2" column="0" rowspan="2" colspan="3"> - <widget class="QGroupBox" name="groupBox_5"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> + <item row="2" column="2" rowspan="2" colspan="4"> + <widget class="QGroupBox" name="groupBox_2"> <property name="title"> - <string>Calculate from file</string> + <string>Logs</string> </property> - <layout class="QGridLayout" name="gridLayout_10"> - <property name="leftMargin"> - <number>5</number> - </property> - <property name="topMargin"> - <number>5</number> - </property> - <property name="rightMargin"> - <number>5</number> - </property> - <property name="bottomMargin"> - <number>5</number> - </property> - <property name="spacing"> - <number>6</number> - </property> - <item row="0" column="0"> - <widget class="QLabel" name="label"> + <layout class="QGridLayout" name="gridLayout"> + <item row="3" column="1"> + <widget class="QPushButton" name="pb_doocs"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> - <string>File name:</string> + <string>Write calibration param. to DOOCS</string> </property> </widget> </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_3"> + <item row="4" column="1"> + <widget class="QPushButton" name="pb_load_doocs"> <property name="text"> - <string>Roll angle:</string> + <string>Load from DOOCS into pySpectrometer</string> </property> </widget> </item> - <item row="3" column="1" colspan="2"> - <widget class="QDoubleSpinBox" name="roll_angle"/> + <item row="2" column="1"> + <widget class="QPushButton" name="pb_logbook"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Logbook</string> + </property> + </widget> </item> - <item row="4" column="4"> - <widget class="QPushButton" name="pb_start_calc"> + <item row="0" column="0" rowspan="2" colspan="2"> + <widget class="QLabel" name="output"> <property name="minimumSize"> <size> <width>200</width> - <height>60</height> + <height>20</height> </size> </property> <property name="maximumSize"> <size> - <width>1000</width> - <height>1000</height> + <width>300</width> + <height>16777215</height> </size> </property> <property name="font"> <font> - <pointsize>14</pointsize> - <weight>75</weight> - <bold>true</bold> + <weight>50</weight> + <bold>false</bold> </font> </property> - <property name="styleSheet"> - <string notr="true">color: rgb(85, 255, 127);</string> - </property> <property name="text"> - <string>Calculate from npz file</string> - </property> - </widget> - </item> - <item row="0" column="1" colspan="3"> - <widget class="QLineEdit" name="file_name"/> - </item> - <item row="0" column="4"> - <widget class="QPushButton" name="browse_button"> - <property name="text"> - <string>Browse</string> - </property> - </widget> - </item> - <item row="4" column="3"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> + <string/> </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> + <property name="scaledContents"> + <bool>true</bool> </property> - </spacer> - </item> - <item row="4" column="0" colspan="3"> - <widget class="QLabel" name="status"> - <property name="text"> - <string/> + <property name="wordWrap"> + <bool>true</bool> </property> </widget> </item> - </layout> - </widget> - </item> - <item row="2" column="3" rowspan="2" colspan="3"> - <widget class="QGroupBox" name="groupBox_2"> - <property name="title"> - <string>Logs</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="2" rowspan="2"> + <item row="0" column="2" rowspan="5"> <widget class="QTableWidget" name="tableWidget"> <property name="maximumSize"> <size> @@ -171,6 +123,9 @@ <height>16777215</height> </size> </property> + <property name="wordWrap"> + <bool>true</bool> + </property> <attribute name="horizontalHeaderCascadingSectionResizes"> <bool>false</bool> </attribute> @@ -230,68 +185,149 @@ </column> </widget> </item> - <item row="1" column="1"> - <widget class="QPushButton" name="pb_doocs"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Write calibration param. to DOOCS</string> - </property> - </widget> - </item> - <item row="0" column="0" colspan="2"> - <widget class="QLabel" name="output"> + </layout> + </widget> + </item> + <item row="2" column="0" rowspan="2"> + <widget class="QGroupBox" name="groupBox_5"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>600</width> + <height>16777215</height> + </size> + </property> + <property name="title"> + <string>Calculate from file</string> + </property> + <layout class="QGridLayout" name="gridLayout_10"> + <property name="leftMargin"> + <number>5</number> + </property> + <property name="topMargin"> + <number>5</number> + </property> + <property name="rightMargin"> + <number>5</number> + </property> + <property name="bottomMargin"> + <number>5</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <item row="4" column="4"> + <widget class="QPushButton" name="pb_start_calc"> <property name="minimumSize"> <size> <width>200</width> - <height>20</height> + <height>60</height> </size> </property> <property name="maximumSize"> <size> - <width>300</width> - <height>16777215</height> + <width>1000</width> + <height>1000</height> </size> </property> <property name="font"> <font> - <weight>50</weight> - <bold>false</bold> + <pointsize>14</pointsize> + <weight>75</weight> + <bold>true</bold> </font> </property> - <property name="text"> - <string/> + <property name="styleSheet"> + <string notr="true">color: rgb(85, 255, 127);</string> </property> - <property name="scaledContents"> - <bool>true</bool> + <property name="text"> + <string>Calculate from npz file</string> </property> - <property name="wordWrap"> - <bool>true</bool> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Roll angle:</string> </property> </widget> </item> - <item row="2" column="1"> - <widget class="QPushButton" name="pb_load_doocs"> + <item row="0" column="4"> + <widget class="QPushButton" name="browse_button"> <property name="text"> - <string>Load from DOOCS into pySpectrometer</string> + <string>Browse</string> </property> </widget> </item> - <item row="1" column="0" rowspan="2"> - <widget class="QPushButton" name="pb_logbook"> - <property name="enabled"> - <bool>false</bool> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>File name:</string> </property> + </widget> + </item> + <item row="3" column="1" colspan="2"> + <widget class="QDoubleSpinBox" name="roll_angle"/> + </item> + <item row="0" column="1" colspan="2"> + <widget class="QLineEdit" name="file_name"/> + </item> + <item row="4" column="0" colspan="2"> + <widget class="QLabel" name="status"> <property name="text"> - <string>Logbook</string> + <string/> </property> </widget> </item> </layout> </widget> </item> - <item row="1" column="3" colspan="3"> + <item row="0" column="3"> + <widget class="QTextEdit" name="model_title"> + <property name="maximumSize"> + <size> + <width>2000</width> + <height>40</height> + </size> + </property> + <property name="html"> + <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;"> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:18pt; font-weight:600;">Model</span></p></body></html></string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QTextEdit" name="measured_title"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>600</width> + <height>40</height> + </size> + </property> + <property name="html"> + <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;"> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:18pt; font-weight:600;">Measurement</span></p></body></html></string> + </property> + </widget> + </item> + <item row="1" column="2" colspan="4"> <widget class="QWidget" name="widget_calc_2" native="true"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> @@ -307,7 +343,7 @@ </property> </widget> </item> - <item row="1" column="0" colspan="3"> + <item row="1" column="0"> <widget class="QWidget" name="widget_calc" native="true"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> @@ -321,40 +357,12 @@ <height>200</height> </size> </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QTextEdit" name="measured_title"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>40</height> - </size> - </property> - <property name="html"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;"> -<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:18pt; font-weight:600;">Measurement</span></p></body></html></string> - </property> - </widget> - </item> - <item row="0" column="3"> - <widget class="QTextEdit" name="model_title"> <property name="maximumSize"> <size> - <width>608</width> - <height>40</height> + <width>600</width> + <height>16777215</height> </size> </property> - <property name="html"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;"> -<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:18pt; font-weight:600;">Model</span></p></body></html></string> - </property> </widget> </item> </layout> diff --git a/gui/UIdaq.py b/gui/UIdaq.py new file mode 100644 index 0000000..2faeb78 --- /dev/null +++ b/gui/UIdaq.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'UIdaq.ui' +# +# Created by: PyQt5 UI code generator 5.12 +# +# WARNING! All changes made in this file will be lost! + -- GitLab From 77d1cc784880936abd060ab493ad411623865f3f Mon Sep 17 00:00:00 2001 From: Christian Grech <chrisgre23@gmail.com> Date: Fri, 1 Apr 2022 15:42:16 +0200 Subject: [PATCH 3/6] Update calculator.py --- calculator.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/calculator.py b/calculator.py index c740041..f58e59b 100644 --- a/calculator.py +++ b/calculator.py @@ -18,7 +18,7 @@ from matplotlib import cm import pandas as pd from scipy import ndimage from datetime import datetime, timedelta -#from skimage.filters import threshold_yen +from skimage.filters import threshold_yen #from sklearn.model_selection import cross_val_score from sklearn.neighbors import NearestNeighbors, KNeighborsClassifier #from sklearn.ensemble import GradientBoostingClassifier, AdaBoostClassifier, RandomForestClassifier, VotingClassifier @@ -307,20 +307,20 @@ class UICalculator(QWidget): self.min_pangle = min(self.np_doocs) self.max_pangle = max(self.np_doocs) self.corr2d[self.corr2d < 0] = 0 - #self.image = self.corr2d.T - #thresh = threshold_yen(self.image, nbins=256) - #binary = self.image > thresh - #self.processed_image = binary + self.image = self.corr2d.T + thresh = threshold_yen(self.image, nbins=256) + binary = self.image > thresh + self.processed_image = binary #### ALTERNATE MANUAL THRESHOLDING - range_scale = np.ptp(self.corr2d) - threshold = 0.16 * range_scale - max_value = np.amax(self.corr2d) - min_value = np.amin(self.corr2d) + #range_scale = np.ptp(self.corr2d) + #threshold = 0.16 * range_scale + #max_value = np.amax(self.corr2d) + #min_value = np.amin(self.corr2d) # all values above threshold are set to max_value - self.corr2d[self.corr2d > threshold] = max_value + #self.corr2d[self.corr2d > threshold] = max_value # all values above threshold are set to min_value - self.corr2d[self.corr2d < threshold] = min_value - self.processed_image = self.corr2d.T + #self.corr2d[self.corr2d < threshold] = min_value + #self.processed_image = self.corr2d.T def get_binarized_line(self): df = pd.DataFrame(data=self.processed_image.T) -- GitLab From 49b61007ffd05897d76350f89d741bef49cb365d Mon Sep 17 00:00:00 2001 From: Christian Grech <chrisgre23@gmail.com> Date: Mon, 2 May 2022 12:44:31 +0200 Subject: [PATCH 4/6] changed pitch axis convention --- .gitignore | 1 + model_functions/HXRSS_Bragg_max_generator.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0bf7d76..b54a748 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ model_functions/archive.txt hirexold.py calculator_local.py hirex_local.py +*.ipynb diff --git a/model_functions/HXRSS_Bragg_max_generator.py b/model_functions/HXRSS_Bragg_max_generator.py index ea72274..392908e 100644 --- a/model_functions/HXRSS_Bragg_max_generator.py +++ b/model_functions/HXRSS_Bragg_max_generator.py @@ -138,7 +138,9 @@ def HXRSS_Bragg_max_generator(thplist, h_max, k_max, l_max, dthp, dthy, roll_ang #User defined quantities ################ AMERICAN NAME CONVENTION --- OUR ROLL IS YAW HERE AND VICEVERSA!!!###################### - pitchax = np.array((-1, 1, 0))/np.linalg.norm(np.array((-1, 1, 0))) + #pitchax = np.array((-1, 1, 0))/np.linalg.norm(np.array((-1, 1, 0))) Changed convention + pitchax = np.array((1, -1, 0))/np.linalg.norm(np.array((1, -1, 0))) + rollax = np.array((0, 0, 1))/np.linalg.norm(np.array((0, 0, 1))) yawax = np.array((1, 1, 0))/np.linalg.norm(np.array((1, 1, 0))) n0 = -rollax # direction of incident radiation -- GitLab From 05eec7db330a28585e20e1495e3868a40b9099fd Mon Sep 17 00:00:00 2001 From: Christian Grech <chrisgre23@gmail.com> Date: Fri, 20 May 2022 09:23:34 +0200 Subject: [PATCH 5/6] Update calculator.py --- calculator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/calculator.py b/calculator.py index f58e59b..7864448 100644 --- a/calculator.py +++ b/calculator.py @@ -97,7 +97,7 @@ class UICalculator(QWidget): self.ui.pb_doocs.clicked.connect(self.check_if_scan_is_recent) self.ui.pb_load_doocs.clicked.connect(self.load_from_doocs) # Set constants - self.hmax, self.kmax, self.lmax = 5, 5, 5 + self.hmax, self.kmax, self.lmax = 6, 6, 7 self.d_kernel, self.e_kernel = 2, 2 # Set up and show the two graph axes and display latest npz file self.add_image_widget() @@ -274,7 +274,7 @@ class UICalculator(QWidget): pen = pg.mkPen(str(self.color_list[r]), width=3, style=style_type) self.model = pg.PlotCurveItem( x=self.pa[r], y=self.phen[r], pen=pen, name=self.gid_list[r]) - if self.phen[r][100] <= max(self.np_phen)+700 and self.phen[r][100] >= min(self.np_phen)-700: + if self.phen[r][50] <= max(self.np_phen)+1500 and self.phen[r][50] >= min(self.np_phen)-1500: self.plot1.addItem(self.model) self.plot1.setXRange(min(self.np_doocs), max(self.np_doocs), padding=None, update=True) @@ -412,15 +412,15 @@ class UICalculator(QWidget): self.DTHP = -0.392 self.dthy = 1.17 self.DTHR = 0.1675 - self.alpha = 0.00238 + self.alpha = 0.00338 else: self.DTHP = -0.392 self.dthy = 1.17 self.DTHR = 0.1675 - self.alpha = 0.00238 - self.pa_range = np.linspace(self.min_pangle-1, self.max_pangle+1, 200) + self.alpha = 0.00338 + self.pa_range = np.linspace(self.min_pangle-1, self.max_pangle+1, 100) self.pa_range_plot = np.linspace( - self.min_pangle-1, self.max_pangle+1, 200) + self.min_pangle-1, self.max_pangle+1, 100) # pass pitch and roll errors and create Bragg curves self.phen_list, self.p_angle_list, self.gid_list, self.roll_angle_list, color_list, linestyle_list = HXRSS_Bragg_max_generator( self.pa_range, self.hmax, self.kmax, self.lmax, self.DTHP, self.dthy, self.roll, self.DTHR, self.alpha) -- GitLab From d612d0dec2fe269240cd4d1e111761c35a9f20e8 Mon Sep 17 00:00:00 2001 From: Christian Grech <chrisgre23@gmail.com> Date: Wed, 25 May 2022 06:35:23 +0200 Subject: [PATCH 6/6] updated model convention --- calculator.py | 10 +++++++--- model_functions/HXRSS_Bragg_single.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/calculator.py b/calculator.py index 7864448..ced6cf6 100644 --- a/calculator.py +++ b/calculator.py @@ -519,8 +519,8 @@ class UICalculator(QWidget): self.add_table_row( 'Avg. ev/px', '-', str(np.round(self.pixel_calibration_mean, 3))) self.add_plot() - self.plot1.setYRange(min(self.np_phen)+self.dE_mean, - max(self.np_phen)+self.dE_mean, padding=None, update=True) + self.plot1.setYRange(min(self.np_phen)-100, + max(self.np_phen)+100, padding=None, update=True) if abs(self.dE_mean) > 300: self.ind = 'error' self.add_table_row( @@ -739,7 +739,11 @@ class UICalculator(QWidget): def load_corr2d(self): self.tt = np.load(self.pathname) self.orig_image = self.tt['corr2d'] - self.np_doocs = self.tt['doocs_scale'] + self.doocs_scale = self.tt['doocs_scale'] + if len(self.doocs_scale) != len(self.orig_image): + self.np_doocs = self.doocs_scale[:-1] + else: + self.np_doocs = self.doocs_scale self.np_phen = self.tt['phen_scale'] self.doocs_label = self.tt['doocs_channel'] self.info_mono_no() diff --git a/model_functions/HXRSS_Bragg_single.py b/model_functions/HXRSS_Bragg_single.py index 6c1e6fa..de8fbd4 100644 --- a/model_functions/HXRSS_Bragg_single.py +++ b/model_functions/HXRSS_Bragg_single.py @@ -1 +1 @@ -# -*- coding: utf-8 -*- """ Created on Mon Nov 11 14:12:59 2019 @author: ggeloni Edited to function by cgrech (Jul 6, 21) """ from sympy.utilities.iterables import multiset_permutations import sys, os import matplotlib.pyplot as plt import numpy as np import time import logging def HXRSSsingle(X, dthp, dthy, dthr, alpha): h_list, k_list, l_list, roll_angle_list, centroid_pa = X p_angle_list, phen_list, label_list, gid_list, roll_list, slope_list =[], [], [], [], [], [] def plotIR(hlm,Phene,Pitch,thy,thr): #Note: same conventions as LCLS! fig2 = plt.figure(1) plot = fig2.add_subplot(111) plot.set_title(" ") Pitch = 0 Phene = 0 hlm = [0,0,0] #annotaz = plot.annotate(" ", (0,0), (-60, 650), xycoords='axes fraction', textcoords='offset points', va='top') def rotm(th,ux,uy,uz): r = np.array(( ( ux*ux*(1-np.cos(th))+np.cos(th), ux*uy*(1-np.cos(th))-uz*np.sin(th), ux*uz*(1-np.cos(th))+uy*np.sin(th) ), ( ux*uy*(1-np.cos(th))+uz*np.sin(th), uy*uy*(1-np.cos(th))+np.cos(th), uy*uz*(1-np.cos(th))-ux*np.sin(th) ), ( ux*uz*(1-np.cos(th))-uy*np.sin(th), uy*uz*(1-np.cos(th))+ux*np.sin(th), uz*uz*(1-np.cos(th))+np.cos(th) ) )) return r #(1) Pitch of thp around PitchAx, and rotation of Yaw and Roll axis: def rotm1(thp,pitchax,rollax,yawax): r1 = rotm(np.pi/2-thp,pitchax[0],pitchax[1],pitchax[2]) rollax2 = r1.dot(rollax) yawax2 = r1.dot(yawax) return r1, rollax2, yawax2 #(2) Yaw of thy around yawax2, and rotation of Roll axis: def rotm2(thy,rollax2,yawax2): r2 = rotm(thy,yawax2[0],yawax2[1],yawax2[2]) rollax3 = r2.dot(rollax2) return r2, rollax3 #(3) Roll of thr around Rollax3: def rotm3(thr,rollax3): r3 = rotm(thr,rollax3[0],rollax3[1],rollax3[2]) return r3 def kirot(thp,thy,thr,n0, pitchax,rollax,yawax): #note: it seems like in Alberto's tool the roll and yaw are not transformed by subsequent rotations. For comparison, Ileave this out too. r1, rollax2, yawax2 = rotm1(thp,pitchax,rollax,yawax) rollax2=rollax yawax2=yawax r2, rollax3 = rotm2(thy,rollax2,yawax2) rollax3=rollax r3 = rotm3(thr,rollax3) return r3.dot(r2.dot(r1.dot(n0))) def phev(fact,n,h,k,l,a,thp,thy,thr,n0, pitchax,rollax,yawax): d=a/np.sqrt(h**2+k**2+l**2) return fact*np.sqrt(h**2+k**2+l**2)/(2*d*n*np.linalg.norm(kirot(thp,thy,thr,n0, pitchax,rollax,yawax).dot((h,k,l)))) def plotene(thplist,fact,n,h,k,l,a,DTHP,thy,thr,n0,pitchax,rollax,yawax): eevlist = phev(fact,1,h,k,l,a,thplist/180*np.pi,thy,thr,n0,pitchax,rollax,yawax) eevlist_minus = phev(fact,1,h,k,l,a,(thplist-0.1)/180*np.pi,thy,thr,n0,pitchax,rollax,yawax) slope = (eevlist-eevlist_minus)/0.1 rosso = np.array((1,1,1)) verde = np.array((2,2,0)) nero = np.array((1,1,3)) blu = np.array((4,0,0)) magenta = np.array((3,3,1)) arancio = np.array((2,2,4)) azzurro = np.array((3,3,3)) giallo = np.array((1,1,5)) viola = np.array((1,3,5)) marrone = np.array((5,5,5)) porpora = np.array((1,5,5)) grigio = np.array((3,5,5)) oro = np.array((3,5,5)) beige = np.array((3,3,5)) aquamarine = np.array((4,4,4)) wheat = np.array((4,4,0)) if [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(rosso)): colore='red' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(verde)): colore='green' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(nero)): colore='black' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(blu)): colore='blue' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(magenta)): colore='magenta' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(arancio)): colore='orange' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(azzurro)): colore='cyan' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(giallo)): colore='yellow' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(viola)): colore='violet' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(marrone)): colore='brown' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(porpora)): colore='purple' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(grigio)): colore='grey' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(oro)): colore='gold' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(beige)): colore='beige' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(aquamarine)): colore='aquamarine' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(wheat)): colore='wheat' else : colore = 'black' simbolo ='dashed' if (h>=0 and k>=0 and l >=0) or (h<=0 and k<=0 and l<=0): simbolo = 'solid' if not(h == k): simbolo = 'dashdot' #plt.plot(thplist+DTHP,eevlist,color=colore, linestyle=simbolo,label='['+str(h)+str(k)+str(l)+']'.format([h,k,l]),gid=[h,k,l]) #plt.ylim((3000,19000)) #plt.ylabel('Photon Energy (eV)') #plt.xlabel('Pitch angle (deg) \n \n (111) red - (220) green - (1,1,3) black - (400) blue - (331) magenta - (224) orange - (333) cyan - (115) yellow - (135) violet - (555) brown - (155) purple - (355) grey - (335) beige - (444) aquamarine - (440) wheat\n STYLE: - dashdot: h != k ; solid: h=k and h,k,l all positive ; dashed: otherwise \n CONVENTION h>=0 i.e. [h,k,l] coincides with [-h,-k,-l]') gid=[h,k,l] color=colore linestyle=str(simbolo) label=str('['+str(h)+str(k)+str(l)+']'.format([h,k,l])) thplist_f=thplist+DTHP return thplist_f, eevlist, gid, slope #User defined quantities ################ AMERICAN NAME CONVENTION --- OUR ROLL IS YAW HERE AND VICEVERSA!!!###################### pitchax = np.array((-1,1,0))/np.linalg.norm(np.array((-1,1,0))) rollax = np.array((0,0,1))/np.linalg.norm(np.array((0,0,1))) yawax = np.array((1,1,0))/np.linalg.norm(np.array((1,1,0))) n0 = -rollax #direction of incident radiation a = 3.5667899884942195e-10 hbar = 1.05457173e-34 clight = 299792458.0 eel = 1.60217657e-19 fact = 2*np.pi*clight*hbar/eel nord=1 hmax=5 kmax=5 lmax=5 DTHP = dthp#-0.6921-0.09 pa_list=[] for h, k, l, roll_angle, thplist in zip(h_list, k_list, l_list, roll_angle_list, centroid_pa): #eevlist=np.zeros(len(thplist)) #DTHY=np.zeros(len(thplist)) DTHY = dthy+(alpha*thplist) #15#15#0#-0.15#-0.39#-0.15 #0.0885 DTHR = dthr thy=(-DTHY+roll_angle)/180*np.pi #######AMERICAN YAW DEFINITION thr=(-DTHR)/180*np.pi#0.0/180*np.pi #########AMERICAN ROLL DEFINITION ref = h*np.array((1,0,0))+k*np.array((0,1,0))+l*np.array((0,0,1)) p_angle, phen, gid, slope = plotene(thplist,fact,nord,h,k,l,a,DTHP,thy,thr,n0,pitchax,rollax,yawax) phen_list.append(phen) pa_list.append(p_angle) gid_list.append(str(gid)) slope_list.append(slope) #plt.show() return pa_list, phen_list, gid_list, slope_list \ No newline at end of file +# -*- coding: utf-8 -*- """ Created on Mon Nov 11 14:12:59 2019 @author: ggeloni Edited to function by cgrech (Jul 6, 21) """ from sympy.utilities.iterables import multiset_permutations import sys, os import matplotlib.pyplot as plt import numpy as np import time import logging def HXRSSsingle(X, dthp, dthy, dthr, alpha): h_list, k_list, l_list, roll_angle_list, centroid_pa = X p_angle_list, phen_list, label_list, gid_list, roll_list, slope_list =[], [], [], [], [], [] def plotIR(hlm,Phene,Pitch,thy,thr): #Note: same conventions as LCLS! fig2 = plt.figure(1) plot = fig2.add_subplot(111) plot.set_title(" ") Pitch = 0 Phene = 0 hlm = [0,0,0] #annotaz = plot.annotate(" ", (0,0), (-60, 650), xycoords='axes fraction', textcoords='offset points', va='top') def rotm(th,ux,uy,uz): r = np.array(( ( ux*ux*(1-np.cos(th))+np.cos(th), ux*uy*(1-np.cos(th))-uz*np.sin(th), ux*uz*(1-np.cos(th))+uy*np.sin(th) ), ( ux*uy*(1-np.cos(th))+uz*np.sin(th), uy*uy*(1-np.cos(th))+np.cos(th), uy*uz*(1-np.cos(th))-ux*np.sin(th) ), ( ux*uz*(1-np.cos(th))-uy*np.sin(th), uy*uz*(1-np.cos(th))+ux*np.sin(th), uz*uz*(1-np.cos(th))+np.cos(th) ) )) return r #(1) Pitch of thp around PitchAx, and rotation of Yaw and Roll axis: def rotm1(thp,pitchax,rollax,yawax): r1 = rotm(np.pi/2-thp,pitchax[0],pitchax[1],pitchax[2]) rollax2 = r1.dot(rollax) yawax2 = r1.dot(yawax) return r1, rollax2, yawax2 #(2) Yaw of thy around yawax2, and rotation of Roll axis: def rotm2(thy,rollax2,yawax2): r2 = rotm(thy,yawax2[0],yawax2[1],yawax2[2]) rollax3 = r2.dot(rollax2) return r2, rollax3 #(3) Roll of thr around Rollax3: def rotm3(thr,rollax3): r3 = rotm(thr,rollax3[0],rollax3[1],rollax3[2]) return r3 def kirot(thp,thy,thr,n0, pitchax,rollax,yawax): #note: it seems like in Alberto's tool the roll and yaw are not transformed by subsequent rotations. For comparison, Ileave this out too. r1, rollax2, yawax2 = rotm1(thp,pitchax,rollax,yawax) rollax2=rollax yawax2=yawax r2, rollax3 = rotm2(thy,rollax2,yawax2) rollax3=rollax r3 = rotm3(thr,rollax3) return r3.dot(r2.dot(r1.dot(n0))) def phev(fact,n,h,k,l,a,thp,thy,thr,n0, pitchax,rollax,yawax): d=a/np.sqrt(h**2+k**2+l**2) return fact*np.sqrt(h**2+k**2+l**2)/(2*d*n*np.linalg.norm(kirot(thp,thy,thr,n0, pitchax,rollax,yawax).dot((h,k,l)))) def plotene(thplist,fact,n,h,k,l,a,DTHP,thy,thr,n0,pitchax,rollax,yawax): eevlist = phev(fact,1,h,k,l,a,thplist/180*np.pi,thy,thr,n0,pitchax,rollax,yawax) eevlist_minus = phev(fact,1,h,k,l,a,(thplist-0.1)/180*np.pi,thy,thr,n0,pitchax,rollax,yawax) slope = (eevlist-eevlist_minus)/0.1 rosso = np.array((1,1,1)) verde = np.array((2,2,0)) nero = np.array((1,1,3)) blu = np.array((4,0,0)) magenta = np.array((3,3,1)) arancio = np.array((2,2,4)) azzurro = np.array((3,3,3)) giallo = np.array((1,1,5)) viola = np.array((1,3,5)) marrone = np.array((5,5,5)) porpora = np.array((1,5,5)) grigio = np.array((3,5,5)) oro = np.array((3,5,5)) beige = np.array((3,3,5)) aquamarine = np.array((4,4,4)) wheat = np.array((4,4,0)) if [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(rosso)): colore='red' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(verde)): colore='green' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(nero)): colore='black' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(blu)): colore='blue' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(magenta)): colore='magenta' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(arancio)): colore='orange' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(azzurro)): colore='cyan' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(giallo)): colore='yellow' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(viola)): colore='violet' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(marrone)): colore='brown' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(porpora)): colore='purple' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(grigio)): colore='grey' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(oro)): colore='gold' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(beige)): colore='beige' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(aquamarine)): colore='aquamarine' elif [np.abs(h),np.abs(k),np.abs(l)] in list(multiset_permutations(wheat)): colore='wheat' else : colore = 'black' simbolo ='dashed' if (h>=0 and k>=0 and l >=0) or (h<=0 and k<=0 and l<=0): simbolo = 'solid' if not(h == k): simbolo = 'dashdot' #plt.plot(thplist+DTHP,eevlist,color=colore, linestyle=simbolo,label='['+str(h)+str(k)+str(l)+']'.format([h,k,l]),gid=[h,k,l]) #plt.ylim((3000,19000)) #plt.ylabel('Photon Energy (eV)') #plt.xlabel('Pitch angle (deg) \n \n (111) red - (220) green - (1,1,3) black - (400) blue - (331) magenta - (224) orange - (333) cyan - (115) yellow - (135) violet - (555) brown - (155) purple - (355) grey - (335) beige - (444) aquamarine - (440) wheat\n STYLE: - dashdot: h != k ; solid: h=k and h,k,l all positive ; dashed: otherwise \n CONVENTION h>=0 i.e. [h,k,l] coincides with [-h,-k,-l]') gid=[h,k,l] color=colore linestyle=str(simbolo) label=str('['+str(h)+str(k)+str(l)+']'.format([h,k,l])) thplist_f=thplist+DTHP return thplist_f, eevlist, gid, slope #User defined quantities ################ AMERICAN NAME CONVENTION --- OUR ROLL IS YAW HERE AND VICEVERSA!!!###################### pitchax = np.array((1,-1,0))/np.linalg.norm(np.array((1,-1,0))) #pitchax = np.array((-1,1,0))/np.linalg.norm(np.array((-1,1,0))) rollax = np.array((0,0,1))/np.linalg.norm(np.array((0,0,1))) yawax = np.array((1,1,0))/np.linalg.norm(np.array((1,1,0))) n0 = -rollax #direction of incident radiation a = 3.5667899884942195e-10 hbar = 1.05457173e-34 clight = 299792458.0 eel = 1.60217657e-19 fact = 2*np.pi*clight*hbar/eel nord=1 hmax=5 kmax=5 lmax=5 DTHP = dthp#-0.6921-0.09 pa_list=[] for h, k, l, roll_angle, thplist in zip(h_list, k_list, l_list, roll_angle_list, centroid_pa): #eevlist=np.zeros(len(thplist)) #DTHY=np.zeros(len(thplist)) DTHY = dthy+(alpha*thplist) #15#15#0#-0.15#-0.39#-0.15 #0.0885 DTHR = dthr thy=(-DTHY+roll_angle)/180*np.pi #######AMERICAN YAW DEFINITION thr=(-DTHR)/180*np.pi#0.0/180*np.pi #########AMERICAN ROLL DEFINITION ref = h*np.array((1,0,0))+k*np.array((0,1,0))+l*np.array((0,0,1)) p_angle, phen, gid, slope = plotene(thplist,fact,nord,h,k,l,a,DTHP,thy,thr,n0,pitchax,rollax,yawax) phen_list.append(phen) pa_list.append(p_angle) gid_list.append(str(gid)) slope_list.append(slope) #plt.show() return pa_list, phen_list, gid_list, slope_list \ No newline at end of file -- GitLab