From 0edcd75a320a28fdd63a65d6e44369a73b324261 Mon Sep 17 00:00:00 2001 From: Guilherme Date: Tue, 24 Jan 2023 01:25:07 +0100 Subject: [PATCH 1/3] ENH: Parachute.__str__ method --- rocketpy/Parachute.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rocketpy/Parachute.py b/rocketpy/Parachute.py index cc45f0624..210dac86e 100644 --- a/rocketpy/Parachute.py +++ b/rocketpy/Parachute.py @@ -117,4 +117,20 @@ def __init__( self.noiseFunction = lambda: alpha * self.noiseSignal[-1][ 1 ] + beta * np.random.normal(noise[0], noise[1]) + def __str__(self): + """Returns a string representation of the Parachute class. + Parameters + ---------- + None + + Returns + ------- + string + String representation of Parachute class. It is human readable. + """ + return "Parachute {} with a CdS of {:.4f} m2".format( + self.name.title(), + self.CdS, + ) + return None From 98122c22e5673c2287b2811427df7a6826edc19e Mon Sep 17 00:00:00 2001 From: Guilherme Date: Tue, 24 Jan 2023 01:27:16 +0100 Subject: [PATCH 2/3] ENH: Parachute.info() method created --- rocketpy/Parachute.py | 20 ++++++- rocketpy/prints/__init__.py | 5 +- rocketpy/prints/parachute_prints.py | 81 +++++++++++++++++++++++++++++ rocketpy/prints/rocket_prints.py | 16 +----- 4 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 rocketpy/prints/parachute_prints.py diff --git a/rocketpy/Parachute.py b/rocketpy/Parachute.py index 210dac86e..8e6ff9e80 100644 --- a/rocketpy/Parachute.py +++ b/rocketpy/Parachute.py @@ -1,4 +1,4 @@ -__author__ = "Giovani Hidalgo Ceotto, Franz Masatoshi Yuri" +__author__ = "Giovani Hidalgo Ceotto, Franz Masatoshi Yuri, Guilherme Fernandes Alves" __copyright__ = "Copyright 20XX, RocketPy Team" __license__ = "MIT" @@ -6,6 +6,8 @@ from .Function import Function +from .prints.parachute_prints import _ParachutePrints + class Parachute: """Keeps parachute information. @@ -117,6 +119,11 @@ def __init__( self.noiseFunction = lambda: alpha * self.noiseSignal[-1][ 1 ] + beta * np.random.normal(noise[0], noise[1]) + + self.prints = _ParachutePrints(self) + + return None + def __str__(self): """Returns a string representation of the Parachute class. Parameters @@ -133,4 +140,15 @@ def __str__(self): self.CdS, ) + def info(self): + + self.prints.all() + + return None + + def allInfo(self): + + self.info() + # self.plots.all() # Parachutes still doesn't have plots + return None diff --git a/rocketpy/prints/__init__.py b/rocketpy/prints/__init__.py index b8c1a820b..36dccc4e5 100644 --- a/rocketpy/prints/__init__.py +++ b/rocketpy/prints/__init__.py @@ -1,4 +1,5 @@ -from .flight_prints import _FlightPrints +from .compare_prints import _ComparePrints from .environment_prints import _EnvironmentPrints +from .flight_prints import _FlightPrints +from .parachute_prints import _ParachutePrints from .rocket_prints import _RocketPrints -from .compare_prints import _ComparePrints diff --git a/rocketpy/prints/parachute_prints.py b/rocketpy/prints/parachute_prints.py new file mode 100644 index 000000000..4c9c92a9e --- /dev/null +++ b/rocketpy/prints/parachute_prints.py @@ -0,0 +1,81 @@ +__author__ = "Guilherme Fernandes Alves" +__copyright__ = "Copyright 20XX, RocketPy Team" +__license__ = "MIT" + + +class _ParachutePrints: + """Class that holds prints methods for Parachute class. + + Attributes + ---------- + _ParachutePrints.parachute : rocketpy.Parachute + Parachute object that will be used for the prints. + + """ + + def __init__(self, parachute) -> None: + """Initializes _ParachutePrints class + + Parameters + ---------- + parachute: rocketpy.Parachute + Instance of the Parachute class. + + Returns + ------- + None + """ + self.parachute = parachute + + return None + + def trigger(self): + """Prints trigger information. + + Parameters + ---------- + None + + Return + ------ + None + """ + + if self.parachute.trigger.__name__ == "": + line = self.rocket.getsourcelines(self.parachute.trigger)[0][0] + print( + "Ejection signal trigger: " + + line.split("lambda ")[1].split(",")[0].split("\n")[0] + ) + else: + print("Ejection signal trigger: " + self.parachute.trigger.__name__) + + print(f"Ejection system refresh rate: {self.parachute.samplingRate:.3f} Hz") + print( + f"Time between ejection signal is triggered and the parachute is fully opened: {self.parachute.lag:.1f} s\n" + ) + + return None + + def noise(self): + # Not implemented yet + pass + + def all(self): + """Prints all information about the parachute. + + Parameters + ---------- + None + + Return + ------ + None + """ + + print("\nParachute Details\n") + print(self.parachute.__str__()) + self.trigger() + self.noise() + + return None diff --git a/rocketpy/prints/rocket_prints.py b/rocketpy/prints/rocket_prints.py index dd835820c..aea9a3774 100644 --- a/rocketpy/prints/rocket_prints.py +++ b/rocketpy/prints/rocket_prints.py @@ -158,21 +158,7 @@ def parachute_data(self): None """ for chute in self.rocket.parachutes: - print("\n" + chute.name.title() + " Parachute\n") - print("CdS Coefficient: " + str(chute.CdS) + " m2") - if chute.trigger.__name__ == "": - line = self.rocket.getsourcelines(chute.trigger)[0][0] - print( - "Ejection signal trigger: " - + line.split("lambda ")[1].split(",")[0].split("\n")[0] - ) - else: - print("Ejection signal trigger: " + chute.trigger.__name__) - print("Ejection system refresh rate: " + str(chute.samplingRate) + " Hz.") - print( - "Time between ejection signal is triggered and the " - "parachute is fully opened: " + str(chute.lag) + " s" - ) + chute.allInfo() return None def all(self): From 801d22e41b8a1ecfc9b8f4bb749b2067a18a06a4 Mon Sep 17 00:00:00 2001 From: Guilherme Date: Tue, 24 Jan 2023 01:29:48 +0100 Subject: [PATCH 3/3] MAINT: update docstring of _RocketPrints --- rocketpy/prints/rocket_prints.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rocketpy/prints/rocket_prints.py b/rocketpy/prints/rocket_prints.py index aea9a3774..97df57795 100644 --- a/rocketpy/prints/rocket_prints.py +++ b/rocketpy/prints/rocket_prints.py @@ -1,4 +1,4 @@ -__author__ = " " +__author__ = "Mateus Stano Junqueira" __copyright__ = "Copyright 20XX, RocketPy Team" __license__ = "MIT" @@ -8,7 +8,7 @@ class _RocketPrints: Attributes ---------- - _RocketPrints.environment : rocket + _RocketPrints.rocket : rocket Rocket object that will be used for the prints. """ @@ -18,8 +18,8 @@ def __init__(self, rocket) -> None: Parameters ---------- - environment: Environment - Instance of the Environment class. + rocket: rocketpy.rocket + Instance of the rocket class. Returns ------- @@ -159,7 +159,7 @@ def parachute_data(self): """ for chute in self.rocket.parachutes: chute.allInfo() - return None + return None def all(self): """Prints all print methods about the Environment.