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

Revert "perform measurement in a separate thread"

This reverts commit c6944c41.
parent c6944c41
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,6 @@ import pandas as pd ...@@ -2,7 +2,6 @@ import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
import time import time
import queue
# Different exceptions can be thrown while plotting, depending on the backend. # Different exceptions can be thrown while plotting, depending on the backend.
# We catch them all locally and raise our own exception instead # We catch them all locally and raise our own exception instead
...@@ -54,28 +53,7 @@ class MeasurementPlot: ...@@ -54,28 +53,7 @@ class MeasurementPlot:
labels = [pc.get_label() for pc in all_path_collections] labels = [pc.get_label() for pc in all_path_collections]
self.ax1[1].legend(all_path_collections, labels, loc='lower right') self.ax1[1].legend(all_path_collections, labels, loc='lower right')
self.data_queue = queue.Queue(10) def draw(self, data_frame, pdf_name=''):
def stop(self):
self.data_queue.put((None, None, True))
def draw_in_other_thread(self, data_frame, pdf_name=''):
# A shallow copy is enough (although not strictly 100 % thread safe). Data is only appended and
# the data members are not altered.
frame_copy = data_frame.copy()
try:
self.data_queue.put_nowait((frame_copy, pdf_name, False))
except queue.Full:
pass
def drawing_loop(self):
while True:
data_frame, pdf_name, stop_thread = self.data_queue.get()
if stop_thread:
return
self.draw_in_this_thread(data_frame, pdf_name='')
def draw_in_this_thread(self, data_frame, pdf_name=''):
timestamps = data_frame.TIMESTAMP timestamps = data_frame.TIMESTAMP
minimum, maximum = self.get_extended_min_max(timestamps) minimum, maximum = self.get_extended_min_max(timestamps)
self.ax1[0].set_xlim(minimum, maximum) self.ax1[0].set_xlim(minimum, maximum)
...@@ -128,7 +106,6 @@ if __name__ == '__main__': ...@@ -128,7 +106,6 @@ if __name__ == '__main__':
plt.ion() plt.ion()
measurements = [] measurements = []
#FIXME: The loop should run in a separate thread and use draw_in_other_thread
for i in range(20): for i in range(20):
measurement = { measurement = {
'TIMESTAMP': i, 'TIMESTAMP': i,
...@@ -139,11 +116,11 @@ if __name__ == '__main__': ...@@ -139,11 +116,11 @@ if __name__ == '__main__':
'S21_MAGNITUDE': 0.3*i 'S21_MAGNITUDE': 0.3*i
} }
measurements.append(measurement) measurements.append(measurement)
my_data_frame = pd.DataFrame(measurements) data_frame = pd.DataFrame(measurements)
m.draw_in_this_thread(my_data_frame) m.draw(data_frame)
print(str(i)) print(str(i))
time.sleep(0.3) time.sleep(0.3)
print('I am done. ') print('I am done. ')
plt.ioff() plt.ioff()
m.draw_in_this_thread(my_data_frame, 'the.pdf') m.draw(data_frame, 'the.pdf')
...@@ -14,7 +14,6 @@ import json ...@@ -14,7 +14,6 @@ import json
import MeasurementPlot import MeasurementPlot
import sys import sys
import analysis import analysis
import threading
TEMPERATURE_STABLE = 0x1 TEMPERATURE_STABLE = 0x1
HUMIDITY_STABLE = 0x2 HUMIDITY_STABLE = 0x2
...@@ -137,17 +136,7 @@ class Measurements: ...@@ -137,17 +136,7 @@ class Measurements:
plt.close() plt.close()
return sweep_values return sweep_values
# wrapper function which calls the impl in a separate thread and runs the
# plotting loop
def perform_single_measurement(self, output, target_temp, target_hum, soaking_time, n_stable_reads): def perform_single_measurement(self, output, target_temp, target_hum, soaking_time, n_stable_reads):
measurement_thread = threading.Thread(target=self.perform_single_measurement_impl,
args=(output, target_temp, target_hum, soaking_time,
n_stable_reads))
measurement_thread.start()
self.measurement_plot.drawing_loop()
measurement_thread.join()
def perform_single_measurement_impl(self, output, target_temp, target_hum, soaking_time, n_stable_reads):
with open(output, mode='w', newline='') as csv_file: with open(output, mode='w', newline='') as csv_file:
fieldnames = ['TIMESTAMP', 'TARGET_TEMPERATURE', 'READBACK_TEMPERATURE', 'TARGET_HUMIDITY', fieldnames = ['TIMESTAMP', 'TARGET_TEMPERATURE', 'READBACK_TEMPERATURE', 'TARGET_HUMIDITY',
'READBACK_HUMIDITY', 'RF_POWER', 'RF_FREQUENCY', 'DUT_IDENTIFIER', 'RUN_ID', 'READBACK_HUMIDITY', 'RF_POWER', 'RF_FREQUENCY', 'DUT_IDENTIFIER', 'RUN_ID',
...@@ -266,8 +255,6 @@ class Measurements: ...@@ -266,8 +255,6 @@ class Measurements:
writer.writerow(measurement) writer.writerow(measurement)
self.measurement_plot.stop()
def sleep_until(self, wakeup_time): def sleep_until(self, wakeup_time):
remaining_sleep_time = wakeup_time - self.clock.time() remaining_sleep_time = wakeup_time - self.clock.time()
if remaining_sleep_time > 0: if remaining_sleep_time > 0:
...@@ -306,7 +293,7 @@ class Measurements: ...@@ -306,7 +293,7 @@ class Measurements:
} }
self.data_collection.append(measurement) self.data_collection.append(measurement)
data_frame = pd.DataFrame(self.data_collection) data_frame = pd.DataFrame(self.data_collection)
self.measurement_plot.draw_in_other_thread(data_frame) self.measurement_plot.draw(data_frame)
def current_milli_time(self): def current_milli_time(self):
return int(round(self.clock.time() * 1000)) return int(round(self.clock.time() * 1000))
...@@ -375,7 +362,7 @@ def plot_output(output_basename, measurements_appendices, show_blocking_plot, ti ...@@ -375,7 +362,7 @@ def plot_output(output_basename, measurements_appendices, show_blocking_plot, ti
if show_blocking_plot: if show_blocking_plot:
plt.ioff() plt.ioff()
plot = MeasurementPlot.MeasurementPlot(title) plot = MeasurementPlot.MeasurementPlot(title)
plot.draw_in_this_thread(combined_data_frame, output_basename + '_graph.pdf') plot.draw(combined_data_frame, output_basename + '_graph.pdf')
def run_temperature_sweep_from_file(temperature_sweep_file, meas): def run_temperature_sweep_from_file(temperature_sweep_file, meas):
with open(temperature_sweep_file) as file: with open(temperature_sweep_file) as file:
......
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