Skip to content

FIX: correct default Earth radius (10x too large) in geopotential height conversions - #1193

Closed
zjk199506 wants to merge 1 commit into
RocketPy-Team:developfrom
zjk199506:fix/geopotential-default-radius
Closed

FIX: correct default Earth radius (10x too large) in geopotential height conversions#1193
zjk199506 wants to merge 1 commit into
RocketPy-Team:developfrom
zjk199506:fix/geopotential-default-radius

Conversation

@zjk199506

Copy link
Copy Markdown

Summary

The default Earth radius of the three geopotential conversion helpers in rocketpy/tools.py is 63781370 m — 10x the WGS-84 semi-major axis — directly contradicting their own docstrings:

def geopotential_height_to_geometric_height(geopotential_height, radius=63781370.0):
    """...
    radius : float, optional
        The Earth's radius in meters, defaulting to 6378137.0.   # <- docstring disagrees with signature

geopotential_to_height_asl and geopotential_to_height_agl carry the same radius=63781370 default, and the docstring examples of all three functions are anchored to the 10x-radius values, which masked the bug.

Impact

  • The main Environment processing paths already pass self.earth_radius explicitly and are unaffected.
  • The default bites when the helpers are reused directly, e.g. EnvironmentAnalysis computes surface elevation from NOAA reanalysis surface geopotential (z) via geopotential_to_height_asl(surface_geopotential) with the default radius (environment_analysis.py:876).
  • Height bias from the 10x radius: ~-14 m at 10 km, ~-57 m at 20 km (conversion returns heights too low).
Geopotential height Old default (63781370) Correct (6378137)
10000 m 10001.568 m 10015.703 m
20000 m 20006.273 m 20062.912 m

Changes

  • Defaults: radius=63781370(0.0) -> radius=6378137.0 (WGS-84 semi-major axis, matching the value used in environment.py geodesy and the existing docstrings) in all three helpers
  • Docstring Default is 63781370 m -> Default is 6378137.0 m (WGS-84 semi-major axis)
  • Docstring examples re-anchored to the correct values
  • New regression test test_geopotential_height_to_geometric_height_default_radius pins the correct conversion at 10/20 km and checks explicit-radius override still works

Testing

  • tests/unit/test_tools.py + doctests of rocketpy/tools.py: all pass
  • tests/unit/environment/test_environment.py: 145 passed (explicit-radius call sites unchanged)
  • black clean

The default radius of geopotential_height_to_geometric_height,
geopotential_to_height_asl and geopotential_to_height_agl was
63781370 m - 10x the WGS-84 semi-major axis - contradicting their
own docstrings ("defaulting to 6378137.0"). The docstring examples
were anchored to the 10x-radius values, masking the bug.

The main Environment processing paths already pass earth_radius
explicitly and are unaffected; the default only bites when the
helpers are reused directly (e.g. EnvironmentAnalysis surface
elevation from NOAA reanalysis 'z'), biasing heights low by
~14 m at 10 km and ~57 m at 20 km.

Defaults now use 6378137.0 m; docstring examples and a regression
test pin the correct values.
@zjk199506
zjk199506 requested a review from a team as a code owner September 5, 2026 07:29
@zjk199506 zjk199506 closed this by deleting the head repository Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants