-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualization.py
executable file
·112 lines (96 loc) · 3.4 KB
/
Visualization.py
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
from matplotlib import pyplot as plt
import numpy as np
from Utils import celcius
import plotly.express as px
def Viz(data, time) -> None:
altitudes = data[:, 0] * 1e-3
speed = data[:, 1]
volume = data[:, 2]
lats = data[:, 3]
lngs = data[:, 4]
volumes = data[:, 5]
buoyancy = data[:, 6]
drag = data[:, 7]
acceleration = data[:, 8]
weights = data[:, 9]
temperature = data[:, 10]
pressure = data[:, 11]
density = data[:, 12]
time_step = time[1] - time[0]
minutes = time / 60
def find_burst(x: list[float], y: list[float]):
i = 1
current = y[i]
previous = y[i-1]
while(current > previous and i < len(y)):
current = y[i]
previous = y[i-1]
i += 1
return (x[i], y[i], i)
burst_time, burst_altitude, i = find_burst(minutes, altitudes)
print(f"Burst: {burst_time:.2f}min, {burst_altitude:.2f}km")
fig = plt.figure(figsize=(14, 8))
fig.suptitle('Simulation Results', fontsize=16)
ax = plt.subplot(3, 3, 1)
if burst_time > minutes[1]:
print(f"Calculating Linear Aproximation...")
coefs = np.polyfit(minutes[:i//2], altitudes[:i//2], 1)
line = np.poly1d(coefs)
linear_burst_time = (burst_altitude - coefs[1]) / coefs[0]
print(
f"Linear Approx. Burst: {linear_burst_time:.2f}min, {line(linear_burst_time):.2f}km")
i = int(linear_burst_time / time_step * 60)
plt.plot(minutes, altitudes, linewidth=2,
color="black", label='Altitude ($h$)')
plt.plot(minutes[:i], line(minutes[:i]), color='red')
plt.ylabel("Altitude (km)")
plt.grid()
plt.subplot(3, 3, 2, sharex=ax)
plt.plot(minutes, volume, linewidth=2,
color="blue", label="Gas Mass ($h$)")
plt.ylabel("Volume ($m^3$)")
plt.grid()
plt.subplot(3, 3, 3, sharex=ax)
plt.plot(minutes, speed, linewidth=2, color="orange",
label="Ascent Rate ($\dot h$)")
plt.ylabel("Speed (m/s)")
plt.grid()
plt.subplot(3, 3, 5, sharex=ax)
plt.plot(minutes, buoyancy, linewidth=2,
color="red", label="Buoyancy ($B$)")
plt.plot(minutes, drag, linewidth=2, color="green", label="Drag ($D$)")
plt.plot(minutes, weights, linewidth=2,
color="yellow", label="Weight ($W$)")
plt.ylabel("Force (N)")
plt.grid()
plt.subplot(3, 3, 4, sharex=ax)
plt.plot(minutes, acceleration, linewidth=2,
color="purple", label="Acc. ($\ddot h$)")
plt.ylabel("Acceleration ($m/s^2$)")
plt.grid()
ax2 = plt.subplot(3, 3, 6, sharex=ax)
plt.plot(minutes, volumes, linewidth=2,
color="blue", label="Volume ($V_{B}$)")
plt.ylabel("Volume ($m^3$)")
plt.grid()
plt.subplot(3, 3, 7, sharex=ax)
plt.plot(minutes, celcius(temperature))
plt.legend(["Temperature"])
plt.ylabel("Temperature (°C)")
plt.xlabel("Time (minutes)")
plt.grid()
plt.subplot(3, 3, 8, sharex=ax)
plt.plot(minutes, density)
plt.legend(["Density"])
plt.ylabel("Density ($kg/m^3$)")
plt.xlabel("Time (minutes)")
plt.grid()
plt.subplot(3, 3, 9, sharex=ax)
plt.plot(minutes, pressure*1e-2)
plt.legend(["Pressure"])
plt.xlabel("Time (min)")
plt.ylabel("Pressure (kPa)")
plt.grid()
fig = px.line_mapbox(lat=lats, lon=lngs, zoom=3, mapbox_style='open-street-map', height=300)
fig.show()
plt.show()