Gas¶
Gas mix value object for diveplan.
Represents an immutable O2/He/N2 breathing gas mixture. Provides partial pressure calculations, operating limits, and best-mix selection.
- class diveplan.core.gas.Gas(fo2, fhe=0.0)[source]¶
Bases:
objectImmutable O2/He/N2 breathing gas mixture.
Fractions are stored as floats (0.0-1.0).
fn2is derived:fn2 = 1.0 - fo2 - fhe. The three fractions always sum to 1.0 within a tolerance of 1e-6.Use the named constructors (
air,nitrox,trimix, …) rather than the raw constructor wherever possible.- Parameters:
- Raises:
ValueError – If any fraction is negative, or the fractions do not sum to 1.0 within 1e-6.
Example
>>> Gas(0.32) Gas(fo2=0.32, fhe=0.00, fn2=0.68) >>> Gas(0.21, fhe=0.35) Gas(fo2=0.21, fhe=0.35, fn2=0.44)
- classmethod air()[source]¶
Return standard air (21 % O2, 79 % N2).
- Return type:
- Returns:
A
Gasrepresenting atmospheric air.
- classmethod nitrox(fo2)[source]¶
Return a nitrox (O2/N2) mix with the given O2 fraction.
- Parameters:
fo2 (
float) – Oxygen fraction, e.g.0.32for EAN32.- Return type:
- Returns:
A
Gaswith no helium and nitrogen making up the remainder.- Raises:
ValueError – If
fo2 <= 0orfo2 > 1.
- classmethod trimix(fo2, fhe)[source]¶
Return a trimix (O2/He/N2) gas.
- Parameters:
- Return type:
- Returns:
A
Gaswhere nitrogen fills the remainder.- Raises:
ValueError – If
fo2 <= 0,fhe <= 0, or fractions are otherwise invalid.
- classmethod from_name(name)[source]¶
Parse a gas mix from a human-readable name string.
Supported formats (case-insensitive):
"air""oxygen""nx32","ean32","nitrox 32"— O2 % as integer"tx21/35","trimix 21/35"— O2%/He%
- Parameters:
name (
str) – Human-readable gas name.- Return type:
- Returns:
The corresponding
Gasinstance.- Raises:
ValueError – If the name cannot be parsed.
Example
>>> Gas.from_name("ean32") Gas(fo2=0.32, fhe=0.00, fn2=0.68) >>> Gas.from_name("tx21/35") Gas(fo2=0.21, fhe=0.35, fn2=0.44)
- mod(*, ppo2_bar)[source]¶
Return the maximum operating depth (MOD) for a given ppO2 limit.
- Parameters:
ppo2_bar (
float) – ppO2 ceiling in bar, e.g.1.4.- Return type:
- Returns:
The MOD as a
Pressure.- Raises:
ValueError – If
ppo2_bar <= 0.
Example
>>> from diveplan.core.pressure import Pressure >>> Gas.nitrox(0.32).mod(ppo2_bar=1.4).bar 4.375
- end(pressure)[source]¶
Return the equivalent narcotic depth (END) at the given pressure.
Helium is assumed non-narcotic; the narcotic fraction is
fo2 + fn2.
- is_breathable(pressure)[source]¶
Whether this gas is breathable at the given ambient pressure.
Breathable means the ppO2 sits within the configured
[min_ppo2_bar, deco_ppo2_bar]window (fromDiveConfig.current()). The deco limit is used because this is the gas-switching question — switches happen during the ascent, where the deco ppO2 applies; compare againstmod(ppo2_bar=...)for an explicit working limit.
- best_mix(depth, *, trimix=False, hypoxic=False)[source]¶
Return the optimal gas mix for the given depth.
Maximises
fo2within the ppO2 and END/ppN2 constraints taken fromdiveplan.core.config.DiveConfig.current().hypoxic=Trueimpliestrimix=True.- Parameters:
- Return type:
- Returns:
The best
Gasfor the given depth and constraints.- Raises:
ValueError – If the constraints cannot be satisfied (e.g.
best_mix(120, trimix=False)).
Example
>>> Gas.air().best_mix(30) Gas(fo2=0.32, fhe=0.00, fn2=0.68)