Skip to content
Snippets Groups Projects
Commit f1c05b60 authored by Martin Killenberg's avatar Martin Killenberg
Browse files

first working version of a temperature sweep

parent c6e4ab54
No related branches found
No related tags found
No related merge requests found
25.1 35.1 2.5 35 300 30
......@@ -12,6 +12,7 @@ import VNA
import virtual_time
import json
import MeasurementPlot
import sys
TEMPERATURE_STABLE = 0x1
HUMIDITY_STABLE = 0x2
......@@ -35,7 +36,7 @@ class MeasurementData:
class Measurements:
def __init__(self, chamber_address, vna_address, sweep_file, output_basename, standby, config_data):
def __init__(self, chamber_address, vna_address, output_basename, standby, config_data):
self.max_delta_temp = config_data['delta_temp']
self.max_delta_hum = config_data['delta_hum']
self.max_delta_mag = config_data['delta_mag']
......@@ -46,7 +47,6 @@ class Measurements:
target_accuracy = [self.max_delta_temp, self.max_delta_hum]
self.chamber = climate_chamber.create_chamber(chamber_address, target_accuracy)
self.vna = VNA.create_vna(vna_address, target_accuracy)
self.sweep_file = sweep_file
self.standby = standby
self.output_basename = output_basename
self.clock = virtual_time.get_clock(chamber_address, target_accuracy)
......@@ -64,8 +64,8 @@ class Measurements:
self.measurement_plot = MeasurementPlot.MeasurementPlot()
self.data_collection = []
def perform_measurements(self):
with open(self.sweep_file) as file:
def perform_measurements(self, sweep_file):
with open(sweep_file) as file:
try:
measurement_number = 0
while line := file.readline().rstrip():
......@@ -90,6 +90,20 @@ class Measurements:
standby_response = self.chamber.set_mode('STANDBY')
print(standby_response)
def perform_temperature_sweep(self, start_temp, stop_temp, temp_step, target_hum, soaking_time, n_stable_reads):
current_temp = start_temp
temperatures = []
while current_temp < stop_temp:
temperatures.append(current_temp)
current_temp = round(current_temp + temp_step, 1)
temperatures.append(stop_temp)
for temp in temperatures:
output_name = self.output_basename + '_'+str(temp)+'deg.csv'
self.perform_single_measurement(output_name, temp, target_hum, soaking_time, n_stable_reads)
return temperatures
def perform_single_measurement(self, output, target_temp, target_hum, soaking_time, n_stable_reads):
with open(output, mode='w', newline='') as csv_file:
fieldnames = ['TIMESTAMP', 'TARGET_TEMPERATURE', 'READBACK_TEMPERATURE', 'TARGET_HUMIDITY',
......@@ -306,9 +320,9 @@ class Measurements:
return (target_hum-self.max_delta_hum <= float(readback_hum)) and \
(float(readback_hum) <= target_hum+self.max_delta_hum)
def plot_output(output_basename, n_measurements, show_blocking_plot):
def plot_output(output_basename, measurements_appendices, show_blocking_plot):
list_of_frames = []
for m in range(n_measurements):
for m in measurements_appendices:
measurement_name = output_basename+'_'+str(m)
list_of_frames.append(pd.read_csv(measurement_name+'.csv'))
......@@ -317,7 +331,25 @@ def plot_output(output_basename, n_measurements, show_blocking_plot):
plt.ioff()
plot = MeasurementPlot.MeasurementPlot()
plot.draw(combined_data_frame, output_basename + '_graph.pdf')
def run_temperature_sweep_from_file(temperature_sweep_file, meas):
with open(temperature_sweep_file) as file:
try:
line = file.readline().rstrip()
list_of_values = line.split()
start_temp = float(list_of_values[0])
stop_temp = float(list_of_values[1])
temperature_step = float(list_of_values[2])
target_hum = float(list_of_values[3])
soaking_time = int(list_of_values[4])
n_stable_reads = int(list_of_values[5])
return meas.perform_temperature_sweep(start_temp, stop_temp, temperature_step, target_hum, soaking_time,
n_stable_reads)
except KeyboardInterrupt:
pass
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("-c", "--chamber",
......@@ -327,8 +359,11 @@ if __name__ == '__main__':
help="IP address of VNA", metavar="ADDR",
required=True)
parser.add_argument('-f', '--file',
help='File containing list of sweeps',
required=True)
help='File containing custom list of measurements',
default='')
parser.add_argument('-t', '--temperaturesweepfile',
help='File containing temperature sweep parameters',
default='')
parser.add_argument('-o', '--output',
help='Name of output file')
parser.add_argument("-s", "--standby",
......@@ -343,6 +378,10 @@ if __name__ == '__main__':
# help="don't print status messages to stdout")
args = parser.parse_args()
if args.file == '' and args.temperaturesweepfile == '':
print('Argument error: Either \'file\' or \'temperaturesweepfile\' must be specified.')
sys.exit(-1)
if not args.output:
output_basename = time.strftime("%Y_%m_%d-%H_%M_%S") + "_results"
else:
......@@ -354,12 +393,19 @@ if __name__ == '__main__':
with open('test_stand_parameter.json', 'r') as f:
config_data = json.load(f)
mes = Measurements(args.chamber, args.vna, args.file, output_basename, args.standby, config_data)
mes = Measurements(args.chamber, args.vna, output_basename, args.standby, config_data)
try:
n_measurements = mes.perform_measurements()
plot_output(output_basename, n_measurements, args.plot)
if args.file:
n_measurements = mes.perform_measurements(args.file)
plot_output(output_basename, range(n_measurements), args.plot)
if args.temperaturesweepfile:
temperatures = run_temperature_sweep_from_file(args.temperaturesweepfile, mes)
#run analysis here
temp_extensions = []
for t in temperatures:
temp_extensions.append(str(t)+'deg')
plot_output(output_basename, temp_extensions, args.plot)
print(str(temp_extensions))
finally:
mes.chamber.close()
......
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