Skip to content

Commit 145e4c5

Browse files
Merge
2 parents 2ceca6a + 4e40c42 commit 145e4c5

8 files changed

+62677
-181
lines changed
Binary file not shown.
Binary file not shown.

docs/notebooks/environment_analysis_EuroC_example.ipynb

Lines changed: 62310 additions & 0 deletions
Large diffs are not rendered by default.

docs/user/requirements.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The following packages are needed in order to run RocketPy:
2727
- timezonefinder
2828
- simplekml
2929
- ipywidgets >= 7.6.3
30-
- json
30+
- jsonpickle
3131

3232

3333
All of these packages, with the exception of netCDF4, should be automatically installed when RocketPy is installed using either ``pip`` or ``conda``.
@@ -50,6 +50,7 @@ The packages needed can be installed via ``pip`` by running the following lines
5050
pip install pytz
5151
pip install timezonefinder
5252
pip install simplekml
53+
pip install jsonpickle
5354
5455
Installing Required Packages Using ``conda``
5556
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ requests
88
pytz
99
timezonefinder
1010
simplekml
11-
json
11+
jsonpickle

rocketpy/EnvironmentAnalysis.py

Lines changed: 229 additions & 178 deletions
Large diffs are not rendered by default.

rocketpy/utilities.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
__copyright__ = "Copyright 20XX, RocketPy Team"
44
__license__ = "MIT"
55

6+
import matplotlib.pyplot as plt
67
import numpy as np
78
from scipy.integrate import solve_ivp
89

910
from .Environment import Environment
11+
from .EnvironmentAnalysis import EnvironmentAnalysis
1012
from .Function import Function
1113

1214

@@ -197,3 +199,135 @@ def du(z, u):
197199
velocityFunction()
198200

