From 1880179ad0279f888bbe368e43ba555a83a2417e Mon Sep 17 00:00:00 2001 From: Martin Killenberg <martin.killenberg@desy.de> Date: Fri, 27 Oct 2023 15:09:07 +0200 Subject: [PATCH] feat: add analysis parameters to GUI --- Python_script/SoftwareVersion.py | 5 + Python_script/analysis.py | 16 +-- Python_script/climate-lab-gui.py | 25 ++++- Python_script/climate-lab-main.ui | 165 +++++++++++++++++++++++++++--- Python_script/prototype.py | 9 +- 5 files changed, 195 insertions(+), 25 deletions(-) create mode 100644 Python_script/SoftwareVersion.py diff --git a/Python_script/SoftwareVersion.py b/Python_script/SoftwareVersion.py new file mode 100644 index 0000000..b4d8701 --- /dev/null +++ b/Python_script/SoftwareVersion.py @@ -0,0 +1,5 @@ +import subprocess + +def software_version(): + return subprocess.check_output(['git', 'describe']).strip().decode() + diff --git a/Python_script/analysis.py b/Python_script/analysis.py index 4dffe72..0a37b67 100644 --- a/Python_script/analysis.py +++ b/Python_script/analysis.py @@ -2,6 +2,7 @@ import pandas as pd import matplotlib.pyplot as plt import numpy as np from matplotlib import gridspec +from SoftwareVersion import software_version def extract_stable_data(datafile, measurement_set, reference_signal_names, extra_signal_names): datapoint = {} @@ -38,8 +39,7 @@ def extract_stable_data(datafile, measurement_set, reference_signal_names, extra # sweep_type is either 'temperature' or 'humidity' def plot_sweep(temperatures, humidities, basename, sweep_type, measurement_sets, reference_signal_names, - analysis_config = {'type': 'rf_cable', 'normalise': [True, False], 'cable_length': 10, - 'extra_signal_names' : ['RF_FREQUENCY']}): + analysis_config): set_data = {} derivatives = {} for measurement_set in measurement_sets: @@ -84,10 +84,11 @@ def plot_sweep(temperatures, humidities, basename, sweep_type, measurement_sets, fig = plt.figure(figsize=(10, 15)) gs = gridspec.GridSpec(nrows=6, ncols=1, hspace=0)#, width_ratios=[3, 1], height_ratios=[3, 1]) - upper_text_block = '\n'.join(['DUT name: some cable', - 'SW version: FIXME']) + upper_text_block = '\n'.join(['DUT name: '+analysis_config['dut_name'], + 'SW version: '+software_version(), 'Date: '+analysis_config['time_string']]) + - fig.text(0.1, 0.9, upper_text_block) + fig.text(0.1, 0.88, upper_text_block) ax1 = fig.add_subplot(gs[1, 0]) ax2 = fig.add_subplot(gs[2, 0], sharex=ax1) @@ -198,4 +199,7 @@ def plot_sweep(temperatures, humidities, basename, sweep_type, measurement_sets, if __name__ == '__main__': print('run \'./prototype.py -t first_tempsweep.txt -p -o tempsweep1\' to get the data needed for this plot.' ) plot_sweep(np.arange(20., 31.+1.), [35.]*12, 'tempsweep1', 'temperature', - ['1.3GHz', '1.0GHz', '3.0GHz', '6.0GHz', '10.0GHz'], ['S21_PHASE', 'S21_MAGNITUDE']) + ['1.3GHz', '1.0GHz', '3.0GHz', '6.0GHz', '10.0GHz'], ['S21_PHASE', 'S21_MAGNITUDE'], + analysis_config={'type': 'rf_cable', 'normalise': [True, False], 'cable_length': 10, + 'extra_signal_names': ['RF_FREQUENCY'], 'dut_name': 'simulated cable', + 'time_string': '0:0:0'}) diff --git a/Python_script/climate-lab-gui.py b/Python_script/climate-lab-gui.py index 8027d24..6b387bc 100755 --- a/Python_script/climate-lab-gui.py +++ b/Python_script/climate-lab-gui.py @@ -54,6 +54,22 @@ class TestStandMainWindow(QMainWindow): print('changed dir') return True + def get_analysis_config(self, time_string): + analysis_config = {} + analysis_config['dut_name'] = self.dutName.text() + analysis_config['time_string'] = time_string + if self.analysisTypeCableButton.isChecked(): + analysis_config['type'] = 'rf_cable' + analysis_config['extra_signal_names'] = ['RF_FREQUENCY'] + analysis_config['normalise'] = [True, False] + analysis_config['cable_length'] = self.cableLengthSpinBox.value() + else: + analysis_config['type'] = 'default' + analysis_config['extra_signal_names'] = [] + analysis_config['normalise'] = [self.removeOffsetsSignal0.isChecked(), self.removeOffsetsSignal1.isChecked()] + + return analysis_config + def do_measurement(self): self.setEnabled(False) self.qt_app.processEvents(); @@ -65,15 +81,16 @@ class TestStandMainWindow(QMainWindow): with open('ext_sensor_channels.json', 'r') as f2: ext_sensor_channels = json.load(f2) + time_string = time.strftime("%Y_%m_%d-%H_%M_%S") if self.autoNameCheckbox.isChecked(): - output_basename = time.strftime("%Y_%m_%d-%H_%M_%S") + "_results" + output_basename = time_string + "_results" else: output_basename = self.baseName.text() if not self.check_and_change_dir(config_data['data_folder'] + '/' + output_basename): self.setEnabled(True) return - + meas = prototype.Measurements(config_data, output_basename,False, ext_sensor_channels) try: if self.tempSweepButton.isChecked(): @@ -86,7 +103,7 @@ class TestStandMainWindow(QMainWindow): temp_extensions.append(str(t) + 'deg_' + str(self.fixedParameter.value()) + 'rh') analysis.plot_sweep(temperatures, [self.fixedParameter.value()] * len(temperatures), output_basename, 'temperature', meas.dut.get_measurement_set_names(), - meas.dut.get_dut_reference_signal_names()) + meas.dut.get_dut_reference_signal_names(), self.get_analysis_config(time_string)) prototype.plot_output(output_basename, temp_extensions, True, config_data, ext_sensor_channels, meas.dut.get_measurement_set_names(), meas.dut.get_dut_reference_signal_names(), @@ -103,7 +120,7 @@ class TestStandMainWindow(QMainWindow): hum_extensions.append(str(self.fixedParameter.value()) + 'deg_' + str(h) + 'rh') analysis.plot_sweep([self.fixedParameter.value()] * len(humidities), humidities, output_basename, 'humidity', meas.dut.get_measurement_set_names(), - meas.dut.get_dut_reference_signal_names()) + meas.dut.get_dut_reference_signal_names(), self.get_analysis_config(time_string)) prototype.plot_output(output_basename, hum_extensions, True, config_data, ext_sensor_channels, meas.dut.get_measurement_set_names(), meas.dut.get_dut_reference_signal_names(), diff --git a/Python_script/climate-lab-main.ui b/Python_script/climate-lab-main.ui index 8fa5ffb..9f90c66 100644 --- a/Python_script/climate-lab-main.ui +++ b/Python_script/climate-lab-main.ui @@ -6,16 +6,16 @@ <rect> <x>0</x> <y>0</y> - <width>618</width> - <height>603</height> + <width>536</width> + <height>786</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralwidget"> - <layout class="QGridLayout" name="gridLayout_4"> - <item row="0" column="0"> + <layout class="QVBoxLayout" name="verticalLayout_8"> + <item> <widget class="QFrame" name="measurementTypeFrame"> <property name="frameShape"> <enum>QFrame::StyledPanel</enum> @@ -74,7 +74,7 @@ </layout> </widget> </item> - <item row="1" column="0"> + <item> <spacer name="verticalSpacer_2"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -87,7 +87,7 @@ </property> </spacer> </item> - <item row="2" column="0"> + <item> <widget class="QGroupBox" name="parametersGroupBox"> <property name="title"> <string>Sweep parameters</string> @@ -265,7 +265,7 @@ </layout> </widget> </item> - <item row="3" column="0"> + <item> <spacer name="verticalSpacer_3"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -278,10 +278,10 @@ </property> </spacer> </item> - <item row="4" column="0"> + <item> <widget class="QGroupBox" name="nameGroupBox"> <property name="title"> - <string>Name</string> + <string>Run Name</string> </property> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> @@ -307,7 +307,114 @@ </layout> </widget> </item> - <item row="5" column="0"> + <item> + <widget class="QGroupBox" name="analysisGroupBox"> + <property name="title"> + <string>Analysis</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_7"> + <item> + <layout class="QHBoxLayout" name="dutNameLayout"> + <item> + <widget class="QLabel" name="dutNameLabel"> + <property name="text"> + <string>DUT name</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="dutName"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="analysisMiddleLayout"> + <item> + <widget class="QGroupBox" name="analysisTypeGroupBox"> + <property name="title"> + <string>Analysis type</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_6"> + <item> + <widget class="QRadioButton" name="analysisTypeDefaultButton"> + <property name="text"> + <string>Default</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="analysisTypeCableButton"> + <property name="text"> + <string>RF Cable</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="cableLengthLayout"> + <item> + <widget class="QLabel" name="cableLengthLabel"> + <property name="text"> + <string>Length [m]</string> + </property> + </widget> + </item> + <item> + <widget class="QDoubleSpinBox" name="cableLengthSpinBox"> + <property name="value"> + <double>10.000000000000000</double> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="removeOffsetsGroupBox"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="title"> + <string>Remove offsets</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <widget class="QCheckBox" name="removeOffsetsSignal1"> + <property name="text"> + <string>Signal 1</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="removeOffsetsSignal2"> + <property name="text"> + <string>Signal 2</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> <layout class="QHBoxLayout" name="startButtonLayout"> <item> <spacer name="horizontalSpacer"> @@ -351,7 +458,7 @@ <rect> <x>0</x> <y>0</y> - <width>618</width> + <width>536</width> <height>30</height> </rect> </property> @@ -383,8 +490,8 @@ <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> - <x>122</x> - <y>514</y> + <x>136</x> + <y>504</y> </hint> <hint type="destinationlabel"> <x>138</x> @@ -408,5 +515,37 @@ </hint> </hints> </connection> + <connection> + <sender>analysisTypeCableButton</sender> + <signal>toggled(bool)</signal> + <receiver>removeOffsetsGroupBox</receiver> + <slot>setDisabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>139</x> + <y>719</y> + </hint> + <hint type="destinationlabel"> + <x>60</x> + <y>557</y> + </hint> + </hints> + </connection> + <connection> + <sender>analysisTypeCableButton</sender> + <signal>toggled(bool)</signal> + <receiver>removeOffsetsSignal1</receiver> + <slot>setChecked(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>115</x> + <y>723</y> + </hint> + <hint type="destinationlabel"> + <x>92</x> + <y>586</y> + </hint> + </hints> + </connection> </connections> </ui> diff --git a/Python_script/prototype.py b/Python_script/prototype.py index 7f0faf8..ae66644 100755 --- a/Python_script/prototype.py +++ b/Python_script/prototype.py @@ -451,8 +451,9 @@ if __name__ == '__main__': print('Argument error: Either \'file\' or \'temperaturesweepfile\' must be specified.') sys.exit(-1) + time_string = time.strftime("%Y_%m_%d-%H_%M_%S") if not args.output: - output_basename = time.strftime("%Y_%m_%d-%H_%M_%S") + "_results" + output_basename = time_string + "_results" else: output_basename = args.output @@ -478,7 +479,11 @@ if __name__ == '__main__': for t in temperatures: temp_extensions.append(str(t)+'deg_'+str(humidity)+'rh') analysis.plot_sweep(temperatures, [humidity]*len(temperatures), output_basename, 'temperature', - mes.dut.get_measurement_set_names(), mes.dut.get_dut_reference_signal_names()) + mes.dut.get_measurement_set_names(), mes.dut.get_dut_reference_signal_names(), + analysis_config={'type': 'default', 'normalise': [False, False], + 'extra_signal_names': [], + 'dut_name': 'measurement from prototype script', + 'time_string': time_string}) plot_output(output_basename, temp_extensions, args.plot, config_data, ext_sensor_channels, mes.dut.get_measurement_set_names(), mes.dut.get_dut_reference_signal_names(), output_basename + ': Temperature sweep ' + -- GitLab