From 8e6b80c4a655bc2bd61619086e5a67b28bf8d1f6 Mon Sep 17 00:00:00 2001 From: julio Date: Tue, 6 Feb 2024 21:26:54 -0300 Subject: [PATCH 1/5] ENH: Plotting both drag power on and off curves in a single plot. --- rocketpy/plots/rocket_plots.py | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/rocketpy/plots/rocket_plots.py b/rocketpy/plots/rocket_plots.py index c3fb998f6..1dc122354 100644 --- a/rocketpy/plots/rocket_plots.py +++ b/rocketpy/plots/rocket_plots.py @@ -86,27 +86,31 @@ def stability_margin(self): return None - def power_on_drag(self): - """Plots power on drag of the rocket as a function of time. - - Returns - ------- - None - """ - - self.rocket.power_on_drag() - - return None - - def power_off_drag(self): - """Plots power off drag of the rocket as a function of time. + def power_on_and_off_drag(self): + """Plots power off and on drag curve 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="--" + ) - self.rocket.power_off_drag() + ax.set_title("Power on and off Drag") + 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() return None @@ -524,8 +528,7 @@ def all(self): # Drag Plots print("Drag Plots") print("-" * 20) # Separator for Drag Plots - self.power_on_drag() - self.power_off_drag() + self.power_on_and_off_drag() # Stability Plots print("\nStability Plots") From b1f155e8b10112939c7802a7ff51a6e6699d3ad0 Mon Sep 17 00:00:00 2001 From: julio Date: Tue, 6 Feb 2024 21:45:42 -0300 Subject: [PATCH 2/5] MNT: Updating the changelog file. --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1137336a0..886b49f89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ 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 @@ -52,7 +52,7 @@ straightforward as possible. - 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 From 872bd09383efa274a70bd9ace105f7d63be5e62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Machado?= <85506246+juliomachad0@users.noreply.github.com> Date: Tue, 6 Feb 2024 22:49:47 -0300 Subject: [PATCH 3/5] Update rocketpy/plots/rocket_plots.py MNT: removing the unnecessary 'return None' line Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> --- rocketpy/plots/rocket_plots.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rocketpy/plots/rocket_plots.py b/rocketpy/plots/rocket_plots.py index 1dc122354..d1136e481 100644 --- a/rocketpy/plots/rocket_plots.py +++ b/rocketpy/plots/rocket_plots.py @@ -112,7 +112,6 @@ def power_on_and_off_drag(self): plt.grid(True) plt.show() - return None def thrust_to_weight(self): """Plots the motor thrust force divided by rocket From 243c49314f3558c2bec9ad64f7ccf06f58a097ef Mon Sep 17 00:00:00 2001 From: Lint Action Date: Wed, 7 Feb 2024 01:50:14 +0000 Subject: [PATCH 4/5] Fix code style issues with Black --- rocketpy/plots/rocket_plots.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rocketpy/plots/rocket_plots.py b/rocketpy/plots/rocket_plots.py index d1136e481..59da692ac 100644 --- a/rocketpy/plots/rocket_plots.py +++ b/rocketpy/plots/rocket_plots.py @@ -112,7 +112,6 @@ def power_on_and_off_drag(self): plt.grid(True) plt.show() - def thrust_to_weight(self): """Plots the motor thrust force divided by rocket weight as a function of time. From 0ccd0b3c09e31501d032617c20f23ff6ef77296e Mon Sep 17 00:00:00 2001 From: julio Date: Wed, 7 Feb 2024 01:30:21 -0300 Subject: [PATCH 5/5] MNT: Making the changes that @Gui-FernandesBR suggested. --- rocketpy/plots/rocket_plots.py | 48 +++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/rocketpy/plots/rocket_plots.py b/rocketpy/plots/rocket_plots.py index 59da692ac..56b57fdd1 100644 --- a/rocketpy/plots/rocket_plots.py +++ b/rocketpy/plots/rocket_plots.py @@ -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 @@ -86,13 +87,52 @@ def stability_margin(self): return None - def power_on_and_off_drag(self): - """Plots power off and on drag curve of the rocket as a function of time. + def power_on_drag(self): + """Plots power on drag of the rocket as a function of time. Returns ------- None """ + + warnings.warn( + "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 + + def power_off_drag(self): + """Plots power off drag of the rocket as a function of time. + + Returns + ------- + None + """ + + warnings.warn( + "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 @@ -104,7 +144,7 @@ def power_on_and_off_drag(self): x_power_drag_off, y_power_drag_off, label="Power off Drag", linestyle="--" ) - ax.set_title("Power on and off Drag") + 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") @@ -526,7 +566,7 @@ def all(self): # Drag Plots print("Drag Plots") print("-" * 20) # Separator for Drag Plots - self.power_on_and_off_drag() + self.drag_curves() # Stability Plots print("\nStability Plots")