TheAlgorithms/Python · error · ValueError

Value Higher than Pressure at Sea Level !

Error message

Value Higher than Pressure at Sea Level !

What it means

Raised by get_altitude_at_pressure when the supplied pressure exceeds 101325 Pa, the standard sea-level pressure. The barometric formula used (44330 * (1 - (p/101325)^(1/5.5255))) is only defined for pressures at or below sea level; higher pressures would correspond to negative altitudes outside the model.

Source

Thrown at physics/altitude_pressure.py:43

    Examples:
    >>> get_altitude_at_pressure(pressure=100_000)
    105.47836610778828
    >>> get_altitude_at_pressure(pressure=101_325)
    0.0
    >>> get_altitude_at_pressure(pressure=80_000)
    1855.873388064995
    >>> get_altitude_at_pressure(pressure=201_325)
    Traceback (most recent call last):
      ...
    ValueError: Value Higher than Pressure at Sea Level !
    >>> get_altitude_at_pressure(pressure=-80_000)
    Traceback (most recent call last):
      ...
    ValueError: Atmospheric Pressure can not be negative !
    """

    if pressure > 101325:
        raise ValueError("Value Higher than Pressure at Sea Level !")
    if pressure < 0:
        raise ValueError("Atmospheric Pressure can not be negative !")
    return 44_330 * (1 - (pressure / 101_325) ** (1 / 5.5255))


if __name__ == "__main__":
    import doctest

    doctest.testmod()

View on GitHub (pinned to f5988cc097)

Solutions

  1. Ensure the pressure is in pascals and at most 101325 (standard sea level)
  2. Convert units first if your data is in hPa or atm: hPa * 100, atm * 101325
  3. If pressures above one atmosphere are legitimate for your use case, this model is not applicable

Example fix

# before
get_altitude_at_pressure(pressure=201_325)  # ValueError

# after
get_altitude_at_pressure(pressure=min(pressure_pa, 101_325))  # or fix the source data
Defensive patterns

Strategy: validation

Validate before calling

SEA_LEVEL_PA = 101_325

def plausible_pressure(pressure_pa) -> bool:
    return 0 <= pressure_pa <= SEA_LEVEL_PA

Prevention

When it happens

Trigger: Calling get_altitude_at_pressure(pressure=201_325), or any pressure > 101325 such as values in different units (e.g. hPa like 1013 hPa passed as 101300... actually 1013 hPa = 101300 Pa is fine; passing 150000 does raise).

Common situations: Unit confusion — passing pressure in hPa where Pa is expected (e.g. 1013 instead of 101300 does not raise but yields wrong results), or using pressures from below-sea-level sites / pressurized enclosures that exceed one atmosphere.

Related errors


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/de6e4e944babd681. Report an issue: GitHub.