diff --git a/Python_script/prototype.py b/Python_script/prototype.py index 58c2b0534e2d0dea97150f6326ca9a28ba658723..1c56e8295a9963190d228a3b8fe163a9fef4737b 100755 --- a/Python_script/prototype.py +++ b/Python_script/prototype.py @@ -73,10 +73,10 @@ class Measurements: try: while line := file.readline().rstrip(): list_of_values = line.split() - next_temp = float(list_of_values[0]) - next_hum = float(list_of_values[1]) - next_soaking = int(list_of_values[2]) - next_reads = int(list_of_values[3]) + next_temp = float(list_of_values[0]) # target_temperature + next_hum = float(list_of_values[1]) # target_humidity + next_soaking = int(list_of_values[2]) # soaking_time + next_reads = int(list_of_values[3]) # number of stable readings set_const_response = self.chamber.set_const((next_temp, next_hum)) print(set_const_response) @@ -109,7 +109,6 @@ class Measurements: magnitudes_queue.append(self.calculate_mean_magnitude(data.s21)) else: magnitudes_queue.clear() - # check cable stability parameters self.magnitude_stable = False if len(magnitudes_queue) >= number_of_soaking_reads: @@ -137,8 +136,8 @@ class Measurements: if self.temperature_stable and self.humidity_stable and self.magnitude_stable and\ self.phase_stable: - self.reference_magnitude = magnitudes_queue[-1] - self.reference_phase = phase_queue[-1] + reference_magnitude = magnitudes_queue[-1] + reference_phase = phase_queue[-1] print('SOAKING FINISHED!') break else: @@ -153,30 +152,31 @@ class Measurements: self.humidity_stable = self.calculate_humidity_stability(next_hum, float(data.hum)) mag = self.calculate_mean_magnitude(data.s21) phase = self.calculate_mean_phase(data.s21) - self.magnitude_stable = (self.reference_magnitude-self.max_delta_mag <= mag) and\ - (mag <= self.reference_magnitude+self.max_delta_mag) - self.phase_stable = (self.reference_phase-self.max_delta_phase <= phase) and\ - (phase <= self.reference_phase+self.max_delta_phase) - print('phase '+str(phase)+', ref_phase '+str(self.reference_phase)+', max_delta '+str(self.max_delta_phase)) + self.magnitude_stable = (reference_magnitude-self.max_delta_mag <= mag) and\ + (mag <= reference_magnitude+self.max_delta_mag) + self.phase_stable = (reference_phase-self.max_delta_phase <= phase) and\ + (phase <= reference_phase+self.max_delta_phase) supposedly_stable_measurements.append([data, self.cook_up_equi_indicator()]) - print('Read no.', str(i)) - if (self.temperature_stable and self.humidity_stable and self.magnitude_stable and\ + + if (self.temperature_stable and self.humidity_stable and self.magnitude_stable and self.phase_stable): self.clock.sleep(self.sleep_time) else: - print('HELP, I am lost!') all_measurements_stable = False break - for [d, measurement_equi] in supposedly_stable_measurements: - if (all_measurements_stable): + for [d, measurement_equi] in supposedly_stable_measurements: + if all_measurements_stable: equi = TEMPERATURE_STABLE | HUMIDITY_STABLE | MAGNITUDE_STABLE | PHASE_STABLE | MEASUREMENT_STABLE do_another_measurement = False else: equi = measurement_equi self.write_data(writer, next_temp, next_hum, d, equi) - + parser1 = ArgumentParser() + parser1.add_argument("-p", "--plot", + help="graph plotting", metavar="ADDR", + required=True) except KeyboardInterrupt: pass @@ -266,7 +266,7 @@ class Measurements: def plot_output(self, output_file): csv_data = pd.read_csv(output_file) - fig, ax1 = plt.subplots(2, figsize=(8, 8)) + fig, ax1 = plt.subplots(2, figsize=(12, 10)) fig.suptitle("Graphical representation of chamber output", color="red") path_collection01 = ax1[0].scatter(csv_data.TIMESTAMP, csv_data.S11_PHASE, c='red', marker='<', label='Phase') @@ -305,6 +305,9 @@ class Measurements: labels = [pc.get_label() for pc in all_path_collections] ax1[1].legend(all_path_collections, labels, loc='lower right') + fig.savefig(time.strftime("%Y_%m_%d-%H_%M_%S") + 'graph.png') + plt.close(fig) + plt.show() def calculate_temperature_stability(self, target_temp, readback_temp):