From b6b6a34843a4afd1a3f475c0bb3a989b066bd602 Mon Sep 17 00:00:00 2001 From: Martin Killenberg <martin.killenberg@desy.de> Date: Thu, 12 Jan 2023 09:19:14 +0100 Subject: [PATCH] use MeasurementPlot class in prototype script --- Python_script/prototype.py | 76 +++++++------------------------------- 1 file changed, 13 insertions(+), 63 deletions(-) diff --git a/Python_script/prototype.py b/Python_script/prototype.py index 61a9ca6..5c014eb 100755 --- a/Python_script/prototype.py +++ b/Python_script/prototype.py @@ -11,7 +11,7 @@ import climate_chamber import VNA import virtual_time import json - +import MeasurementPlot TEMPERATURE_STABLE = 0x1 HUMIDITY_STABLE = 0x2 @@ -61,6 +61,8 @@ class Measurements: self.vna.create_new_trace("Trace3", "S21") self.vna.create_new_trace("Trace4", "S22") + self.measurement_plot = MeasurementPlot.MeasurementPlot() + def perform_measurements(self): with open(self.output, mode='w', newline='') as csv_file: fieldnames = ['TIMESTAMP', 'TARGET_TEMPERATURE', 'READBACK_TEMPERATURE', 'TARGET_HUMIDITY', @@ -71,7 +73,7 @@ class Measurements: writer = csv.DictWriter(csv_file, fieldnames=fieldnames) writer.writeheader() self.data_collection = [] - self.subplot_tuple = plt.subplots(2, figsize=(12, 10)) + plt.ion() with open(self.sweep_file) as file: try: @@ -136,8 +138,7 @@ class Measurements: print('Setpoint: ' + str(next_temp) + ' ' + str(next_hum) + ' | Temp: ' + data.temp + ' °C' + ' | Humid: ' + data.hum + '%' + ' | soaking read nr' + str(len(magnitudes_queue))) - self.write_data(writer, next_temp, next_hum, data, self.cook_up_equi_indicator())#, - #data_frame, subplot_tuple) + self.write_data(writer, next_temp, next_hum, data, self.cook_up_equi_indicator()) if self.temperature_stable and self.humidity_stable and self.magnitude_stable and\ self.phase_stable: @@ -201,13 +202,13 @@ class Measurements: return MeasurementData(int(self.clock.time()), temp, hum, power, frequency, s11, s21, s12, s22) - def write_data(self, writer, target_temp, target_hum, data, equi_indicator):#, data_frame, subplot_tuple): + def write_data(self, writer, target_temp, target_hum, data, equi_indicator): measurement = { 'TIMESTAMP': data.timestamp, 'TARGET_TEMPERATURE': target_temp, - 'READBACK_TEMPERATURE': data.temp, + 'READBACK_TEMPERATURE': float(data.temp), 'TARGET_HUMIDITY': target_hum, - 'READBACK_HUMIDITY': data.hum, + 'READBACK_HUMIDITY': float(data.hum), 'RF_POWER': data.power, 'RF_FREQUENCY': data.frequency, 'EQUILIBRIUM_INDICATOR': equi_indicator, @@ -223,7 +224,7 @@ class Measurements: writer.writerow(measurement) self.data_collection.append(measurement) data_frame = pd.DataFrame(self.data_collection) - plot_measurement(data_frame, False, False, self.subplot_tuple) + self.measurement_plot.draw(data_frame) def current_milli_time(self): return int(round(self.clock.time() * 1000)) @@ -282,63 +283,12 @@ class Measurements: return (target_hum-self.max_delta_hum <= float(readback_hum)) and \ (float(readback_hum) <= target_hum+self.max_delta_hum) -# plot a single measurement (phase, magnitude, temp and hum against time) from a pandas data frame -def plot_measurement(data_frame, show_blocking_plot, save_pdf=True, subplot_tuple = (None, None)): - fig, ax1 = subplot_tuple - if fig is None or ax1 is None: - fig, ax1 = plt.subplots(2, figsize=(12, 10)) - - path_collection01 = ax1[0].scatter(data_frame.TIMESTAMP, data_frame.S21_PHASE, c='red', marker='<', label='Phase') - twin2_0 = ax1[0].twinx() - path_collection02 = twin2_0.scatter(data_frame.TIMESTAMP, data_frame.S21_MAGNITUDE, c='#3120E0', marker='4', - label='Magnitude') - twin3_0 = ax1[0].twinx() - twin3_0.spines['right'].set_position(('outward', 40)) - path_collection03 = twin3_0.scatter(data_frame.TIMESTAMP, data_frame.EQUILIBRIUM_INDICATOR, c='black', marker=".", - label='Equilibrium_Indicator') - ax1[0].set_xlabel("TIMESTAMP") - ax1[0].set_ylabel("PHASE", color='red') - twin2_0.set_ylabel("MAGNITUDE", color='#3120E0') - twin3_0.set_ylabel("EQUILIBRIUM_INDICATOR", color='black') - - ax1[0].grid(True, linestyle=":") - all_path_collections = [path_collection01, path_collection02, path_collection03] - labels = [pc.get_label() for pc in all_path_collections] - ax1[0].legend(all_path_collections, labels, loc='lower right') - - path_collection11 = ax1[1].scatter(data_frame.TIMESTAMP, data_frame.READBACK_TEMPERATURE, c='blue', marker='p', - label="Temperature") - twin2_1 = ax1[1].twinx() - path_collection12 = twin2_1.scatter(data_frame.TIMESTAMP, data_frame.READBACK_HUMIDITY, c='green', marker="*", - label="Humidity") - twin3_1 = ax1[1].twinx() - twin3_1.spines['right'].set_position(('outward', 40)) - path_collection13 = twin3_1.scatter(data_frame.TIMESTAMP, data_frame.EQUILIBRIUM_INDICATOR, c='black', marker=".", - label="Equilibrium_Indicator") - ax1[1].set_xlabel("TIMESTAMP") - ax1[1].set_ylabel("TEMPERATURE ", color='blue') - twin2_1.set_ylabel("HUMIDITY", color='green') - twin3_1.set_ylabel("EQUILIBRIUM_INDICATOR", color='black') - ax1[1].grid(True, linestyle=":") - all_path_collections = [path_collection11, path_collection12, path_collection13] - labels = [pc.get_label() for pc in all_path_collections] - ax1[1].legend(all_path_collections, labels, loc='lower right') - - if save_pdf: - fig.savefig(output_basename + '_graph.pdf') - - # turn interactive on if we are not supposed to block, otherwise turn it off - if show_blocking_plot: - plt.ioff() - else: - plt.ion() - fig.canvas.draw() - fig.canvas.flush_events() - plt.show() - def plot_output(output_basename, show_blocking_plot, save_pdf=True): data_frame = pd.read_csv(output_basename+'.csv') - plot_measurement(data_frame, show_blocking_plot, save_pdf) + if show_blocking_plot: + plt.ioff() + plot = MeasurementPlot.MeasurementPlot() + plot.draw(data_frame, output_basename + '_graph.pdf') if __name__ == '__main__': parser = ArgumentParser() -- GitLab