Skip to content

Commit 3eeb5a1

Browse files
ENH: improve plots not related to stability
1 parent e70825c commit 3eeb5a1

File tree

6 files changed

+52
-24
lines changed

6 files changed

+52
-24
lines changed

rocketpy/mathutils/function.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,8 @@ def plot2D(
11521152
samples=[30, 30],
11531153
force_data=True,
11541154
disp_type="surface",
1155+
alpha=0.6,
1156+
cmap="viridis",
11551157
):
11561158
"""Plot 2-Dimensional Function, from a lower limit to an upper limit,
11571159
by sampling the Function several times in the interval. The title of
@@ -1185,6 +1187,12 @@ def plot2D(
11851187
disp_type : string, optional
11861188
Display type of plotted graph, which can be surface, wireframe,
11871189
contour, or contourf. Default value is surface.
1190+
alpha : float, optional
1191+
Transparency of plotted graph, which can be a value between 0 and
1192+
1. Default value is 0.6.
1193+
cmap : string, optional
1194+
Colormap of plotted graph, which can be any of the colormaps
1195+
available in matplotlib. Default value is viridis.
11881196
11891197
Returns
11901198
-------
@@ -1221,6 +1229,9 @@ def plot2D(
12211229
mesh = [[mesh_x_flat[i], mesh_y_flat[i]] for i in range(len(mesh_x_flat))]
12221230
# Evaluate function at all mesh nodes and convert it to matrix
12231231
z = np.array(self.get_value(mesh)).reshape(mesh_x.shape)
1232+
z_min, z_max = z.min(), z.max()
1233+
color_map = plt.cm.get_cmap(cmap)
1234+
norm = plt.Normalize(z_min, z_max)
12241235
# Plot function
12251236
if disp_type == "surface":
12261237
surf = axes.plot_surface(
@@ -1229,9 +1240,11 @@ def plot2D(
12291240
z,
12301241
rstride=1,
12311242
cstride=1,
1232-
# cmap=cm.coolwarm,
1243+
cmap=color_map,
12331244
linewidth=0,
1234-
alpha=0.6,
1245+
alpha=alpha,
1246+
vmin=z_min,
1247+
vmax=z_max,
12351248
)
12361249
figure.colorbar(surf)
12371250
elif disp_type == "wireframe":

rocketpy/plots/flight_plots.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,19 +682,11 @@ def fluid_mechanics_data(self):
682682

683683
ax4 = plt.subplot(414)
684684
ax4.plot(self.flight.angle_of_attack[:, 0], self.flight.angle_of_attack[:, 1])
685-
# Make sure bottom and top limits are different
686-
if (
687-
self.flight.out_of_rail_time
688-
* self.flight.angle_of_attack(self.flight.out_of_rail_time)
689-
!= 0
690-
):
691-
ax4.set_xlim(
692-
self.flight.out_of_rail_time, 10 * self.flight.out_of_rail_time + 1
693-
)
694-
ax4.set_ylim(0, self.flight.angle_of_attack(self.flight.out_of_rail_time))
695685
ax4.set_title("Angle of Attack")
696686
ax4.set_xlabel("Time (s)")
697687
ax4.set_ylabel("Angle of Attack (°)")
688+
ax4.set_xlim(self.flight.out_of_rail_time, self.first_event_time)
689+
ax4.set_ylim(0, self.flight.angle_of_attack(self.flight.out_of_rail_time) + 15)
698690
ax4.grid()
699691

700692
plt.subplots_adjust(hspace=0.5)

rocketpy/plots/rocket_plots.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def stability_margin(self):
7878
upper=[2, self.rocket.motor.burn_out_time], # Mach 2 and burnout
7979
samples=[20, 20],
8080
disp_type="surface",
81+
alpha=1,
8182
)
8283

8384
return None
@@ -130,15 +131,31 @@ def all(self):
130131
None
131132
"""
132133

133-
# Show plots
134+
# Mass Plots
134135
print("\nMass Plots")
136+
print("-" * 40)
135137
self.total_mass()
136138
self.reduced_mass()
139+
140+
# Aerodynamics Plots
137141
print("\nAerodynamics Plots")
138-
self.static_margin()
139-
self.stability_margin()
142+
print("-" * 40)
143+
144+
# Drag Plots
145+
print("Drag Plots")
146+
print("-" * 20) # Separator for Drag Plots
140147
self.power_on_drag()
141148
self.power_off_drag()
149+
150+
# Stability Plots
151+
print("\nStability Plots")
152+
print("-" * 20) # Separator for Stability Plots
153+
self.static_margin()
154+
self.stability_margin()
155+
156+
# Thrust-to-Weight Plot
157+
print("\nThrust-to-Weight Plot")
158+
print("-" * 40)
142159
self.thrust_to_weight()
143160

144161
return None

