From b1f0c5cdb8f06762a457255da9e2989bc136e3f4 Mon Sep 17 00:00:00 2001
From: Michael Pawelzik <michael.pawelzik@desy.de>
Date: Sat, 29 Jul 2023 09:00:59 +0200
Subject: [PATCH] - json file ext_sensor_param.json rename to
 ext_sensor_channels.json - in ext_sensor_channels.json key names for mapping
 sensor channels to measured values renamed - comments in TeststandGUI.bat and
 new path settings - edit names for import jsofile ext_sensor_channels.json in
 climate-lab-gui.py - edit names for reference to keys in
 ext_sensor_channels.json - edit import routine in prototype.py for import of
 external sensor data
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

### long term run with step from 25 to 30 °C sucessful ###
---
 Python_script/TestStandGUI.bat         |  4 +-
 Python_script/almemo710.py             |  2 +
 Python_script/climate-lab-gui.py       | 12 +++---
 Python_script/ext_sensor_channels.json |  1 +
 Python_script/ext_sensor_param.json    |  1 -
 Python_script/prototype.py             | 52 +++++++++++++-------------
 6 files changed, 37 insertions(+), 35 deletions(-)
 create mode 100644 Python_script/ext_sensor_channels.json
 delete mode 100644 Python_script/ext_sensor_param.json

diff --git a/Python_script/TestStandGUI.bat b/Python_script/TestStandGUI.bat
index 020561a..425416a 100644
--- a/Python_script/TestStandGUI.bat
+++ b/Python_script/TestStandGUI.bat
@@ -1,6 +1,6 @@
 @echo off
 cd..
 cd..
-cd C:\climate-lab-test-stand-modified\Python_script & REM path has to be changed to folder with file "climate-lab-gui.py"
-python C:\climate-lab-test-stand-modified\Python_script\climate-lab-gui.py %* & REM Python_script & REM path has to be changed to folder with file "climate-lab-gui.py"
+cd C:\git\climate-lab-test-stand\Python_script & REM path has to be changed to folder with file "climate-lab-gui.py"
+python C:\git\climate-lab-test-stand\Python_script\climate-lab-gui.py %* & REM Python_script & REM path has to be changed to folder with file "climate-lab-gui.py"
 pause
\ No newline at end of file
diff --git a/Python_script/almemo710.py b/Python_script/almemo710.py
index 63b8340..14fddca 100644
--- a/Python_script/almemo710.py
+++ b/Python_script/almemo710.py
@@ -426,5 +426,7 @@ class almemo710:
 
 
 
+
+
     
     
\ No newline at end of file
diff --git a/Python_script/climate-lab-gui.py b/Python_script/climate-lab-gui.py
index 2ab868f..a0cf1b4 100755
--- a/Python_script/climate-lab-gui.py
+++ b/Python_script/climate-lab-gui.py
@@ -63,8 +63,8 @@ class TestStandMainWindow(QMainWindow):
             config_data = json.load(f)
        
         # open json file ext_sens_data.joson and load values from file 
-        with open('ext_sensor_param.json', 'r') as f2:
-            config_ext_sens_data = json.load(f2)
+        with open('ext_sensor_channels.json', 'r') as f2:
+            ext_sensor_channels = json.load(f2)
 
         if self.autoNameCheckbox.isChecked():
             output_basename = time.strftime("%Y_%m_%d-%H_%M_%S") + "_results"
