Skip to content

Commit

Permalink
Merge pull request #547 from RocketPy-Team/enh/drag-plot-on-off
Browse files Browse the repository at this point in the history
ENH: Plotting both power on and off drag curves in a single plot.
  • Loading branch information
phmbressan authored Feb 7, 2024
2 parents 3f35ead + 0ccd0b3 commit e5d1122
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ straightforward as possible.
- ENH Precalculate Barometric Height [#511](https://github.com/RocketPy-Team/RocketPy/pull/511)
- MNT: Encapsulate quaternion conversions [#537](https://github.com/RocketPy-Team/RocketPy/pull/537)
- MNT: improve the low pass filter and document an example [#538](https://github.com/RocketPy-Team/RocketPy/pull/538)

- ENH: Plotting both power on and off drag curves in a single plot [#547](https://github.com/RocketPy-Team/RocketPy/pull/547)

### Fixed

- ENH: Parachute trigger doesn't work if "Apogee" is used instead of "apogee" [#489](https://github.com/RocketPy-Team/RocketPy/pull/489)
- BUG: fin_flutter_analysis doesn't find any fin set [#510](https://github.com/RocketPy-Team/RocketPy/pull/510)
- FIX: EmptyMotor is breaking the Rocket.draw() method [#516](https://github.com/RocketPy-Team/RocketPy/pull/516)
- BUG: 3D trajectory plot not labeling axes [#533](https://github.com/RocketPy-Team/RocketPy/pull/533)
-


## [v1.1.5] - 2024-01-21

Expand Down
45 changes: 43 additions & 2 deletions rocketpy/plots/rocket_plots.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import matplotlib.pyplot as plt
import numpy as np
import warnings

from rocketpy.motors import EmptyMotor, HybridMotor, LiquidMotor, SolidMotor
from rocketpy.rocket.aero_surface import Fins, NoseCone, Tail
Expand Down Expand Up @@ -94,6 +95,13 @@ def power_on_drag(self):
None
"""

warnings.warn(

Check warning on line 98 in rocketpy/plots/rocket_plots.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/plots/rocket_plots.py#L98

Added line #L98 was not covered by tests
"The method 'power_on_drag' is deprecated as of version "
+ "1.2 and will be removed in version 1.4 "
+ "Use 'plots.drag_curves' instead.",
DeprecationWarning,
)

self.rocket.power_on_drag()

return None
Expand All @@ -106,10 +114,44 @@ def power_off_drag(self):
None
"""

warnings.warn(

Check warning on line 117 in rocketpy/plots/rocket_plots.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/plots/rocket_plots.py#L117

Added line #L117 was not covered by tests
"The method 'power_off_drag' is deprecated as of version "
+ "1.2 and will be removed in version 1.4 "
+ "Use 'plots.drag_curves' instead.",
DeprecationWarning,
)

self.rocket.power_off_drag()

return None

def drag_curves(self):
"""Plots power off and on drag curves of the rocket as a function of time.
Returns
-------
None
"""

x_power_drag_off = self.rocket.power_off_drag.x_array
y_power_drag_off = self.rocket.power_off_drag.y_array
x_power_drag_on = self.rocket.power_on_drag.x_array
y_power_drag_on = self.rocket.power_on_drag.y_array

fig, ax = plt.subplots()
ax.plot(x_power_drag_on, y_power_drag_on, label="Power on Drag")
ax.plot(
x_power_drag_off, y_power_drag_off, label="Power off Drag", linestyle="--"
)

ax.set_title("Drag Curves")
ax.set_ylabel("Drag Coefficient")
ax.set_xlabel("Mach")
ax.axvspan(0.8, 1.2, alpha=0.3, color="gray", label="Transonic Region")
ax.legend(loc="best", shadow=True)
plt.grid(True)
plt.show()

def thrust_to_weight(self):
"""Plots the motor thrust force divided by rocket
weight as a function of time.
Expand Down Expand Up @@ -524,8 +566,7 @@ def all(self):
# Drag Plots
print("Drag Plots")
print("-" * 20) # Separator for Drag Plots
self.power_on_drag()
self.power_off_drag()
self.drag_curves()

# Stability Plots
print("\nStability Plots")
Expand Down

0 comments on commit e5d1122

Please sign in to comment.