From d0b97119a30234b8b323398162f19fdad0928f66 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Wed, 13 Mar 2024 10:55:51 -0400 Subject: [PATCH] MNT: Refactor code to use dictionary unpacking in stochastic_aero_surfaces.py and stochastic_parachute.py --- .../stochastic/stochastic_aero_surfaces.py | 50 ++----------------- rocketpy/stochastic/stochastic_parachute.py | 10 +--- 2 files changed, 6 insertions(+), 54 deletions(-) diff --git a/rocketpy/stochastic/stochastic_aero_surfaces.py b/rocketpy/stochastic/stochastic_aero_surfaces.py index cfc47c531..e5cd7191d 100644 --- a/rocketpy/stochastic/stochastic_aero_surfaces.py +++ b/rocketpy/stochastic/stochastic_aero_surfaces.py @@ -106,15 +106,7 @@ def create_object(self): NoseCone object with the randomly generated input arguments. """ generated_dict = next(self.dict_generator()) - nosecone = NoseCone( - length=generated_dict["length"], - kind=generated_dict["kind"], - base_radius=generated_dict["base_radius"], - bluffness=generated_dict["bluffness"], - rocket_radius=generated_dict["rocket_radius"], - name=generated_dict["name"], - ) - return nosecone + return NoseCone(**generated_dict) class StochasticTrapezoidalFins(StochasticModel): @@ -237,18 +229,7 @@ def create_object(self): TrapezoidalFins object with the randomly generated input arguments. """ generated_dict = next(self.dict_generator()) - fins = TrapezoidalFins( - n=generated_dict["n"], - root_chord=generated_dict["root_chord"], - tip_chord=generated_dict["tip_chord"], - span=generated_dict["span"], - rocket_radius=generated_dict["rocket_radius"], - cant_angle=generated_dict["cant_angle"], - sweep_length=generated_dict["sweep_length"], - airfoil=generated_dict["airfoil"], - name=generated_dict["name"], - ) - return fins + return TrapezoidalFins(**generated_dict) class StochasticEllipticalFins(StochasticModel): @@ -347,16 +328,7 @@ def create_object(self): EllipticalFins object with the randomly generated input arguments. """ generated_dict = next(self.dict_generator()) - fins = EllipticalFins( - n=generated_dict["n"], - root_chord=generated_dict["root_chord"], - span=generated_dict["span"], - rocket_radius=generated_dict["rocket_radius"], - cant_angle=generated_dict["cant_angle"], - airfoil=generated_dict["airfoil"], - name=generated_dict["name"], - ) - return fins + return EllipticalFins(**generated_dict) class StochasticTail(StochasticModel): @@ -439,14 +411,7 @@ def create_object(self): Tail object with the randomly generated input arguments. """ generated_dict = next(self.dict_generator()) - tail = Tail( - top_radius=generated_dict["top_radius"], - bottom_radius=generated_dict["bottom_radius"], - length=generated_dict["length"], - rocket_radius=generated_dict["rocket_radius"], - name=generated_dict["name"], - ) - return tail + return Tail(**generated_dict) class StochasticRailButtons(StochasticModel): @@ -516,9 +481,4 @@ def create_object(self): RailButtons object with the randomly generated input arguments. """ generated_dict = next(self.dict_generator()) - rail_buttons = RailButtons( - buttons_distance=generated_dict["buttons_distance"], - angular_position=generated_dict["angular_position"], - name=generated_dict["name"], - ) - return rail_buttons + return RailButtons(**generated_dict) diff --git a/rocketpy/stochastic/stochastic_parachute.py b/rocketpy/stochastic/stochastic_parachute.py index 938d329fd..7b958e926 100644 --- a/rocketpy/stochastic/stochastic_parachute.py +++ b/rocketpy/stochastic/stochastic_parachute.py @@ -138,12 +138,4 @@ def create_object(self): Parachute object with the randomly generated input arguments. """ generated_dict = next(self.dict_generator()) - parachute = Parachute( - name=generated_dict["name"], - cd_s=generated_dict["cd_s"], - trigger=generated_dict["trigger"], - sampling_rate=generated_dict["sampling_rate"], - lag=generated_dict["lag"], - noise=generated_dict["noise"], - ) - return parachute + return Parachute(**generated_dict)