Pressure¶
core/pressure.py — Pressure value type.
Ground truth is always integer millibar. Pressure represents absolute pressures only (ambient, partial pressures, tissue loadings) — always >= 0.
- Arithmetic:
Pressure + Pressure -> Pressure (e.g. surface + hydrostatic) Pressure - Pressure -> int (signed mbar delta — NOT a Pressure) Pressure * float -> Pressure (e.g. ppO2 = ambient * o2_fraction) float * Pressure -> Pressure (commutative) Pressure / Pressure -> float (dimensionless ratio) Pressure / float -> Pressure (scaling)
- Depth conversion:
Pressure.from_depth_m(depth_m) reads DiveConfig.current().physics pressure.depth_m reads DiveConfig.current().physics
Dependency: Pressure -> DiveConfig (one way only, never reversed).
- class diveplan.core.pressure.Pressure(mbar)[source]¶
Bases:
objectAbsolute pressure stored as integer millibar.
Immutable. __slots__ for memory efficiency in batch simulation.
Examples
>>> Pressure(1013) Pressure(1013) >>> Pressure.from_bar(4.013).depth_m # at standard surface pressure, salt water 30.0
- Parameters:
mbar (
int)
- classmethod from_depth_m(depth_m)[source]¶
Construct from depth in metres using the current DiveConfig environment.
- Reads DiveConfig.current().physics — context manager overrides apply:
- with DiveConfig(physics=_PhysicsConfig(surface_pressure_mbar=800)):
Pressure.from_depth_m(40) # altitude dive
- classmethod from_depth_ft(depth_ft)[source]¶
Construct from depth in feet using the current DiveConfig environment.
- Reads DiveConfig.current().physics — context manager overrides apply:
- with DiveConfig(physics=_PhysicsConfig(surface_pressure_mbar=800)):
Pressure.from_depth_ft(130) # altitude dive
- classmethod surface()[source]¶
Convenience constructor for surface pressure in the current DiveConfig environment.
- Return type:
- classmethod from_str(s)[source]¶
- Parse a pressure from a string with unit suffix. Supported formats:
“4.013 bar” “4013 mbar” “1 atm” “14.7 psi” “30 m” “98 ft”
- Parameters:
s (
str) – Input string to parse.- Raises:
ValueError – If the input string has an invalid format or unit.
ValueError – If the parsed value is negative.
ValueError – If the parsed value is not a valid number.
- Returns:
The parsed pressure instance.
- Return type:
- property depth_m: float¶
Depth in metres in the context of the current DiveConfig environment.
Reads DiveConfig.current().physics — context manager overrides apply. Returns a negative value if pressure is below surface pressure (e.g. altitude surface, though that shouldn’t arise in normal use).
- diveplan.core.pressure.PressureUnit¶
Unit names accepted by
Pressure.to_str().alias of
Literal[‘bar’, ‘mbar’, ‘atm’, ‘psi’, ‘m’, ‘ft’]