From 84aa3202ad51d1e3e8cbc38710285265d5c2c4e5 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Wed, 8 Jul 2026 22:26:39 -0300 Subject: [PATCH 1/2] ENH: Resolve pressure_ISA discretization bounds TODO (#1056) --- CHANGELOG.md | 1 + rocketpy/environment/environment.py | 4 +++- tests/unit/environment/test_environment.py | 24 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2de3b092..8de78d469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Attention: The newest changes should be on top --> ### Changed +- ENH: Resolve pressure_ISA discretization bounds TODO [#1056](https://github.com/RocketPy-Team/RocketPy/pull/1056) - ENH: Refactor flight.py latitude/longitude to use inverted_haversine [#1055](https://github.com/RocketPy-Team/RocketPy/pull/1055) ### Deprecated diff --git a/rocketpy/environment/environment.py b/rocketpy/environment/environment.py index c4c1ed298..70f52a127 100644 --- a/rocketpy/environment/environment.py +++ b/rocketpy/environment/environment.py @@ -2553,7 +2553,9 @@ def pressure_function(h): return P # Discretize this Function to speed up the trajectory simulation - altitudes = np.linspace(0, 80000, 100) # TODO: should be -2k instead of 0 + min_height = geopotential_height_to_geometric_height(-2000, earth_radius) + max_height = geopotential_height_to_geometric_height(80000, earth_radius) + altitudes = np.linspace(min_height, max_height, 100) pressures = [pressure_function(h) for h in altitudes] return np.column_stack([altitudes, pressures]) diff --git a/tests/unit/environment/test_environment.py b/tests/unit/environment/test_environment.py index d56332e27..249af9e9c 100644 --- a/tests/unit/environment/test_environment.py +++ b/tests/unit/environment/test_environment.py @@ -707,3 +707,27 @@ def test_pressure_conversion_factor_autodetect_by_model( None, None, model ) assert factor == expected_factor + + +def test_pressure_isa_discretization_bounds(example_plain_env): + """Test that pressure_ISA contains the expected range of altitudes + starting from the minimum geopotential height (-2000m) converted to + geometric height, up to the maximum (80000m) geopotential height converted to + geometric height. + """ + from rocketpy.tools import geopotential_height_to_geometric_height + + # Act + pressure_isa_function = example_plain_env.pressure_ISA + source_array = pressure_isa_function.source + altitudes = source_array[:, 0] + + # Expected min/max geometric heights + earth_radius = example_plain_env.earth_radius + expected_min_height = geopotential_height_to_geometric_height(-2000, earth_radius) + expected_max_height = geopotential_height_to_geometric_height(80000, earth_radius) + + # Assert + assert np.isclose(altitudes[0], expected_min_height) + assert np.isclose(altitudes[-1], expected_max_height) + assert len(altitudes) == 100 From 80ac30a5f7fdf97931f320c3056f35562acd2bd9 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 10 Jul 2026 23:46:27 -0300 Subject: [PATCH 2/2] TST: Fix test_flight and environment interpolation due to new ISA bounds --- rocketpy/environment/environment.py | 4 +++- tests/integration/simulation/test_flight.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rocketpy/environment/environment.py b/rocketpy/environment/environment.py index 70f52a127..e4774038a 100644 --- a/rocketpy/environment/environment.py +++ b/rocketpy/environment/environment.py @@ -2555,7 +2555,9 @@ def pressure_function(h): # Discretize this Function to speed up the trajectory simulation min_height = geopotential_height_to_geometric_height(-2000, earth_radius) max_height = geopotential_height_to_geometric_height(80000, earth_radius) - altitudes = np.linspace(min_height, max_height, 100) + altitudes_below = np.linspace(min_height, 0, 10, endpoint=False) + altitudes_above = np.linspace(0, max_height, 90) + altitudes = np.concatenate((altitudes_below, altitudes_above)) pressures = [pressure_function(h) for h in altitudes] return np.column_stack([altitudes, pressures]) diff --git a/tests/integration/simulation/test_flight.py b/tests/integration/simulation/test_flight.py index a69729e2f..5b870847b 100644 --- a/tests/integration/simulation/test_flight.py +++ b/tests/integration/simulation/test_flight.py @@ -460,7 +460,7 @@ def test_freestream_speed_at_apogee(example_plain_env, calisto): assert np.isclose( test_flight.stream_velocity_x(test_flight.apogee_time), - 0.4641492104717301, + 0.46416088113985227, atol=hard_atol, ) assert np.isclose( @@ -472,11 +472,11 @@ def test_freestream_speed_at_apogee(example_plain_env, calisto): ) assert np.isclose( test_flight.free_stream_speed(test_flight.apogee_time), - 0.4641492104717798, + 0.46416088113985277, atol=hard_atol, ) assert np.isclose( - test_flight.apogee_freestream_speed, 0.4641492104717798, atol=hard_atol + test_flight.apogee_freestream_speed, 0.46416088113985277, atol=hard_atol )