Skip to content

Commit 84aa320

Browse files
ENH: Resolve pressure_ISA discretization bounds TODO (#1056)
1 parent 5c17f5a commit 84aa320

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Attention: The newest changes should be on top -->
6060

6161
### Changed
6262

63+
- ENH: Resolve pressure_ISA discretization bounds TODO [#1056](https://github.com/RocketPy-Team/RocketPy/pull/1056)
6364
- ENH: Refactor flight.py latitude/longitude to use inverted_haversine [#1055](https://github.com/RocketPy-Team/RocketPy/pull/1055)
6465

6566
### Deprecated

rocketpy/environment/environment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,9 @@ def pressure_function(h):
25532553
return P
25542554

25552555
# Discretize this Function to speed up the trajectory simulation
2556-
altitudes = np.linspace(0, 80000, 100) # TODO: should be -2k instead of 0
2556+
min_height = geopotential_height_to_geometric_height(-2000, earth_radius)
2557+
max_height = geopotential_height_to_geometric_height(80000, earth_radius)
2558+
altitudes = np.linspace(min_height, max_height, 100)
25572559
pressures = [pressure_function(h) for h in altitudes]
25582560

25592561
return np.column_stack([altitudes, pressures])

tests/unit/environment/test_environment.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,3 +707,27 @@ def test_pressure_conversion_factor_autodetect_by_model(
707707
None, None, model
708708
)
709709
assert factor == expected_factor
710+
711+
712+
def test_pressure_isa_discretization_bounds(example_plain_env):
713+
"""Test that pressure_ISA contains the expected range of altitudes
714+
starting from the minimum geopotential height (-2000m) converted to
715+
geometric height, up to the maximum (80000m) geopotential height converted to
716+
geometric height.
717+
"""
718+
from rocketpy.tools import geopotential_height_to_geometric_height
719+
720+
# Act
721+
pressure_isa_function = example_plain_env.pressure_ISA
722+
source_array = pressure_isa_function.source
723+
altitudes = source_array[:, 0]
724+
725+
# Expected min/max geometric heights
726+
earth_radius = example_plain_env.earth_radius
727+
expected_min_height = geopotential_height_to_geometric_height(-2000, earth_radius)
728+
expected_max_height = geopotential_height_to_geometric_height(80000, earth_radius)
729+
730+
# Assert
731+
assert np.isclose(altitudes[0], expected_min_height)
732+
assert np.isclose(altitudes[-1], expected_max_height)
733+
assert len(altitudes) == 100

0 commit comments

Comments
 (0)