@@ -79,7 +79,7 @@ class TestStandMainWindow(QMainWindow):
         # ext_sens_data are the imported values from json file ext_sens_data.json , Michael
         # config_data['logger_ip'] is the imported ip from jason file test_stand_parameter.json, Michael
         meas = prototype.Measurements(config_data['chamber_ip'], config_data['vna_ip'], output_basename,
-                                      False, config_data, config_ext_sens_data, config_data['logger_ip'])
+                                      False, config_data, ext_sensor_channels, config_data['logger_ip'])
         try:
             if self.tempSweepButton.isChecked():
                 temperatures = meas.perform_sweep(self.startParameter.value(), self.stopParameter.value(),
@@ -94,7 +94,7 @@ class TestStandMainWindow(QMainWindow):
                 
                 # add ext_sens_data to parameterlist of plot_output method, Michael
                 # ext_sens_data are the imported values from json file ext_sens_data.json , Michael
-                prototype.plot_output(output_basename, temp_extensions, True, config_data, config_ext_sens_data, output_basename +
+                prototype.plot_output(output_basename, temp_extensions, True, config_data, ext_sensor_channels, output_basename +
                                       ': Temperature sweep ' + str(temperatures[0]) + '--' +
                                       str(temperatures[-1]) + ' degC @ ' + str(self.fixedParameter.value()) + ' % r.h.')
 
@@ -111,7 +111,7 @@ class TestStandMainWindow(QMainWindow):
                                 
                 # add ext_sens_data to parameterlist of plot_output method, Michael
                 # ext_sens_data are the imported values from json file ext_sens_data.json, Michael 
-                prototype.plot_output(output_basename, hum_extensions, True, config_data, config_ext_sens_data, output_basename +
+                prototype.plot_output(output_basename, hum_extensions, True, config_data, ext_sensor_channels, output_basename +
                                       ': Humidity sweep ' + str(humidities[0]) + '--' +
                                       str(humidities[-1]) + ' % r.h. @ ' + str(self.fixedParameter.value()) + ' degC')
 
@@ -121,7 +121,7 @@ class TestStandMainWindow(QMainWindow):
                                                                             self.measurementFile.text()))
                     # add ext_sens_data to parameterlist of plot_output method, Michael
                     # ext_sens_data are the imported values from json file ext_sens_data.json, Michael 
-                    prototype.plot_output(output_basename, range(n_measurements), True, config_ext_sens_data, output_basename)
+                    prototype.plot_output(output_basename, range(n_measurements), True, ext_sensor_channels, output_basename)
                 except FileNotFoundError as e:
                     QtWidgets.QMessageBox.warning(self, 'Warning', str(e))
 
diff --git a/Python_script/ext_sensor_channels.json b/Python_script/ext_sensor_channels.json
new file mode 100644
index 0000000..107a681
--- /dev/null
+++ b/Python_script/ext_sensor_channels.json
@@ -0,0 +1 @@
+{"temp_dut": "0.0", "hum_dut": "0.1", "temp_room": "1.0" , "hum_room": "1.1", "air_press_room":  "1.3", "temp_meas_instr": "2.0", "hum_meas_instr": "2.1"}
diff --git a/Python_script/ext_sensor_param.json b/Python_script/ext_sensor_param.json
deleted file mode 100644
index 77f69fe..0000000
--- a/Python_script/ext_sensor_param.json
+++ /dev/null
@@ -1 +0,0 @@
-{"ch_temp_dut": "0.0", "ch_hum_dut": "0.1", "ch_temp_room": "1.0" , "ch_hum_room": "1.1", "ch_air_press_room":  "1.3", "ch_temp_meas_inst": "2.0", "ch_hum_meas_inst": "2.1"}
diff --git a/Python_script/prototype.py b/Python_script/prototype.py
index a0fd08c..c663488 100755
--- a/Python_script/prototype.py
+++ b/Python_script/prototype.py
@@ -63,12 +63,12 @@ class MeasurementData:
 
 class Measurements:
     def __init__(self, chamber_address, vna_address, output_basename, standby, config_data, \
-                 config_ext_sens_data, logger_adress):
+                 ext_sensor_channels, logger_adress):
         self.max_delta_temp = config_data['delta_temp']
         self.max_delta_hum = config_data['delta_hum']
         self.max_delta_mag = config_data['delta_mag']
         self.max_delta_phase = config_data['delta_phase']
-        self.ext_sens_data = config_ext_sens_data
+        self.ext_sensor_channels = ext_sensor_channels
         self.sleep_time = config_data["sleep_time"]
         self.frequency = config_data["frequency"]
         self.vna_config_file = config_data["vna_config_file"]
