Skip to content

Commit e915e37

Browse files
MNT: self-document pressure_ISA bounds and strengthen discretization test
Derive the pressure_ISA discretization bounds from the standard-atmosphere layer table (geopotential_height[0]/[-1]) instead of hardcoding -2000/80000, and document why the grid is split around sea level. Strengthen the discretization test with physical-sanity assertions (strictly increasing altitude, strictly decreasing pressure, sea level sampled). No change in numeric output. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 04763df commit e915e37

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

rocketpy/environment/environment.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,9 +2554,19 @@ def pressure_function(h):
25542554
)
25552555
return P
25562556

2557-
# Discretize this Function to speed up the trajectory simulation
2558-
min_height = geopotential_height_to_geometric_height(-2000, earth_radius)
2559-
max_height = geopotential_height_to_geometric_height(80000, earth_radius)
2557+
# Discretize this Function to speed up the trajectory simulation.
2558+
# The ISA model is only defined between the lowest and highest
2559+
# geopotential layers, so convert those bounds to geometric height and
2560+
# sample the whole valid range (including below sea level, which the
2561+
# previous grid starting at 0 m did not cover).
2562+
min_height = geopotential_height_to_geometric_height(
2563+
geopotential_height[0], earth_radius
2564+
)
2565+
max_height = geopotential_height_to_geometric_height(
2566+
geopotential_height[-1], earth_radius
2567+
)
2568+
# Split the 100 samples between the narrow sub-sea-level band and the
2569+
# much wider region above it.
25602570
altitudes_below = np.linspace(min_height, 0, 10, endpoint=False)
25612571
altitudes_above = np.linspace(0, max_height, 90)
25622572
altitudes = np.concatenate((altitudes_below, altitudes_above))

tests/unit/environment/test_environment.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -831,27 +831,35 @@ def test_pressure_conversion_factor_autodetect_by_model(
831831

832832

833833
def test_pressure_isa_discretization_bounds(example_plain_env):
834-
"""Test that pressure_ISA contains the expected range of altitudes
835-
starting from the minimum geopotential height (-2000m) converted to
836-
geometric height, up to the maximum (80000m) geopotential height converted to
837-
geometric height.
834+
"""The pressure_ISA discretization must span the full range of the
835+
Standard Atmosphere model: from the lowest geopotential layer (-2000 m) up
836+
to the highest (80000 m), both converted to geometric height. It must also
837+
be a physically sane pressure curve: altitude strictly increasing, pressure
838+
strictly decreasing, and sea level (0 m) sampled exactly.
838839
"""
839840
from rocketpy.tools import geopotential_height_to_geometric_height
840841

841842
# Act
842843
pressure_isa_function = example_plain_env.pressure_ISA
843844
source_array = pressure_isa_function.source
844845
altitudes = source_array[:, 0]
846+
pressures = source_array[:, 1]
845847

846848
# Expected min/max geometric heights
847849
earth_radius = example_plain_env.earth_radius
848850
expected_min_height = geopotential_height_to_geometric_height(-2000, earth_radius)
849851
expected_max_height = geopotential_height_to_geometric_height(80000, earth_radius)
850852

851853
# Assert
854+
assert len(altitudes) == 100
852855
assert np.isclose(altitudes[0], expected_min_height)
853856
assert np.isclose(altitudes[-1], expected_max_height)
854-
assert len(altitudes) == 100
857+
assert expected_min_height < 0 < expected_max_height
858+
# Sea level must be one of the sampled points (split boundary)
859+
assert np.any(np.isclose(altitudes, 0.0))
860+
# Physical sanity: altitude increasing, pressure decreasing monotonically
861+
assert np.all(np.diff(altitudes) > 0)
862+
assert np.all(np.diff(pressures) < 0)
855863

856864

857865
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)