From 8e173798594286ae39f462c353b9dd7388c56434 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 13 Oct 2023 17:14:57 -0300 Subject: [PATCH 1/3] BUG: cannot print max_acceleration_power_on_time - This happens when we use EmptyMotors - ValueError: attempt to get argmax of an empty sequence --- rocketpy/simulation/flight.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 1a5533643..ca3c7195f 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -2137,6 +2137,9 @@ def max_acceleration_power_on_time(self): burn_out_time_index = find_closest( self.acceleration.source[:, 0], self.rocket.motor.burn_out_time ) + if burn_out_time_index == 0: + return 0 # the burn out time is before the first time step + max_acceleration_time_index = np.argmax( self.acceleration[:burn_out_time_index, 1] ) From b8194b290bcd30fcc90c73875ca129b0a58f2135 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 13 Oct 2023 17:33:19 -0300 Subject: [PATCH 2/3] TST: add a test to cover the last bug behavior --- tests/test_flight.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_flight.py b/tests/test_flight.py index 7a0be6544..3ce811169 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -141,6 +141,32 @@ def test_initial_solution(mock_show, example_env, calisto_robust): assert test_flight.all_info() == None +@patch("matplotlib.pyplot.show") +def test_empty_motor_flight(mock_show, example_env, calisto_motorless): + flight = Flight( + rocket=calisto_motorless, + environment=example_env, + rail_length=5, + initial_solution=[ # a random flight starting at apogee + 22.945995194368354, + 277.80976806186936, + 353.29457980509113, + 3856.1112773441596, + 12.737953434495966, + 15.524649322067267, + -0.00011874766384947776, + -0.06086838708814366, + 0.019695167217632138, + -0.35099420532705555, + -0.9338841410225396, + 0.25418555574446716, + 0.03632002739509155, + 2.0747266017020563, + ], + ) + assert flight.all_info() == None + + @pytest.mark.parametrize("wind_u, wind_v", [(0, 10), (0, -10), (10, 0), (-10, 0)]) @pytest.mark.parametrize( "static_margin, max_time", @@ -537,6 +563,7 @@ def test_rail_length(calisto_robust, example_env, rail_length, out_of_rail_time) assert abs(test_flight.z(test_flight.out_of_rail_time) - out_of_rail_time) < 1e-6 +@pytest.mark.slow @patch("matplotlib.pyplot.show") def test_time_overshoot(mock_show, calisto_robust, example_env_robust): """Test the time_overshoot parameter of the Flight class. This basically From 743f142ab3012bcb0a53cd4a5b90658d40f248ae Mon Sep 17 00:00:00 2001 From: Lint Action Date: Fri, 13 Oct 2023 20:44:41 +0000 Subject: [PATCH 3/3] Fix code style issues with Black --- rocketpy/simulation/flight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index ca3c7195f..9b3c6b6f0 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -2138,7 +2138,7 @@ def max_acceleration_power_on_time(self): self.acceleration.source[:, 0], self.rocket.motor.burn_out_time ) if burn_out_time_index == 0: - return 0 # the burn out time is before the first time step + return 0 # the burn out time is before the first time step max_acceleration_time_index = np.argmax( self.acceleration[:burn_out_time_index, 1]