Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
junzis
GitHub Repository: junzis/openap
Path: blob/master/test/test_phase.py
532 views
1
import os
2
3
import matplotlib.pyplot as plt
4
import numpy as np
5
import pandas as pd
6
from openap import FlightPhase
7
8
root = os.path.dirname(os.path.realpath(__file__))
9
10
df = pd.read_csv(root + "/data/flight_phase_test.csv")
11
12
ts = df["ts"].values
13
ts = ts - ts[0]
14
alt = df["alt"].values
15
spd = df["spd"].values
16
roc = df["roc"].values
17
18
ts_ = np.arange(0, ts[-1], 1)
19
alt_ = np.interp(ts_, ts, alt)
20
spd_ = np.interp(ts_, ts, spd)
21
roc_ = np.interp(ts_, ts, roc)
22
23
24
fp = FlightPhase()
25
fp.set_trajectory(ts_, alt_, spd_, roc_)
26
labels = fp.phaselabel()
27
28
29
def test_segment():
30
31
phasecolors = {
32
"GND": "black",
33
"CL": "green",
34
"DE": "blue",
35
"LVL": "cyan",
36
"CR": "purple",
37
"NA": "red",
38
}
39
40
colors = [phasecolors[lbl] for lbl in labels]
41
42
plt.subplot(311)
43
plt.scatter(ts_, alt_, marker=".", c=colors, lw=0)
44
plt.ylabel("altitude (ft)")
45
46
plt.subplot(312)
47
plt.scatter(ts_, spd_, marker=".", c=colors, lw=0)
48
plt.ylabel("speed (kt)")
49
50
plt.subplot(313)
51
plt.scatter(ts_, roc_, marker=".", c=colors, lw=0)
52
plt.ylabel("roc (fpm)")
53
54
plt.show()
55
56
57
def test_phase():
58
idx = fp.flight_phase_indices()
59
60
fig = plt.figure()
61
62
ax = fig.add_subplot(111)
63
plt.plot(ts, alt, color="gray")
64
y0, y1 = ax.get_ylim()
65
for k, v in idx.items():
66
if v is None:
67
continue
68
69
plt.plot([ts_[v], ts_[v]], [y0, y1], label=k)
70
# plt.text(lx, ly, k, ha='center')
71
plt.title("altitude")
72
plt.legend()
73
74
plt.show()
75
76
77
if __name__ == "__main__":
78
test_segment()
79
test_phase()
80
81