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: object

Absolute 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_bar(bar)[source]

Construct from bar. Rounds to nearest mbar.

Parameters:

bar (float)

Return type:

Pressure

classmethod from_mbar(mbar)[source]

Construct from float mbar. Rounds to nearest integer mbar.

Parameters:

mbar (float)

Return type:

Pressure

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

Parameters:

depth_m (float)

Return type:

Pressure

classmethod from_atm(atm)[source]

Construct from atmospheres. Rounds to nearest mbar.

Parameters:

atm (float)

Return type:

Pressure

classmethod from_psi(psi)[source]

Construct from psi. Rounds to nearest mbar.

Parameters:

psi (float)

Return type:

Pressure

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

Parameters:

depth_ft (float)

Return type:

Pressure

classmethod surface()[source]

Convenience constructor for surface pressure in the current DiveConfig environment.

Return type:

Pressure

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:

Pressure

property mbar: int

Absolute pressure in integer millibar (the ground-truth value).

property bar: float

Absolute pressure in bar.

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).

property depth_ft: float

Depth in feet 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).

property atm: float

Absolute pressure in atmospheres, relative to the current surface pressure.

property psi: float

Absolute pressure in pounds per square inch.

property is_surface: bool

Whether this pressure is at (or above) the configured surface.

to_str(unit='bar')[source]

Format pressure as a string in the specified unit.

Supported units: ‘bar’, ‘mbar’, ‘atm’, ‘psi’, ‘m’ (depth in metres), ‘ft’ (depth in feet).

Parameters:

unit (Literal['bar', 'mbar', 'atm', 'psi', 'm', 'ft'])

Return type:

str

diveplan.core.pressure.PressureUnit

Unit names accepted by Pressure.to_str().

alias of Literal[‘bar’, ‘mbar’, ‘atm’, ‘psi’, ‘m’, ‘ft’]