rocketpy/prints/flight_prints.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,19 @@ def impact_conditions(self):
301301
print("\nImpact Conditions\n")
302302
print("X Impact: {:.3f} m".format(self.flight.x_impact))
303303
print("Y Impact: {:.3f} m".format(self.flight.y_impact))
304+
print("Latitude: {:.7f}°".format(self.flight.latitude(self.flight.t_final)))
305+
print(
306+
"Longitude: {:.7f}°".format(self.flight.longitude(self.flight.t_final))
307+
)
304308
print("Time of Impact: {:.3f} s".format(self.flight.t_final))
305309
print("Velocity at Impact: {:.3f} m/s".format(self.flight.impact_velocity))
306310
elif self.flight.terminate_on_apogee is False:
307311
print("End of Simulation")
308-
print("Time: {:.3f} s".format(self.flight.solution[-1][0]))
312+
t_final = self.flight.solution[-1][0]
313+
print("Time: {:.3f} s".format(t_final))
309314
print("Altitude: {:.3f} m".format(self.flight.solution[-1][3]))
315+
print("Latitude: {:.3f}°".format(self.flight.latitude(t_final)))
316+
print("Longitude: {:.3f}°".format(self.flight.longitude(t_final)))
310317

311318
return None
312319

rocketpy/prints/rocket_prints.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def inertia_details(self):
6363
)
6464
)
6565
print(
66-
"Rocket Inertia (with motor, but without propellant) 23: {:.3f} kg*m2".format(
66+
"Rocket Inertia (with motor, but without propellant) 23: {:.3f} kg*m2\n".format(
6767
self.rocket.dry_I_23
6868
)
6969
)
@@ -82,7 +82,7 @@ def rocket_geometrical_parameters(self):
8282
print("Rocket Frontal Area: " + "{:.6f}".format(self.rocket.area) + " m2")
8383
print("\nRocket Distances")
8484
print(
85-
"Rocket Center of Dry Mass - Center of Mass withour Motor: "
85+
"Rocket Center of Dry Mass - Center of Mass without Motor: "
8686
+ "{:.3f} m".format(
8787
abs(
8888
self.rocket.center_of_mass_without_motor
@@ -91,7 +91,7 @@ def rocket_geometrical_parameters(self):
9191
)
9292
)
9393
print(
94-
"Rocket Center of Dry Mass - Nozzle Exit Distance: "
94+
"Rocket Center of Dry Mass - Nozzle Exit: "
9595
+ "{:.3f} m".format(
9696
abs(
9797
self.rocket.center_of_dry_mass_position - self.rocket.motor_position
@@ -109,7 +109,7 @@ def rocket_geometrical_parameters(self):
109109
)
110110
print(
111111
"Rocket Center of Mass - Rocket Loaded Center of Mass: "
112-
+ "{:.3f} m".format(
112+
+ "{:.3f} m\n".format(
113113
abs(
114114
self.rocket.center_of_mass(0)
115115
- self.rocket.center_of_dry_mass_position
@@ -192,18 +192,14 @@ def all(self):
192192
"""
193193
# Print inertia details
194194
self.inertia_details()
195-
print()
196195

197196
# Print rocket geometrical parameters
198197
self.rocket_geometrical_parameters()
199-
print()
200198

201199
# Print rocket aerodynamics quantities
202200
self.rocket_aerodynamics_quantities()
203-
print()
204201

205202
# Print parachute data
206203
self.parachute_data()
207-
print()
208204

209205
return None

rocketpy/rocket/rocket.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def evaluate_total_mass(self):
327327
# Calculate total mass by summing up propellant and dry mass
328328
self.total_mass = self.mass + self.motor.total_mass
329329
self.total_mass.set_outputs("Total Mass (Rocket + Propellant) (kg)")
330+
self.total_mass.set_title("Total Mass (Rocket + Propellant) (kg) x Time (s)")
330331

331332
# Return total mass
332333
return self.total_mass
@@ -427,6 +428,7 @@ def evaluate_reduced_mass(self):
427428
# calculate reduced mass
428429
self.reduced_mass = motor_mass * mass / (motor_mass + mass)
429430
self.reduced_mass.set_outputs("Reduced Mass (kg)")
431+
self.reduced_mass.set_title("Reduced Mass (kg) x Time (s)")
430432

431433
# Return reduced mass
432434
return self.reduced_mass
@@ -443,6 +445,7 @@ def evaluate_thrust_to_weight(self):
443445
self.thrust_to_weight = self.motor.thrust / (9.80665 * self.total_mass)
444446
self.thrust_to_weight.set_inputs("Time (s)")
445447
self.thrust_to_weight.set_outputs("Thrust/Weight")
448+
self.thrust_to_weight.set_title(None)
446449

447450
def evaluate_center_of_pressure(self):
448451
"""Evaluates rocket center of pressure position relative to user defined

0 commit comments

Comments
 (0)