Skip to content
Snippets Groups Projects
Commit c03b88af authored by Sai Lakhan Ekal's avatar Sai Lakhan Ekal
Browse files

Added read_and_write function to to read data from chamber and VNA and write it in CSV

Added function to avoid code duplication in perform_measurments function
parent b32864a7
No related branches found
No related tags found
No related merge requests found
...@@ -66,11 +66,11 @@ class Measurements: ...@@ -66,11 +66,11 @@ class Measurements:
self.soaking_time_past = False self.soaking_time_past = False
# wait until set point is reached (+soaking time) # wait until set point is reached (+soaking time)
while True: while True:
# get the actual temperature & humidity # FIXME: Reading is done in read_data_and_write again. Remove this duplication
[temp, hum, mode, alarms] = self.chamber.read_monitor().split(',') [temp, hum, mode, alarms] = self.chamber.read_monitor().split(',')
# if it is not within the target range reset start time # if it is not within the target range reset start time
if not(next_temp - self.target_accuracy[0] <= float(temp) <= next_temp + self.target_accuracy[0]): if not(next_temp-self.target_accuracy[0] <= float(temp) <= next_temp+self.target_accuracy[0]):
start_time = self.current_milli_time() start_time = self.current_milli_time()
if not (next_hum-self.target_accuracy[1] <= float(hum) <= next_hum+self.target_accuracy[1]): if not (next_hum-self.target_accuracy[1] <= float(hum) <= next_hum+self.target_accuracy[1]):
...@@ -86,56 +86,14 @@ class Measurements: ...@@ -86,56 +86,14 @@ class Measurements:
+ ' | Humid: ' + hum + '%' + ' | Humid: ' + hum + '%'
+ ' | time soaking: ' + str((self.current_milli_time() - start_time) / 1000) + 's') + ' | time soaking: ' + str((self.current_milli_time() - start_time) / 1000) + 's')
s11 = self.get_trace_data("Trace1") self.read_data_and_write(writer, next_temp, next_hum)
s21 = self.get_trace_data("Trace2")
s12 = self.get_trace_data("Trace3")
s22 = self.get_trace_data("Trace4")
writer.writerow({
'TIMESTAMP': int(self.clock.time()),
'TARGET_TEMPERATURE': next_temp,
'READBACK_TEMPERATURE': temp,
'TARGET_HUMIDITY': next_hum,
'READBACK_HUMIDITY': hum,
'RF_POWER': self.vna.get_current_power(),
'RF_FREQUENCY': self.vna.get_current_cw_frequency(),
'EQUILIBRIUM_INDICATOR': self.equi_indicator(),
'S11_PHASE': self.calculate_mean_phase(s11),
'S11_MAGNITUDE': self.calculate_mean_magnitude(s11),
'S21_PHASE': self.calculate_mean_phase(s21),
'S21_MAGNITUDE': self.calculate_mean_magnitude(s21),
'S12_PHASE': self.calculate_mean_phase(s12),
'S12_MAGNITUDE': self.calculate_mean_magnitude(s12),
'S22_PHASE': self.calculate_mean_phase(s22),
'S22_MAGNITUDE': self.calculate_mean_magnitude(s22)
})
self.clock.sleep(data["sleep_time"]) self.clock.sleep(data["sleep_time"])
for i in range(0, next_reads): for i in range(0, next_reads):
[temp, hum, mode, alarms] = self.chamber.read_monitor().split(',') self.read_data_and_write(writer, next_temp, next_hum)
s11 = self.get_trace_data("Trace1") print('Read no.', str(i))
s21 = self.get_trace_data("Trace2")
s12 = self.get_trace_data("Trace3")
s22 = self.get_trace_data("Trace4")
print('Read no.', i, ': ', temp, hum, mode, alarms)
writer.writerow({
'TIMESTAMP': int(self.clock.time()),
'TARGET_TEMPERATURE': next_temp,
'READBACK_TEMPERATURE': temp,
'TARGET_HUMIDITY': next_hum,
'READBACK_HUMIDITY': hum,
'RF_POWER': self.vna.get_current_power(),
'RF_FREQUENCY': self.vna.get_current_cw_frequency(),
'EQUILIBRIUM_INDICATOR': self.equi_indicator(),
'S11_PHASE': self.calculate_mean_phase(s11),
'S11_MAGNITUDE': self.calculate_mean_magnitude(s11),
'S21_PHASE': self.calculate_mean_phase(s21),
'S21_MAGNITUDE': self.calculate_mean_magnitude(s21),
'S12_PHASE': self.calculate_mean_phase(s12),
'S12_MAGNITUDE': self.calculate_mean_magnitude(s12),
'S22_PHASE': self.calculate_mean_phase(s22),
'S22_MAGNITUDE': self.calculate_mean_magnitude(s22)
})
self.clock.sleep(data["sleep_time"]) self.clock.sleep(data["sleep_time"])
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
...@@ -143,6 +101,32 @@ class Measurements: ...@@ -143,6 +101,32 @@ class Measurements:
standby_response = self.chamber.set_mode('STANDBY') standby_response = self.chamber.set_mode('STANDBY')
print(standby_response) print(standby_response)
def read_data_and_write(self, writer, target_temp, target_hum):
# get the actual temperature & humidity
[temp, hum, mode, alarms] = self.chamber.read_monitor().split(',')
s11 = self.get_trace_data("Trace1")
s21 = self.get_trace_data("Trace2")
s12 = self.get_trace_data("Trace3")
s22 = self.get_trace_data("Trace4")
writer.writerow({
'TIMESTAMP': int(self.clock.time()),
'TARGET_TEMPERATURE': target_temp,
'READBACK_TEMPERATURE': temp,
'TARGET_HUMIDITY': target_hum,
'READBACK_HUMIDITY': hum,
'RF_POWER': self.vna.get_current_power(),
'RF_FREQUENCY': self.vna.get_current_cw_frequency(),
'EQUILIBRIUM_INDICATOR': self.equi_indicator(),
'S11_PHASE': self.calculate_mean_phase(s11),
'S11_MAGNITUDE': self.calculate_mean_magnitude(s11),
'S21_PHASE': self.calculate_mean_phase(s21),
'S21_MAGNITUDE': self.calculate_mean_magnitude(s21),
'S12_PHASE': self.calculate_mean_phase(s12),
'S12_MAGNITUDE': self.calculate_mean_magnitude(s12),
'S22_PHASE': self.calculate_mean_phase(s22),
'S22_MAGNITUDE': self.calculate_mean_magnitude(s22)
})
def current_milli_time(self): def current_milli_time(self):
return int(round(self.clock.time() * 1000)) return int(round(self.clock.time() * 1000))
...@@ -186,6 +170,7 @@ class Measurements: ...@@ -186,6 +170,7 @@ class Measurements:
# FIXME # FIXME
if self.soaking_time_past == True: if self.soaking_time_past == True:
equilibrium_indicator = equilibrium_indicator | MAGNITUDE_STABLE equilibrium_indicator = equilibrium_indicator | MAGNITUDE_STABLE
if self.soaking_time_past == True: if self.soaking_time_past == True:
equilibrium_indicator = equilibrium_indicator | PHASE_STABLE equilibrium_indicator = equilibrium_indicator | PHASE_STABLE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment