Skip to content

Commit 483d9cf

Browse files
Merge pull request #326 from RocketPy-Team/maint/extract-logic-prints-env
MAINT: move last plots from Environment class
2 parents d8d3b03 + 5d62399 commit 483d9cf

File tree

3 files changed

+155
-111
lines changed

3 files changed

+155
-111
lines changed

rocketpy/Environment.py

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import warnings
1313
from datetime import datetime, timedelta
1414

15-
import matplotlib.pyplot as plt
1615
import numpy as np
1716
import numpy.ma as ma
1817
import pytz
@@ -3022,58 +3021,8 @@ def info(self):
30223021
None
30233022
"""
30243023

3025-
# All prints
30263024
self.prints.all()
3027-
3028-
# Plot graphs
3029-
print("\n\nAtmospheric Model Plots")
3030-
# Create height grid
3031-
grid = np.linspace(self.elevation, self.maxExpectedHeight)
3032-
3033-
# Create figure
3034-
plt.figure(figsize=(9, 4.5))
3035-
3036-
# Create wind speed and wind direction subplot
3037-
ax1 = plt.subplot(121)
3038-
ax1.plot(
3039-
[self.windSpeed(i) for i in grid], grid, "#ff7f0e", label="Speed of Sound"
3040-
)
3041-
ax1.set_xlabel("Wind Speed (m/s)", color="#ff7f0e")
3042-
ax1.tick_params("x", colors="#ff7f0e")
3043-
ax1up = ax1.twiny()
3044-
ax1up.plot(
3045-
[self.windDirection(i) for i in grid],
3046-
grid,
3047-
color="#1f77b4",
3048-
label="Density",
3049-
)
3050-
ax1up.set_xlabel("Wind Direction (°)", color="#1f77b4")
3051-
ax1up.tick_params("x", colors="#1f77b4")
3052-
ax1up.set_xlim(0, 360)
3053-
ax1.set_ylabel("Height Above Sea Level (m)")
3054-
ax1.grid(True)
3055-
3056-
# Create density and speed of sound subplot
3057-
ax2 = plt.subplot(122)
3058-
ax2.plot(
3059-
[self.speedOfSound(i) for i in grid],
3060-
grid,
3061-
"#ff7f0e",
3062-
label="Speed of Sound",
3063-
)
3064-
ax2.set_xlabel("Speed of Sound (m/s)", color="#ff7f0e")
3065-
ax2.tick_params("x", colors="#ff7f0e")
3066-
ax2up = ax2.twiny()
3067-
ax2up.plot(
3068-
[self.density(i) for i in grid], grid, color="#1f77b4", label="Density"
3069-
)
3070-
ax2up.set_xlabel("Density (kg/m³)", color="#1f77b4")
3071-
ax2up.tick_params("x", colors="#1f77b4")
3072-
ax2.set_ylabel("Height Above Sea Level (m)")
3073-
ax2.grid(True)
3074-
3075-
plt.subplots_adjust(wspace=0.5)
3076-
plt.show()
3025+
self.plots.info()
30773026
return None
30783027

30793028
def allInfo(self):

rocketpy/Parachute.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,11 @@ def __str__(self):
141141
)
142142

143143
def info(self):
144-
145144
self.prints.all()
146145

147146
return None
148147

149148
def allInfo(self):
150-
151149
self.info()
152150
# self.plots.all() # Parachutes still doesn't have plots
153151

rocketpy/plots/environment_plots.py

Lines changed: 154 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__author__ = "Mateus Stano Junqueira"
1+
__author__ = "Mateus Stano Junqueira, Guilherme Fernandes Alves"
22
__copyright__ = "Copyright 20XX, RocketPy Team"
33
__license__ = "MIT"
44

@@ -39,112 +39,184 @@ def __init__(self, environment):
3939

4040
return None
4141

42-
def atmospheric_model(self):
43-
"""Plots all atmospheric model graphs available
42+
def __wind(self, ax):
43+
"""Adds wind speed and wind direction graphs to the same axis.
4444
4545
Parameters
4646
----------
47-
None
47+
ax : matplotlib.pyplot.axis
48+
Axis to add the graphs.
4849
49-
Return
50-
------
51-
None
50+
Returns
51+
-------
52+
ax : matplotlib.pyplot.axis
53+
Axis with the graphs.
5254
"""
53-
54-
# Create figure
55-
plt.figure(figsize=(9, 9))
56-
57-
# Create wind speed and wind direction subplot
58-
ax1 = plt.subplot(221)
59-
ax1.plot(
55+
ax.plot(
6056
[self.environment.windSpeed(i) for i in self.grid],
6157
self.grid,
6258
"#ff7f0e",
63-
label="Speed of Sound",
59+
label="Wind Speed",
6460
)
65-
ax1.set_xlabel("Wind Speed (m/s)", color="#ff7f0e")
66-
ax1.tick_params("x", colors="#ff7f0e")
67-
ax1up = ax1.twiny()
68-
ax1up.plot(
61+
ax.set_xlabel("Wind Speed (m/s)", color="#ff7f0e")
62+
ax.tick_params("x", colors="#ff7f0e")
63+
axup = ax.twiny()
64+
axup.plot(
6965
[self.environment.windDirection(i) for i in self.grid],
7066
self.grid,
7167
color="#1f77b4",
72-
label="Density",
68+
label="Wind Direction",
7369
)
74-
ax1up.set_xlabel("Wind Direction (°)", color="#1f77b4")
75-
ax1up.tick_params("x", colors="#1f77b4")
76-
ax1up.set_xlim(0, 360)
77-
ax1.set_ylabel("Height Above Sea Level (m)")
78-
ax1.grid(True)
70+
axup.set_xlabel("Wind Direction (°)", color="#1f77b4")
71+
axup.tick_params("x", colors="#1f77b4")
72+
axup.set_xlim(0, 360)
73+
ax.set_ylabel("Height Above Sea Level (m)")
74+
ax.grid(True)
7975

80-
# Create density and speed of sound subplot
81-
ax2 = plt.subplot(222)
82-
ax2.plot(
76+
return ax
77+
78+
def __density_speed_of_sound(self, ax):
79+
"""Adds density and speed of sound graphs to the same axis.
80+
81+
Parameters
82+
----------
83+
ax : matplotlib.pyplot.axis
84+
Axis to add the graphs.
85+
86+
Returns
87+
-------
88+
ax : matplotlib.pyplot.axis
89+
Axis with the graphs.
90+
"""
91+
ax.plot(
8392
[self.environment.speedOfSound(i) for i in self.grid],
8493
self.grid,
8594
"#ff7f0e",
8695
label="Speed of Sound",
8796
)
88-
ax2.set_xlabel("Speed of Sound (m/s)", color="#ff7f0e")
89-
ax2.tick_params("x", colors="#ff7f0e")
90-
ax2up = ax2.twiny()
91-
ax2up.plot(
97+
ax.set_xlabel("Speed of Sound (m/s)", color="#ff7f0e")
98+
ax.tick_params("x", colors="#ff7f0e")
99+
axup = ax.twiny()
100+
axup.plot(
92101
[self.environment.density(i) for i in self.grid],
93102
self.grid,
94103
color="#1f77b4",
95104
label="Density",
96105
)
97-
ax2up.set_xlabel("Density (kg/m³)", color="#1f77b4")
98-
ax2up.tick_params("x", colors="#1f77b4")
99-
ax2.set_ylabel("Height Above Sea Level (m)")
100-
ax2.grid(True)
106+
axup.set_xlabel("Density (kg/m³)", color="#1f77b4")
107+
axup.tick_params("x", colors="#1f77b4")
108+
ax.set_ylabel("Height Above Sea Level (m)")
109+
ax.grid(True)
101110

102-
# Create wind u and wind v subplot
103-
ax3 = plt.subplot(223)
104-
ax3.plot(
111+
return ax
112+
113+
def __wind_components(self, ax):
114+
"""Adds wind u and wind v graphs to the same axis.
115+
116+
Parameters
117+
----------
118+
ax : matplotlib.pyplot.axis
119+
Axis to add the graphs.
120+
121+
Returns
122+
-------
123+
ax : matplotlib.pyplot.axis
124+
Axis with the graphs.
125+
"""
126+
ax.plot(
105127
[self.environment.windVelocityX(i) for i in self.grid],
106128
self.grid,
107129
label="Wind U",
108130
)
109-
ax3.plot(
131+
ax.plot(
110132
[self.environment.windVelocityY(i) for i in self.grid],
111133
self.grid,
112134
label="Wind V",
113135
)
114-
ax3.legend(loc="best").set_draggable(True)
115-
ax3.set_ylabel("Height Above Sea Level (m)")
116-
ax3.set_xlabel("Wind Speed (m/s)")
117-
ax3.grid(True)
136+
ax.legend(loc="best").set_draggable(True)
137+
ax.set_ylabel("Height Above Sea Level (m)")
138+
ax.set_xlabel("Wind Speed (m/s)")
139+
ax.grid(True)
118140

119-
# Create pressure and temperature subplot
120-
ax4 = plt.subplot(224)
121-
ax4.plot(
141+
return ax
142+
143+
def __pressure_temperature(self, ax):
144+
"""Adds pressure and temperature graphs to the same axis.
145+
146+
Parameters
147+
----------
148+
ax : matplotlib.pyplot.axis
149+
Axis to add the graphs.
150+
151+
Returns
152+
-------
153+
ax : matplotlib.pyplot.axis
154+
Axis with the graphs.
155+
"""
156+
ax.plot(
122157
[self.environment.pressure(i) / 100 for i in self.grid],
123158
self.grid,
124159
"#ff7f0e",
125160
label="Pressure",
126161
)
127-
ax4.set_xlabel("Pressure (hPa)", color="#ff7f0e")
128-
ax4.tick_params("x", colors="#ff7f0e")
129-
ax4up = ax4.twiny()
130-
ax4up.plot(
162+
ax.set_xlabel("Pressure (hPa)", color="#ff7f0e")
163+
ax.tick_params("x", colors="#ff7f0e")
164+
axup = ax.twiny()
165+
axup.plot(
131166
[self.environment.temperature(i) for i in self.grid],
132167
self.grid,
133168
color="#1f77b4",
134169
label="Temperature",
135170
)
136-
ax4up.set_xlabel("Temperature (K)", color="#1f77b4")
137-
ax4up.tick_params("x", colors="#1f77b4")
138-
ax4.set_ylabel("Height Above Sea Level (m)")
139-
ax4.grid(True)
171+
axup.set_xlabel("Temperature (K)", color="#1f77b4")
172+
axup.tick_params("x", colors="#1f77b4")
173+
ax.set_ylabel("Height Above Sea Level (m)")
174+
ax.grid(True)
175+
176+
return ax
177+
178+
def atmospheric_model(self):
179+
"""Plots all atmospheric model graphs available. This includes wind speed
180+
and wind direction, density and speed of sound, wind u and wind v, and
181+
pressure and temperature.
182+
183+
Parameters
184+
----------
185+
None
186+
187+
Return
188+
------
189+
None
190+
"""
191+
192+
# Create figure
193+
plt.figure(figsize=(9, 9))
194+
195+
# Create wind speed and wind direction subplot
196+
ax1 = plt.subplot(221)
197+
ax1 = self.__wind(ax1)
198+
199+
# Create density and speed of sound subplot
200+
ax2 = plt.subplot(222)
201+
ax2 = self.__density_speed_of_sound(ax2)
202+
203+
# Create wind u and wind v subplot
204+
ax3 = plt.subplot(223)
205+
ax3 = self.__wind_components(ax3)
206+
ax3.legend(loc="best").set_draggable(True)
207+
208+
# Create pressure and temperature subplot
209+
ax4 = plt.subplot(224)
210+
ax4 = self.__pressure_temperature(ax4)
140211

141212
plt.subplots_adjust(wspace=0.5, hspace=0.3)
142213
plt.show()
143214

144215
return None
145216

146217
def ensemble_member_comparison(self):
147-
"""Plots ensemble member comparisons.
218+
"""Plots ensemble member comparisons. It requires that the environment
219+
model has been set as Ensemble.
148220
149221
Parameters
150222
----------
@@ -253,8 +325,33 @@ def ensemble_member_comparison(self):
253325

254326
return None
255327

328+
def info(self):
329+
"""Plots a summary of the atmospheric model, including wind speed and
330+
wind direction, density and speed of sound. This is important for the
331+
Environment.info() method.
332+
333+
Returns
334+
-------
335+
None
336+
"""
337+
print("\nAtmospheric Model Plots\n")
338+
plt.figure(figsize=(9, 4.5))
339+
# Create wind speed and wind direction subplot
340+
ax1 = plt.subplot(121)
341+
ax1 = self.__wind(ax1)
342+
343+
# Create density and speed of sound subplot
344+
ax2 = plt.subplot(122)
345+
ax2 = self.__density_speed_of_sound(ax2)
346+
347+
plt.subplots_adjust(wspace=0.5)
348+
plt.show()
349+
return None
350+
256351
def all(self):
257-
"""Prints out all graphs available about the Environment.
352+
"""Prints out all graphs available about the Environment. This includes
353+
a complete description of the atmospheric model and the ensemble members
354+
comparison if the atmospheric model is an ensemble.
258355
259356
Parameters
260357
----------

0 commit comments

Comments
 (0)