-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_vis.py
More file actions
143 lines (123 loc) · 4.51 KB
/
data_vis.py
File metadata and controls
143 lines (123 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import operator
from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties
import seaborn as sns
import pdb
import tables
def stats(t, position, velocity, accel, thrust, drag, name=None):
if name is None:
name = "Mockheed Lartin"
stats = {}
dt = t[1] - t[0]
stats['name'] = name
stats['max_altitude [ft]'] = max(position[:,1])
stats['max_velocity [ft/s]'] = max(velocity[:,1])
stats['max_g_force'] = (max(accel[:,1])/32.18)
stats['total_impulse [lbf-s]'] = sum(thrust)*dt
stats['peak_thrust [lbf]'] = max(thrust)
stats['flight_time [s]'] = max([t[i] if position[i,1] > 0 else 0 for i in xrange(len(t))])
stats['descent_rate [ft/s]'] = [velocity[i,1] for i in xrange(len(t)) if velocity[i,1] != 0][-1]
stats['max_drag [lbf]'] = max(drag[:,1])
launch_rod_length = 3 #ft
stats['velocity_off_launch_rod'] = max([velocity[i,1] for i in xrange(len(t)) if position[i,1] < launch_rod_length])
print(stats)
def stats_table(t, position, velocity, accel, thrust, drag, angle, delay):
altitude = max(position[:,1])
flight_time = max([t[i] if position[i,1] > 0 else 0 for i in xrange(len(t))])
print("Angle: ", angle, "Delay: ", delay, "Altitude: ", altitude, "Time: ", flight_time)
def stats_mass_curve(t, position, velocity, accel, thrust, drag, masses, altitudes):
index, altitude = max(enumerate(altitudes), key=operator.itemgetter(1))
print("Max altitude of " + str(altitude) + " with mass of " + str(masses[index]) + ".")
stats(t, position, velocity, accel, thrust, drag)
plt.figure(1)
plt.plot(masses, altitudes)
plt.ylabel("Apogee Height [ft]")
plt.xlabel("Dry Mass [kg]")
plt.title("Mass Curve")
plt.show()
def plot(t, position, velocity, accel, thrust, drag, name=None, export=False):
if name is None:
name = "Mockheed Lartin"
plt.close('all')
sns.set_style('darkgrid')
# Altitude
plt.figure(1)
plt.subplot(211)
plt.plot(t, position[:,1], label=name)
plt.ylabel('Height [ft]')
plt.xlabel('Time [s]')
plt.title('Altitude')
plt.grid()
plt.subplot(212)
plt.plot(t, velocity[:,1], label=name)
plt.ylabel('Velocity [ft/s]')
plt.xlabel('Time [s]')
plt.title('Velocity')
plt.grid()
plt.tight_layout()
# Velocity
plt.figure(2)
plt.plot(t, velocity[:,1], label=name)
plt.ylabel('Velocity [ft/s]')
plt.xlabel('Time [s]')
plt.title('Velocity')
plt.grid()
plt.tight_layout()
# Launch Rod Velocity
plt.figure(3)
rod_velocity = [velocity[i,1] for i in xrange(len(velocity[:,1]))
if (position[i,1] < 5) & (t[i] < 1)]
rod_position = [position[i,1] for i in xrange(len(position[:,1]))
if (position[i,1] < 5) & (t[i] < 1)]
plt.plot(rod_position, rod_velocity, label=name)
plt.ylabel('Velocity [ft/s]')
plt.xlabel('Position on Launch Rod [ft]')
plt.title('Launch Velocity')
plt.grid()
plt.tight_layout()
# Acceleration
plt.figure(4)
plt.subplot(211)
plt.plot(t[0:len(thrust)-4], accel[0:len(thrust)-4,1], label=name)
plt.ylabel('Acceleration ft/s^2')
plt.xlabel('Time [s]')
plt.title(' Acceleration')
plt.grid()
plt.subplot(212)
plt.plot(t[0:len(thrust)], thrust, label=name)
plt.ylabel('Thrust [lbf]')
plt.xlabel('Time [s]')
plt.title(' Thrust')
plt.grid()
plt.tight_layout()
# Drag and Thrust
plt.figure(5)
plt.plot(t, drag[:,1], label="Drag")
plt.plot([t[i] for i in xrange(len(thrust))], thrust, label="Thrust")
plt.ylabel('Force [lbf]')
plt.xlabel('Time [s]')
plt.title('Drag and Thrust')
lgd = plt.legend()
plt.grid()
plt.tight_layout()
if not export:
plt.show()
def save_plots(name):
""" Saves figures 1, 2, and 3 using labels for legend. These figures must be populated by a call for plot()."""
fontP = FontProperties()
fontP.set_size('small')
fig = plt.figure(1)
lgd = plt.legend(bbox_to_anchor=(0.91,-0.1), loc="lower right", ncol=3,
bbox_transform=fig.transFigure, prop=fontP)
plt.savefig('../lab3/plots/' + 'Altitude' + '.png',
bbox_extra_artists=(lgd,), bbox_inches='tight')
fig = plt.figure(2)
lgd = plt.legend(bbox_to_anchor=(0.91,-0.1), loc="lower right", ncol=3,
bbox_transform=fig.transFigure, prop=fontP)
plt.savefig('../lab3/plots/' + 'Velocity' + '.png',
bbox_extra_artists=(lgd,), bbox_inches='tight')
fig = plt.figure(3)
lgd = plt.legend(bbox_to_anchor=(0.91,-0.1), loc="lower right", ncol=3,
bbox_transform=fig.transFigure, prop=fontP)
plt.savefig('../lab3/plots/' + 'Acceleration' + '.png',
bbox_extra_artists=(lgd,), bbox_inches='tight')