199201
return altitudeFunction, velocityFunction, final_sol
202+
203+
204+
def compareEnvironments(env1, env2, names=["env1", "env2"]):
205+
"""Compares two environments and plots everything.
206+
Useful when comparing Environment Analysis results against forecasts.
207+
208+
Parameters
209+
----------
210+
env1 : Environment or EnvironmentAnalysis
211+
Environment to compare with.
212+
env2: Environment or EnvironmentAnalysis
213+
Environment to compare with.
214+
215+
Returns
216+
-------
217+
diff: Dict
218+
Dictionary with the differences.
219+
"""
220+
221+
# Raise TypeError if env1 or env2 are not Environment nor EnvironmentAnalysis
222+
if not isinstance(env1, Environment) and not isinstance(env1, EnvironmentAnalysis):
223+
raise TypeError("env1 must be an Environment or EnvironmentAnalysis object")
224+
225+
if not isinstance(env2, Environment) and not isinstance(env2, EnvironmentAnalysis):
226+
raise TypeError("env2 must be an Environment or EnvironmentAnalysis object")
227+
228+
# If instances are Environment Analysis, get the equivalent environment
229+
if isinstance(env1, EnvironmentAnalysis):
230+
env1.process_temperature_profile_over_average_day()
231+
env1.process_pressure_profile_over_average_day()
232+
env1.process_wind_velocity_x_profile_over_average_day()
233+
env1.process_wind_velocity_y_profile_over_average_day()
234+
print()
235+
if isinstance(env2, EnvironmentAnalysis):
236+
env2.process_temperature_profile_over_average_day()
237+
env2.process_pressure_profile_over_average_day()
238+
env2.process_wind_velocity_x_profile_over_average_day()
239+
env2.process_wind_velocity_y_profile_over_average_day()
240+
print()
241+
242+
# Plot graphs
243+
print("\n\nAtmospheric Model Plots")
244+
# Create height grid
245+
grid = np.linspace(env1.elevation, env1.maxExpectedHeight)
246+
247+
# Create figure
248+
plt.figure(figsize=(9, 9))
249+
250+
# Create wind speed and wind direction subplot
251+
ax1 = plt.subplot(221)
252+
ax1.plot(
253+
[env1.windSpeed(i) for i in grid],
254+
grid,
255+
"#ff7f0e",
256+
label="Speed of Sound " + names[0],
257+
)
258+
ax1.plot(
259+
[env2.windSpeed(i) for i in grid],
260+
grid,
261+
"#ff7f0e",
262+
label="Speed of Sound " + names[1],
263+
)
264+
ax1.set_xlabel("Wind Speed (m/s)", color="#ff7f0e")
265+
ax1.tick_params("x", colors="#ff7f0e")
266+
# ax1up = ax1.twiny()
267+
# ax1up.plot(
268+
# [env1.windDirection(i) for i in grid],
269+
# grid,
270+
# color="#1f77b4",
271+
# label="Density "+names[0],
272+
# )
273+
# ax1up.plot(
274+
# [env2.windDirection(i) for i in grid],
275+
# grid,
276+
# color="#1f77b4",
277+
# label="Density "+names[1],
278+
# )
279+
# ax1up.set_xlabel("Wind Direction (°)", color="#1f77b4")
280+
# ax1up.tick_params("x", colors="#1f77b4")
281+
# ax1up.set_xlim(0, 360)
282+
ax1.set_ylabel("Height Above Sea Level (m)")
283+
ax1.grid(True)
284+
285+
# # Create density and speed of sound subplot
286+
# ax2 = plt.subplot(222)
287+
# ax2.plot(
288+
# [env1.speedOfSound(i) for i in grid],
289+
# grid,
290+
# "#ff7f0e",
291+
# label="Speed of Sound",
292+
# )
293+
# ax2.set_xlabel("Speed of Sound (m/s)", color="#ff7f0e")
294+
# ax2.tick_params("x", colors="#ff7f0e")
295+
# ax2up = ax2.twiny()
296+
# ax2up.plot([env1.density(i) for i in grid], grid, color="#1f77b4", label="Density")
297+
# ax2up.set_xlabel("Density (kg/m³)", color="#1f77b4")
298+
# ax2up.tick_params("x", colors="#1f77b4")
299+
# ax2.set_ylabel("Height Above Sea Level (m)")
300+
# ax2.grid(True)
301+
302+
# Create wind u and wind v subplot
303+
ax3 = plt.subplot(223)
304+
ax3.plot([env1.windVelocityX(i) for i in grid], grid, label="Wind U " + names[0])
305+
ax3.plot([env1.windVelocityY(i) for i in grid], grid, label="Wind V " + names[0])
306+
ax3.plot([env2.windVelocityX(i) for i in grid], grid, label="Wind U " + names[1])
307+
ax3.plot([env2.windVelocityY(i) for i in grid], grid, label="Wind V " + names[1])
308+
ax3.legend(loc="best").set_draggable(True)
309+
ax3.set_ylabel("Height Above Sea Level (m)")
310+
ax3.set_xlabel("Wind Speed (m/s)")
311+
ax3.grid(True)
312+
313+
# Create pressure and temperature subplot
314+
ax4 = plt.subplot(224)
315+
ax4.plot([env1.pressure(i) / 100 for i in grid], grid, "#ff7f0e", label="Pressure")
316+
ax4.set_xlabel("Pressure (hPa)", color="#ff7f0e")
317+
ax4.tick_params("x", colors="#ff7f0e")
318+
ax4up = ax4.twiny()
319+
ax4up.plot(
320+
[env1.temperature(i) for i in grid],
321+
grid,
322+
color="#1f77b4",
323+
label="Temperature",
324+
)
325+
ax4up.set_xlabel("Temperature (K)", color="#1f77b4")
326+
ax4up.tick_params("x", colors="#1f77b4")
327+
ax4.set_ylabel("Height Above Sea Level (m)")
328+
ax4.grid(True)
329+
330+
plt.subplots_adjust(wspace=0.5, hspace=0.3)
331+
plt.show()
332+
333+
return None # diff

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"pytz",
1717
"timezonefinder",
1818
"simplekml",
19-
"json",
19+
"jsonpickle",
2020
],
2121
maintainer="RocketPy Developers",
2222
author="Giovani Hidalgo Ceotto",

0 commit comments

Comments
 (0)