@@ -329,7 +329,7 @@ class Measurements:
             
             try:
                 # request temperatures, humidities and and air pressure from external sensors, Michael
-                temp_dut, temp_room, temp_meas_inst, hum_dut, hum_room, hum_meas_inst, \
+                temp_dut, temp_room, temp_meas_instr, hum_dut, hum_room, hum_meas_instr, \
                     air_press_room = self.get_ext_sensor_values()
                 # if readout successfull, leave loop, Michael
                 break
@@ -346,8 +346,8 @@ class Measurements:
         # hum_dut, hum_room, hum_meas_instr air_press_room added to parameterlist in returned
         # values, Michael
         return MeasurementData(int(self.clock.time()), temp, hum, power, frequency, s11, s21, s12, s22, \
-                               perc_temp_heater, perc_hum_heater, temp_dut, temp_room, temp_meas_inst, \
-                                   hum_dut, hum_room, hum_meas_inst, air_press_room)
+                               perc_temp_heater, perc_hum_heater, temp_dut, temp_room, temp_meas_instr, \
+                                   hum_dut, hum_room, hum_meas_instr, air_press_room)
 
     def store_and_plot_data(self, target_temp, target_hum, data, equi_indicator):
         measurement = {
@@ -399,31 +399,31 @@ class Measurements:
     # new method to request temperaure values from external sensors of ahlborn, Michael 
     def get_ext_sensor_values(self):
         
+        # empty dictonary for sensor values        
+        sens_vals_dict = dict()
+        
         # request temperatures, humidities and and air pressure from external sensors, Michael
         self.ext_sensors.request_meas_vals_all_channels()
+        
+        # request sensor value vor channel in dictonary and add item to dictionary of sensor values
+        for key, value in self.ext_sensor_channels.items():
             
-        # get DUT temperature, room temperature and measurement instruments temperature , Michael 
-        temp_dut = self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
-                                                    self.ext_sens_data['ch_temp_dut'])[0].meas_val
-        # get DUT temperature, room temperature and measurement instruments temperature , Michael 
-        temp_dut = self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
-                                                    self.ext_sens_data['ch_temp_dut'])[0].meas_val
-        temp_room =self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
-                                                    self.ext_sens_data['ch_temp_room'])[0].meas_val
-        temp_meas_inst = self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
-                                                    self.ext_sens_data['ch_temp_meas_inst'])[0].meas_val
-        # get DUT humidity, room humidity and meas_instruments humidity, Michael
-        hum_dut = self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
-                                                    self.ext_sens_data['ch_hum_dut'])[0].meas_val
-        hum_room =self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
-                                                    self.ext_sens_data['ch_hum_room'])[0].meas_val
-        hum_meas_inst = self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
-                                                    self.ext_sens_data['ch_hum_meas_inst'])[0].meas_val
-        # get air pressure room, Michael 
-        air_press_room = self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
-                                                    self.ext_sens_data['ch_air_press_room'])[0].meas_val
+            sens_vals_dict[key] = self.ext_sensors.fetch_channel_param_from_meas_buffer(pattern = \
+                                                    value)[0].meas_val
+             
+        # set values from series to variables
+        sens_vals_series = pd.Series(sens_vals_dict)
+
+        # set series items for sensor value to matching variable
+        temp_dut =  sens_vals_series.temp_dut
+        temp_room =  sens_vals_series.temp_room
+        temp_meas_instr =  sens_vals_series.temp_meas_instr
+        hum_dut =  sens_vals_series.hum_dut
+        hum_room =  sens_vals_series.hum_room
+        hum_meas_instr =  sens_vals_series.hum_meas_instr
+        air_press_room = sens_vals_series.air_press_room
                  
-        return temp_dut, temp_room, temp_meas_inst, hum_dut, hum_room, hum_meas_inst, \
+        return temp_dut, temp_room, temp_meas_instr, hum_dut, hum_room, hum_meas_instr, \
             air_press_room
     
 
-- 
GitLab