From 84aa3202ad51d1e3e8cbc38710285265d5c2c4e5 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Wed, 8 Jul 2026 22:26:39 -0300 Subject: [PATCH] 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