-
Notifications
You must be signed in to change notification settings - Fork 2
/
span_vs_mission_analysis.py
252 lines (231 loc) · 5.54 KB
/
span_vs_mission_analysis.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
from aerosandbox.tools.pretty_plots import plt, sns, mpl, show_plot
import aerosandbox.numpy as np
from scipy import interpolate
import pandas as pd
run_name = "30kg_payload"
# run_name = "10kg_payload"
# run_name = "10kg_payload_continuous_power"
# run_name = "10kg_payload_no_cycling"
# run_name = "10kg_payload_sunpower"
# run_name = "10kg_payload_ascent"
# run_name = "10kg_payload_350_batteries"
# run_name = "10kg_payload_400_batteries"
# run_name = "10kg_payload_500_batteries"
# run_name = "6kg_payload_100W"
debug_mode = False
# Do raw imports
data = pd.read_csv(f"cache/{run_name}.csv")
data.columns = data.columns.str.strip()
days_raw = np.array(data['Days'], dtype=float)
lats_raw = np.array(data['Latitudes'], dtype=float)
spans_raw = np.array(data['Spans'], dtype=float)
# # Transfer to a grid
# res_y = np.sum(np.diff(lats_raw) < 0) + 1
# res_x = len(lats_raw) // res_y
# lats_grid = lats_raw[:res_x]
# days_grid = days_raw[::res_x]
# spans_grid = spans_raw.reshape((res_y, res_x)).T
# assert len(lats_grid) * len(days_grid) == np.product(spans_raw.shape)
#
# # Patch NaNs
# from interpolate_utils import bridge_nans
#
# bridge_nans(spans_grid, depth=2)
#
# Add dummy points
bad_points = [
(0, 80),
(0, 70),
(365, 80),
(365, 70),
(244, -80),
(244, -70),
]
for p in bad_points:
days_raw = np.append(days_raw, p[0])
lats_raw = np.append(lats_raw, p[1])
spans_raw = np.append(spans_raw, 1000)
# # Filter by nan
nan = np.isnan(spans_raw)
# infeasible_value = 100 # Value to assign to NaNs and worse-than-this points
# spans_raw[nan] = infeasible_value
# spans_raw[spans_raw > infeasible_value] = infeasible_value
# nan = np.isnan(spans_raw)
rbf = interpolate.RBFInterpolator(
np.vstack((
days_raw[~nan],
lats_raw[~nan],
)).T,
spans_raw[~nan],
smoothing=50,
)
days_plot = np.linspace(0, 365, 300)
lats_plot = np.linspace(-80, 80, 200)
# Convert to 2D arrays
Days_plot, Lats_plot = np.meshgrid(days_plot, lats_plot)
Spans = rbf(
np.vstack((
Days_plot.flatten(),
Lats_plot.flatten()
)).T
).reshape(Days_plot.shape)
### Payload plot
fig, ax = plt.subplots(1, 1, figsize=(8, 6), dpi=200)
args = [
Days_plot,
Lats_plot,
Spans,
]
kwargs = {
"levels": np.arange(20, 50.1, 2),
"alpha" : 0.7,
"extend": "both",
}
viridis = mpl.cm.get_cmap('viridis_r', 256)
newcolors = viridis(np.linspace(0, 1, 256))
newcolors[-1, :] = np.array([0, 0, 0, 1])
newcmp = mpl.colors.ListedColormap(newcolors)
CS = plt.contour(*args, **kwargs, colors="k", linewidths=0.5)
CF = plt.contourf(*args, **kwargs, cmap=newcmp)
cbar = plt.colorbar(label="Wing Span [m]", extendrect=True)
ax.clabel(CS, inline=1, fontsize=10, fmt="%.0f m")
### Does unstructured linear interpolation; useful for checking RBF accuracy.
# args = [
# days_raw[~nan],
# lats_raw[~nan],
# spans_raw[~nan]
# ]
# CS = plt.tricontour(*args, **kwargs, colors="k", linewidths=0.5)
# CF = plt.tricontourf(*args, **kwargs, cmap=newcmp)
# cbar = plt.colorbar(label="Wing Span [m]", extendrect=True)
# ax.clabel(CS, inline=1, fontsize=10, fmt="%.0f m")
### Plots the location of raw data points. Useful for debugging.
if debug_mode:
plt.scatter(
days_raw[~nan],
lats_raw[~nan],
c=spans_raw[~nan],
cmap=newcmp,
edgecolor="w",
zorder=4
)
plt.clim(*CS.get_clim())
### Plots the region of interest (arctic ice)
# ax.add_patch(
# plt.Rectangle(
# (1, -80),
# width=(55),
# height=(20),
# linestyle="--",
# color="k",
# linewidth=1,
# fill=False
# )
# )
# ax.add_patch(
# plt.Rectangle(
# (365-22, -80),
# width=(20),
# height=(20),
# linestyle="--",
# color="k",
# linewidth=1,
# fill=False
# )
# )
#
# ax.add_patch(
# plt.Rectangle(
# (115, 60),
# width=(130),
# height=(20),
# linestyle="--",
# color="k",
# linewidth=1,
# fill=False
# )
# )
### Plots the region of interest (CONUS)
plt.plot(
244,
26,
".--k",
label="Region of Interest\n& Sizing Case",
)
ax.add_patch(
plt.Rectangle(
(152, 26),
width=(244 - 152),
height=(49 - 26),
linestyle="--",
color="k",
linewidth=1,
fill=False
)
)
# ### Plot the region of interest (hurricane)
# ax.add_patch(
# plt.Rectangle(
# (212, 5),
# width=(90),
# height=(45),
# linestyle="--",
# color="k",
# linewidth=1,
# fill=False
# )
# )
#
# plt.annotate(
# text="Infeasible",
# xy=(174, -55),
# xycoords="data",
# ha="center",
# fontsize=10,
# color='w',
# )
plt.xticks(
np.linspace(0, 365, 13)[:-1],
(
"Jan. 1",
"Feb. 1",
"Mar. 1",
"Apr. 1",
"May 1",
"June 1",
"July 1",
"Aug. 1",
"Sep. 1",
"Oct. 1",
"Nov. 1",
"Dec. 1"
),
rotation=40
)
lat_label_vals = np.arange(-80, 80.1, 20)
lat_labels = []
for lat in lat_label_vals:
if lat >= 0:
lat_labels.append(f"{lat:.0f}N")
else:
lat_labels.append(f"{-lat:.0f}S")
plt.yticks(
lat_label_vals,
lat_labels
)
plt.suptitle(
"Minimum Wingspan Airplane by Mission",
y=0.98
)
plt.title(
"\n".join([
"30 kg payload, min alt set by strat height, 450 Wh/kg batteries,",
"Microlink solar cells, station-keeping in 95% wind"
]),
fontsize=10
)
show_plot(
xlabel="Time of Year",
ylabel="Latitude",
show=True,
)