Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
junzis
GitHub Repository: junzis/openap
Path: blob/master/test/test_trajectory.py
532 views
1
# %%
2
import matplotlib.pyplot as plt
3
4
from openap import FlightGenerator, aero
5
6
# %%
7
flightgen = FlightGenerator(ac="a320")
8
# flightgen.enable_noise()
9
10
fig, ax = plt.subplots(2, 2, figsize=(12, 6))
11
plt.suptitle("Climb trajectories")
12
for i in range(5):
13
data = flightgen.climb(dt=10, random=True)
14
ax[0][0].plot(
15
data["t"],
16
data["h"] / aero.ft,
17
label="%d/%.2f" % (data["cas_const_cl"].iloc[0], data["mach_const_cl"].iloc[0]),
18
)
19
ax[0][0].set_ylabel("Altitude (ft)")
20
ax[0][1].plot(data["t"], data["s"] / 1000)
21
ax[0][1].set_ylabel("Distanse (km)")
22
ax[1][0].plot(data["t"], data["v"] / aero.kts)
23
ax[1][0].set_ylabel("True airspeed (kt)")
24
ax[1][1].plot(data["t"], data["vs"] / aero.fpm)
25
ax[1][1].set_ylabel("Vertical rate (ft/min)")
26
ax[0][0].legend()
27
plt.show()
28
29
# %%
30
fig, ax = plt.subplots(2, 2, figsize=(12, 6))
31
plt.suptitle("Descent trajectories")
32
for i in range(5):
33
data = flightgen.descent(dt=10, random=True)
34
ax[0][0].plot(
35
data["t"],
36
data["h"] / aero.ft,
37
label="%d/%.2f" % (data["cas_const_de"].iloc[0], data["mach_const_de"].iloc[0]),
38
)
39
ax[0][0].set_ylabel("Altitude (ft)")
40
ax[0][1].plot(data["t"], data["s"] / 1000)
41
ax[0][1].set_ylabel("Distanse (km)")
42
ax[1][0].plot(data["t"], data["v"] / aero.kts)
43
ax[1][0].set_ylabel("True airspeed (kt)")
44
ax[1][1].plot(data["t"], data["vs"] / aero.fpm)
45
ax[1][1].set_ylabel("Vertical rate (ft/min)")
46
ax[0][0].legend()
47
plt.show()
48
49
# %%
50
fig, ax = plt.subplots(2, 2, figsize=(12, 6))
51
plt.suptitle("Cruise trajectories")
52
for i in range(5):
53
data = flightgen.cruise(dt=60, random=True)
54
ax[0][0].plot(data["t"], data["h"] / aero.ft, label="%d" % data["alt_cr"].iloc[0])
55
ax[0][0].set_ylabel("Altitude (ft)")
56
ax[0][1].plot(data["t"], data["s"] / 1000)
57
ax[0][1].set_ylabel("Distanse (km)")
58
ax[1][0].plot(data["t"], data["v"] / aero.kts)
59
ax[1][0].set_ylabel("True airspeed (kt)")
60
ax[1][1].plot(data["t"], data["vs"] / aero.fpm)
61
ax[1][1].set_ylabel("Vertical rate (ft/min)")
62
ax[0][0].legend()
63
plt.show()
64
65
# %%
66
67
fig, ax = plt.subplots(2, 2, figsize=(12, 6))
68
plt.suptitle("Complete trajectories")
69
for i in range(5):
70
data = flightgen.complete(dt=10, random=True)
71
ax[0][0].plot(data["t"], data["h"] / aero.ft)
72
ax[0][0].set_ylabel("Altitude (ft)")
73
ax[0][1].plot(data["t"], data["s"] / 1000)
74
ax[0][1].set_ylabel("Distanse (km)")
75
ax[1][0].plot(data["t"], data["v"] / aero.kts)
76
ax[1][0].set_ylabel("True airspeed (kt)")
77
ax[1][1].plot(data["t"], data["vs"] / aero.fpm)
78
ax[1][1].set_ylabel("Vertical rate (ft/min)")
79
plt.show()
80
81
# %%
82
83