forked from zietzm/Helmholtz_Test_Bench
Visual improvements for csv graphs
This commit is contained in:
+41
-31
@@ -11,7 +11,6 @@ import globals as g
|
||||
|
||||
|
||||
class ExecCSVThread(Thread):
|
||||
# ToDo: handling for disconnected devices
|
||||
def __init__(self, threadID, array, parent, controller):
|
||||
Thread.__init__(self)
|
||||
|
||||
@@ -79,46 +78,57 @@ def execute_sequence(array, delay, parent, controller): # runs through array co
|
||||
def read_csv_to_array(filepath):
|
||||
# csv format: time (s); xField (T); yField (T); zField (T) (german excel)
|
||||
# decimal commas
|
||||
ui.ui_print("Reading File:", filepath)
|
||||
file = pandas.read_csv(filepath, sep=';', decimal=',', header=0) # read csv file
|
||||
array = file.to_numpy() # convert csv to array
|
||||
return array
|
||||
|
||||
|
||||
def check_array(array):
|
||||
# ToDo: message formatting, pop up warning
|
||||
# ToDo: comments
|
||||
concerns = []
|
||||
for row in array:
|
||||
i = 1
|
||||
for axis in g.AXES:
|
||||
value = row[i]
|
||||
if value > axis.max_comp_field[1]:
|
||||
concerns.append(row)
|
||||
elif value < axis.max_comp_field[0]:
|
||||
concerns.append(row)
|
||||
i += 1
|
||||
ui.ui_print("Checked csv, found %i concerns." % len(concerns))
|
||||
if len(concerns) > 0:
|
||||
ui.ui_print(concerns)
|
||||
def check_array_ok(array): # check if any magnetic fields in an array exceed the limits
|
||||
values_ok = True
|
||||
for i in [0, 1, 2]: # go through axes
|
||||
max_val = g.AXES[i].max_comp_field[1] # get limits
|
||||
min_val = g.AXES[i].max_comp_field[0]
|
||||
data = array[:, i + 1] # extract data for this axis from array
|
||||
# noinspection PyTypeChecker
|
||||
if any(data > max_val) or any(data < min_val): # if any datapoint is out of bounds
|
||||
values_ok = False
|
||||
if not values_ok: # show warning pop-up if values are exceeding limits
|
||||
messagebox.showwarning("Value Limits Warning!", "Found field values exceeding limits of test stand."
|
||||
"\nSee plot and check values in csv.")
|
||||
|
||||
|
||||
def plot_field_sequence(array, width, height): # ToDo: comments
|
||||
# ToDo: make pretty
|
||||
fig_dpi = 100
|
||||
px = 1/fig_dpi
|
||||
figure = plt.Figure(figsize=(width*px, height*px), dpi=fig_dpi)
|
||||
def plot_field_sequence(array, width, height): # create plot of fixed size from array
|
||||
# ToDo (optional): polar plots, plots of angle...
|
||||
# ToDo (optional): show graphs as steps (as performed by test stand)
|
||||
fig_dpi = 100 # set figure resolution
|
||||
px = 1/fig_dpi # get pixel to inch size conversion
|
||||
figure = plt.Figure(figsize=(width*px, height*px), dpi=fig_dpi) # create figure with correct size
|
||||
|
||||
# noinspection PyTypeChecker,SpellCheckingInspection
|
||||
axes = figure.subplots(3, sharex=True, sharey=True, gridspec_kw={'hspace': 0.4})
|
||||
axes = figure.subplots(3, sharex=True, sharey=True, gridspec_kw={'hspace': 0.4}) # create subplots with shared axes
|
||||
|
||||
figure.suptitle("Magnetic Field Sequence")
|
||||
t = array[:, 0]
|
||||
|
||||
for i in [0, 1, 2]:
|
||||
data = array[:, i + 1] * 1e6
|
||||
plot = axes[i]
|
||||
plot.plot(t, data)
|
||||
plot.set_title(g.AXIS_NAMES[i])
|
||||
t = array[:, 0] # extract time column
|
||||
for i in [0, 1, 2]: # go through all three axes
|
||||
data = array[:, i + 1] * 1e6 # extract field column of this axis
|
||||
max_val = g.AXES[i].max_comp_field[1] * 1e6 # get limits of achievable field
|
||||
min_val = g.AXES[i].max_comp_field[0] * 1e6
|
||||
plot = axes[i] # get appropriate subplot
|
||||
|
||||
return figure
|
||||
plot.plot(t, data, linestyle='solid', marker='.') # plot data
|
||||
|
||||
if any(data > max_val): # if any value is higher than the maximum
|
||||
plot.axhline(y=max_val, linestyle='dashed', color='r') # plot horizontal line to show maximum
|
||||
# add label to line:
|
||||
plot.text(t[-1], max_val, "max", horizontalalignment='center', verticalalignment='top', color='r')
|
||||
if any(data < min_val): # same as above
|
||||
plot.axhline(y=min_val, linestyle='dashed', color='r')
|
||||
plot.text(t[-1], min_val, "min", horizontalalignment='center', color='r')
|
||||
plot.set_title(g.AXIS_NAMES[i], size=10) # set subplot title (e.g. "X-Axis")
|
||||
|
||||
# set shared axis labels:
|
||||
axes[2].set_xlabel("Time (s)")
|
||||
axes[1].set_ylabel("Magnetic Field (\u03BCT)")
|
||||
|
||||
return figure # return the created figure to be inserted somewhere else
|
||||
|
||||
Reference in New Issue
Block a user