|
1 |
| -__author__ = "Mateus Stano Junqueira" |
| 1 | +__author__ = "Mateus Stano Junqueira, Guilherme Fernandes Alves" |
2 | 2 | __copyright__ = "Copyright 20XX, RocketPy Team"
|
3 | 3 | __license__ = "MIT"
|
4 | 4 |
|
@@ -39,112 +39,184 @@ def __init__(self, environment):
|
39 | 39 |
|
40 | 40 | return None
|
41 | 41 |
|
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. |
44 | 44 |
|
45 | 45 | Parameters
|
46 | 46 | ----------
|
47 |
| - None |
| 47 | + ax : matplotlib.pyplot.axis |
| 48 | + Axis to add the graphs. |
48 | 49 |
|
49 |
| - Return |
50 |
| - ------ |
51 |
| - None |
| 50 | + Returns |
| 51 | + ------- |
| 52 | + ax : matplotlib.pyplot.axis |
| 53 | + Axis with the graphs. |
52 | 54 | """
|
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( |
60 | 56 | [self.environment.windSpeed(i) for i in self.grid],
|
61 | 57 | self.grid,
|
62 | 58 | "#ff7f0e",
|
63 |
| - label="Speed of Sound", |
| 59 | + label="Wind Speed", |
64 | 60 | )
|
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( |
69 | 65 | [self.environment.windDirection(i) for i in self.grid],
|
70 | 66 | self.grid,
|
71 | 67 | color="#1f77b4",
|
72 |
| - label="Density", |
| 68 | + label="Wind Direction", |
73 | 69 | )
|
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) |
79 | 75 |
|
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( |
83 | 92 | [self.environment.speedOfSound(i) for i in self.grid],
|
84 | 93 | self.grid,
|
85 | 94 | "#ff7f0e",
|
86 | 95 | label="Speed of Sound",
|
87 | 96 | )
|
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( |
92 | 101 | [self.environment.density(i) for i in self.grid],
|
93 | 102 | self.grid,
|
94 | 103 | color="#1f77b4",
|
95 | 104 | label="Density",
|
96 | 105 | )
|
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) |
101 | 110 |
|
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( |
105 | 127 | [self.environment.windVelocityX(i) for i in self.grid],
|
106 | 128 | self.grid,
|
107 | 129 | label="Wind U",
|
108 | 130 | )
|
109 |
| - ax3.plot( |
| 131 | + ax.plot( |
110 | 132 | [self.environment.windVelocityY(i) for i in self.grid],
|
111 | 133 | self.grid,
|
112 | 134 | label="Wind V",
|
113 | 135 | )
|
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) |
118 | 140 |
|
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( |
122 | 157 | [self.environment.pressure(i) / 100 for i in self.grid],
|
123 | 158 | self.grid,
|
124 | 159 | "#ff7f0e",
|
125 | 160 | label="Pressure",
|
126 | 161 | )
|
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( |
131 | 166 | [self.environment.temperature(i) for i in self.grid],
|
132 | 167 | self.grid,
|
133 | 168 | color="#1f77b4",
|
134 | 169 | label="Temperature",
|
135 | 170 | )
|
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) |
140 | 211 |
|
141 | 212 | plt.subplots_adjust(wspace=0.5, hspace=0.3)
|
142 | 213 | plt.show()
|
143 | 214 |
|
144 | 215 | return None
|
145 | 216 |
|
146 | 217 | 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. |
148 | 220 |
|
149 | 221 | Parameters
|
150 | 222 | ----------
|
@@ -253,8 +325,33 @@ def ensemble_member_comparison(self):
|
253 | 325 |
|
254 | 326 | return None
|
255 | 327 |
|
| 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 | + |
256 | 351 | 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. |
258 | 355 |
|
259 | 356 | Parameters
|
260 | 357 | ----------
|
|
0 commit comments