Changed csv plots to show instantaneous field changes

This commit is contained in:
Martin Zietz
2021-02-24 16:43:22 +01:00
parent d3b41cae7c
commit ff0f0331dc
4 changed files with 25 additions and 11 deletions
+17 -4
View File
@@ -4,6 +4,7 @@
# import packages:
import time
import pandas
import numpy as np
from threading import *
from tkinter import messagebox
import matplotlib.pyplot as plt
@@ -13,6 +14,7 @@ import User_Interface as ui
import cage_func as func
import globals as g
import traceback # ToDo: remove!
class ExecCSVThread(Thread):
# main class for executing a CSV sequence
@@ -28,7 +30,7 @@ class ExecCSVThread(Thread):
self.__stop_event = Event() # event which can be set to stop the thread execution if needed
def run(self): # called to start the execution of the thread
ui.ui_print("Starting Sequence Execution...")
ui.ui_print("\nStarting Sequence Execution...")
self.execute_sequence(self.array, 0.1, self.parent, self.controller) # run sequence
# when the sequence has ended, reset buttons on the UI:
if not g.exitFlag: # main window is open
@@ -130,7 +132,6 @@ def check_array_ok(array):
def plot_field_sequence(array, width, height): # create plot of fixed size (pixels) 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 (dots per inch)
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
@@ -140,9 +141,21 @@ def plot_field_sequence(array, width, height): # create plot of fixed size (pix
figure.suptitle("Magnetic Field Sequence") # set figure title
t = array[:, 0] # extract time column
# modify data to show instantaneous jumps in field to reflect test stand operation
new_array = np.array([[0, 0, 0, 0]], dtype=float) # initialize modified array, zeros to show start from no fields
last_vals = [0, 0, 0] # [x,y,z] field values from last data point (zero here), used to create step in data
for row in array[:, 0:4]: # go through each row in the original array
# create extra datapoint at current timestamp, with field values from last, this creates "step" in plot:
new_array = np.append(new_array, [[row[0], *last_vals]], axis=0)
new_array = np.append(new_array, [row], axis=0) # add actual datapoint for current timestamp
last_vals = row[1:4] # save values from current timestamp for next
new_array = np.append(new_array, [[new_array[-1, 0], 0, 0, 0]], axis=0) # append last datapoint with 0 fields
# extract data and plot:
t = new_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 and convert to microtesla
data = new_array[:, i + 1] * 1e6 # extract field column of this axis and convert to microtesla
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