forked from zietzm/Helmholtz_Test_Bench
Includes rotation rates to plots
This commit is contained in:
+20
-10
@@ -156,24 +156,24 @@ def plot_field_sequence(array, width, height): # create plot of fixed size (pix
|
||||
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}) # create subplots with shared axes
|
||||
axes = figure.subplots(4, sharex=True, sharey=False, gridspec_kw={'hspace': 0.4}) # create subplots with shared axes
|
||||
|
||||
figure.suptitle("Magnetic Field Sequence") # set figure title
|
||||
|
||||
# modify data to show instantaneous jumps in field to reflect test bench operation
|
||||
new_array = np.array([[0, 0, 0, 0]], dtype=float) # initialize modified array, zeros to show start from no fields
|
||||
new_array = np.array([[0, 0, 0, 0, 0]], dtype=float) # initialize modified array, zeros to show start from no fields
|
||||
|
||||
last_values = [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
|
||||
last_values = [0, 0, 0, 0] # [x,y,z, rr] field values / rot rate from last data point (zero here)
|
||||
for row in array[:, 0:5]: # go through each row in the original array
|
||||
# create extra datapoint at current timestamp, with field values from last to create a "step" in the plot:
|
||||
new_array = np.append(new_array, [[row[0], *last_values]], axis=0)
|
||||
new_array = np.append(new_array, [row], axis=0) # add actual datapoint for current timestamp
|
||||
last_values = 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
|
||||
last_values = row[1:5] # save values from current timestamp for next
|
||||
new_array = np.append(new_array, [[new_array[-1, 0], 0, 0, 0, 0]], axis=0) # append last datapoint with 0 fields
|
||||
|
||||
# extract data and plot:
|
||||
# extract data and plot magnetic fields:
|
||||
t = new_array[:, 0] # extract time column
|
||||
for i in [0, 1, 2]: # go through all three axes
|
||||
for i in [0, 1, 2]: # go through all three axes plus rotation rate
|
||||
data = new_array[:, i + 1] * 1e6 # extract field column of this axis and convert to microtesla
|
||||
min_val, max_val = g.CAGE_DEVICE.axes[i].max_comp_field * 1e6 # get limits of achievable field
|
||||
plot = axes[i] # get appropriate subplot
|
||||
@@ -189,9 +189,19 @@ def plot_field_sequence(array, width, height): # create plot of fixed size (pix
|
||||
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")
|
||||
# plot rotation rate
|
||||
plot = axes[3]
|
||||
plot.plot(t, new_array[:, 4], linestyle='solid', marker='.') # plot data
|
||||
# set ylim of magnetic field axis to same value
|
||||
ylim_mag = ([min(axes[0].get_ylim()), max(axes[0].get_ylim()),
|
||||
min(axes[1].get_ylim()), max(axes[1].get_ylim()),
|
||||
min(axes[2].get_ylim()), max(axes[2].get_ylim())])
|
||||
for i in range(3): axes[0].set_ylim(min(ylim_mag),max(ylim_mag))
|
||||
|
||||
|
||||
# set shared axis labels:
|
||||
axes[2].set_xlabel("Time (s)")
|
||||
axes[1].set_ylabel("Magnetic Field (\u03BCT)")
|
||||
axes[2].set_xlabel("Time [s])")
|
||||
axes[1].set_ylabel("Magnetic Field [\u03BCT]")
|
||||
axes[3].set_ylabel("Rate [°/s]")
|
||||
|
||||
return figure # return the created figure to be inserted somewhere
|
||||
|
||||
Reference in New Issue
Block a user