tephpy.calc#
Tephigram-native thermodynamic analysis over metpy.calc (spec §3.3).
Physics is delegated to MetPy; only tephigram-native compositions live
here, and everything returns pint quantities on the shared registry
(spec §5). Sounding-level functions take a Sounding
— constructing one already validates units, monotonic pressure, and
dewpoint ≤ temperature — while normand_point() is the one
quantity-level function. MetPy stays behind function-local imports so that
import tephpy stays light (spec §10 item 10).
Analysis results distinguish “does not exist” from “zero” (spec §6):
metpy.calc returns NaN quantities for a missing LFC/EL and 0 J/kg
— never NaN — for zero CAPE/CIN, and tephpy passes both through,
documented per SoundingIndices field.
Classes#
Functions#
|
Construct Normand's point — the LCL — for one parcel (spec §3.3). |
|
Compute a parcel's ascent path over the sounding's span (spec §3.3). |
|
Compute the derived thermodynamic parameters (spec §3.3). |
Module Contents#
- class tephpy.calc.Profile[source]#
One computed parcel ascent, ready to plot (spec §3.3).
Plain plottable data:
plot_profiledraws it and the shading builders consume it, and neither re-derives the LCL. Construction mirrorsSounding: bare arrays take theunits=mapping, fields are dimension-checked quantities on the shared registry, and validation happens at construction.- Attributes:
- pressure
pint.Quantity Path pressures, surface-first (strictly decreasing), at least two levels.
- temperature
pint.Quantity Parcel temperatures along the path.
- lcl_pressure
pint.Quantity Scalar pressure of the Normand’s point the path actually uses — the corrected one when a correction was requested — inside the path’s pressure span.
- lcl_temperature
pint.Quantity Scalar temperature at that point.
- parcel
str The lifted parcel:
"surface"or"mixed-layer".- label
strorNone Legend text;
Nonemeans no legend entry.- unitsmapping of
strtostr, optional Construction-only (not stored): unit strings for bare-array fields, keyed by field name (spec §5).
- pressure
- pressure: pint.Quantity#
- temperature: pint.Quantity#
- lcl_pressure: pint.Quantity#
- lcl_temperature: pint.Quantity#
- parcel: Literal['surface', 'mixed-layer'] = 'surface'#
- units: dataclasses.InitVar[collections.abc.Mapping[str, str] | None] = None#
- class tephpy.calc.SoundingIndices[source]#
Derived thermodynamic parameters for one sounding (spec §3.3).
Ten scalar quantity fields, each dimension-checked at construction. There is no cross-field validation: NaN fields are answers, not errors — analysis results distinguish “does not exist” (NaN) from “zero” (spec §6).
- Attributes:
- cape
pint.Quantity Convective available potential energy (J/kg);
0 J/kg— never NaN — when the parcel has no positive-buoyancy region.- cin
pint.Quantity Convective inhibition (J/kg, non-positive);
0 J/kgwhen there is no LFC or no negative-buoyancy region below it.- lcl_pressure
pint.Quantity Pressure of the lifting condensation level the parcel uses (the corrected one when a correction was requested); always defined.
- lcl_temperature
pint.Quantity Temperature at that level; always defined.
- lfc_pressure
pint.Quantity Pressure of the level of free convection; NaN when the parcel never becomes positively buoyant.
- lfc_temperature
pint.Quantity Temperature at that level; NaN with lfc_pressure.
- el_pressure
pint.Quantity Pressure of the equilibrium level; NaN when it does not exist — including while
cape > 0with the parcel still buoyant at the profile top.- el_temperature
pint.Quantity Temperature at that level; NaN with el_pressure.
- theta_w
pint.Quantity Wet-bulb potential temperature of the lifted parcel, evaluated at the parcel start, so it follows the
parcel=option; always defined.- lifted_index
pint.Quantity Lifted index (a temperature difference at 500 hPa); NaN when the profile tops out below 500 hPa.
- unitsmapping of
strtostr, optional Construction-only (not stored): unit strings for bare scalar fields, keyed by field name (spec §5).
- cape
- cape: pint.Quantity#
- cin: pint.Quantity#
- lcl_pressure: pint.Quantity#
- lcl_temperature: pint.Quantity#
- lfc_pressure: pint.Quantity#
- lfc_temperature: pint.Quantity#
- el_pressure: pint.Quantity#
- el_temperature: pint.Quantity#
- theta_w: pint.Quantity#
- lifted_index: pint.Quantity#
- units: dataclasses.InitVar[collections.abc.Mapping[str, str] | None] = None#
- tephpy.calc.normand_point(pressure: object, temperature: object, dewpoint: object, *, units: collections.abc.Mapping[str, str] | None = None) tuple[pint.Quantity, pint.Quantity][source]#
Construct Normand’s point — the LCL — for one parcel (spec §3.3).
The geometric construction: the dry adiabat through (pressure, temperature) meets the humidity mixing-ratio line through (pressure, dewpoint) at the lifting condensation level. This is always the uncorrected construction; the operational cloud-base correction is
parcel_path()’s concern.- Parameters:
- pressure
pint.Quantityorfloat Scalar parcel pressure; a bare value takes the
units=mapping.- temperature
pint.Quantityorfloat Scalar parcel temperature.
- dewpoint
pint.Quantityorfloat Scalar parcel dewpoint; must not exceed temperature (equality — saturation — is physical, and puts Normand’s point at the parcel).
- unitsmapping of
strtostr, optional Unit strings for bare values, keyed by argument name, e.g.
units={"pressure": "hPa", "temperature": "degC"}(spec §5).
- pressure
- Returns:
tupleofpint.QuantityThe scalar
(pressure, temperature)of Normand’s point, in hPa and degrees Celsius.
- Raises:
TephpyUnitsErrorFor unit-less bare values, ambiguous or unparsable units, or the wrong dimensionality.
DewpointExceedsTemperatureErrorIf dewpoint exceeds temperature.
TephpyValidationErrorIf an argument is not a scalar.
- tephpy.calc.parcel_path(snd: tephpy.sounding.Sounding, *, parcel: Literal['surface', 'mixed-layer'] = 'surface', cloud_base_correction: object = None, label: str | None = None) Profile[source]#
Compute a parcel’s ascent path over the sounding’s span (spec §3.3).
Dry adiabat from the parcel start to Normand’s point, then moist adiabat to the profile top. Both legs sample the background moist adiabats’ 5 hPa step, the moist leg is integrated with
metpy.calc.moist_lapse(..., reference_pressure=lcl_pressure)— same integrator, same sampling, same anchoring as the background family — and the LCL vertex is spliced in exactly.- Parameters:
- snd
Sounding The environment sounding; must carry dewpoint.
- parcel
str, default: “surface” The lifted parcel:
"surface"starts from the lowest level;"mixed-layer"starts frommetpy.calc.mixed_parcel()(its 100 hPa default depth is the operational convention).- cloud_base_correction
pint.Quantity, optional A pressure-dimension correction added to the LCL pressure, applied only when explicitly requested; the operational -25 mb value lives in
tephpy._constants.CLOUD_BASE_CORRECTION. The corrected LCL temperature is re-read from the dry adiabat at the corrected pressure.- label
str, optional Legend text for the profile;
Nonemeans no legend entry.
- snd
- Returns:
ProfileThe parcel path, surface-first, with the LCL it actually uses.
- Raises:
MissingDataErrorIf the sounding has no dewpoint.
ProfileTooShortErrorIf the profile tops out at or below the LCL the path would use (the corrected one when a correction is requested), or a mixed-layer parcel is requested but the sounding spans less than the mixed-layer depth.
TephpyUnitsErrorIf cloud_base_correction is not a pressure-dimension quantity.
TephpyValidationErrorIf the selected parcel start has an undefined (NaN) temperature or dewpoint, or the correction places the LCL below the parcel start.
ValueErrorIf parcel is not a known option.
- tephpy.calc.indices(snd: tephpy.sounding.Sounding, *, parcel: Literal['surface', 'mixed-layer'] = 'surface', cloud_base_correction: object = None) SoundingIndices[source]#
Compute the derived thermodynamic parameters (spec §3.3).
The mechanism: derive the parcel curve on the environment levels under the same parcel-selection and correction rules as
parcel_path(), then feed it to the genericmetpy.calcfunctions that take a parcel-profile argument (cape_cin,lfc,el,lifted_index). With the defaults this reduces to plain surface-parcel delegation. Thelcl_*fields report the point the path uses (corrected when requested) and theta_w the parcel start, mirroringProfile.theta_w is computed with
wet_bulb_potential_temperature, whose Davies-Jones formulation differs from the moist-adiabat integrator by ≲0.1 °C: the path is drawn by the integrator, the number by the named function (spec §3.3).- Parameters:
- snd
Sounding The environment sounding; must carry dewpoint.
- parcel
str, default: “surface” The lifted parcel, as for
parcel_path().- cloud_base_correction
pint.Quantity, optional The LCL correction, as for
parcel_path().
- snd
- Returns:
SoundingIndicesThe ten derived parameters, with the spec §6 NaN-versus-zero semantics documented per field.
- Raises:
MissingDataErrorIf the sounding has no dewpoint.
ProfileTooShortErrorIf the profile tops out at or below the LCL the parcel would use, or a mixed-layer parcel is requested but the sounding spans less than the mixed-layer depth.
TephpyUnitsErrorIf cloud_base_correction is not a pressure-dimension quantity.
TephpyValidationErrorIf the selected parcel start has an undefined (NaN) temperature or dewpoint, or the correction places the LCL below the parcel start.
ValueErrorIf parcel is not a known option.