tephpy.sounding#
The Sounding data model (spec §3.4).
A Sounding is a frozen dataclass holding one ascent’s
pressure/temperature/dewpoint/wind arrays as pint quantities on MetPy’s
registry, plus optional station/time metadata and a derived legend label.
Inputs are coerced and validated at construction — bad data fails at
ingest, not mid-plot (spec §6) — and pressure is normalized to decreasing
(surface-first) storage with all arrays reversed together, so downstream
metpy.calc sees one orientation.
The pandas/xarray constructors consume the objects handed to them —
neither library is imported at runtime — so import tephpy stays
light (spec §10 item 10).
Classes#
Module Contents#
- class tephpy.sounding.Sounding[source]#
One sounding: quantified profile arrays plus metadata (spec §3.4).
Pressure and temperature are required; dewpoint and wind are optional, and the two wind fields must arrive together. Bare arrays need the
units=mapping; a constructed Sounding always holds pint quantities on MetPy’s registry, with pressure stored decreasing (surface-first). NaN gaps are data everywhere except pressure.- Attributes:
- pressure
pint.Quantity Level pressures; required, finite, and strictly monotonic (either direction accepted, normalized to decreasing).
- temperature
pint.Quantity Level temperatures; required.
- dewpoint
pint.QuantityorNone Level dewpoints; where dewpoint and temperature are both non-NaN, dewpoint above temperature is rejected (equality — saturation — is physical).
- wind_speed
pint.QuantityorNone Level wind speeds; requires wind_direction.
- wind_direction
pint.QuantityorNone Level wind directions (degrees from north); requires wind_speed.
- station
strorNone Station identifier, e.g.
"72357".- time
datetime.datetimeorNone Launch time;
numpy.datetime64input is accepted, naive datetimes are read as UTC, and aware ones are converted to UTC.- label
strorNone Legend text. When not given it derives as e.g.
"72357 2013-05-20 12Z"if both station and time are present, elseNone— andNonemeans no legend entry.- unitsmapping of
strtostr, optional Construction-only (not stored): unit strings for bare-array fields, keyed by field name, e.g.
units={"pressure": "hPa", "temperature": "degC"}(spec §5).
- pressure
- pressure: pint.Quantity#
- temperature: pint.Quantity#
- dewpoint: pint.Quantity | None = None#
- wind_speed: pint.Quantity | None = None#
- wind_direction: pint.Quantity | None = None#
- time: datetime.datetime | None = None#
- units: dataclasses.InitVar[collections.abc.Mapping[str, str] | None] = None#
- classmethod from_dataframe(df: pandas.DataFrame, *, units: collections.abc.Mapping[str, str] | None = None, station: str | None = None, time: datetime.datetime | None = None, label: str | None = None, **column_map: str) Sounding[source]#
Build a sounding from a pandas DataFrame (spec §3.4).
Column names default to the field names; column_map overrides per field (e.g.
dewpoint="dwpt"). Columns are bare arrays, so the present fields need theunits=mapping.- Parameters:
- df
pandas.DataFrame The profile table; must contain pressure and temperature columns.
- unitsmapping of
strtostr, optional Unit strings keyed by field name (spec §5).
- station
str, optional Station identifier.
- time
datetime.datetime, optional Launch time;
pandas.Timestampandnumpy.datetime64are accepted.- label
str, optional Legend text override.
- **column_map
str Field names mapped to their column names in df.
- df
- Returns:
SoundingThe validated sounding.
- Raises:
- classmethod from_dataset(ds: xarray.Dataset, *, units: collections.abc.Mapping[str, str] | None = None, station: str | None = None, time: datetime.datetime | None = None, label: str | None = None, **var_map: str) Sounding[source]#
Build a sounding from an xarray Dataset (spec §3.4).
Variable names default to the field names; var_map overrides per field. Units are read from each variable’s
attrs["units"](the xarray/CF convention); theunits=mapping is the explicit override.- Parameters:
- ds
xarray.Dataset The profile dataset; must contain pressure and temperature variables.
- unitsmapping of
strtostr, optional Unit strings keyed by field name, overriding
attrs["units"].- station
str, optional Station identifier.
- time
datetime.datetime, optional Launch time;
pandas.Timestampandnumpy.datetime64are accepted.- label
str, optional Legend text override.
- **var_map
str Field names mapped to their variable names in ds.
- ds
- Returns:
SoundingThe validated sounding.
- Raises:
KeyErrorIf a required or explicitly mapped variable is missing.
TephpyUnitsErrorIf a field has neither
attrs["units"]nor aunits=entry.TypeErrorIf var_map names an unknown field.