lair.soundings.get_soundings#
- lair.soundings.get_soundings(station='SLC', start=None, end=None, sounding_dir=None, months=None, driver='xarray', download=False)[source]#
Get upper air soundings from the Wyoming archive.
Reads the soundings that are in the station’s folder. It downloads only when asked: see When get_soundings downloads.
- Parameters:
station (str) – The 3-letter station identifier (e.g.
'SLC'). Names the subdirectory of$LAIR_SOUNDING_DIRand the file prefix.start (datetime | str, optional) – The start date and time (inclusive). A time without a time zone follows the UTC rule; one with a time zone is converted to UTC.
end (datetime | str, optional) – The end date and time (inclusive).
sounding_dir (str) – The directory containing the station’s sounding files. Defaults to
$LAIR_SOUNDING_DIR/<station>.months (list[int], optional) – Only use soundings from these months (with
download, only download those).driver ({'xarray', 'pandas'}, optional) – Return interpolated profiles as an xarray Dataset (default), or the merged raw soundings as a pandas DataFrame. The profiles share one set of heights (Read many soundings says which).
download (bool, optional) – Download the soundings the folder lacks, from
starttoend, before reading them. The default, False, downloads nothing.
- Returns:
xr.Dataset | pd.DataFrame – The sounding data.
- Raises:
ValueError – If no sounding is found for the period (the message says to pass
download=Truewhen it is False); ifdownloadis True withoutstartandend; or for an invaliddriver.
See also
download_soundingsDownload soundings without reading them.
Examples
Two made-up soundings in a folder, read as one dataset on the same heights (Read a sounding and compute its potential temperature reads real ones):
>>> import pathlib >>> import tempfile >>> import pandas as pd >>> from lair.soundings import get_soundings >>> folder = pathlib.Path(tempfile.mkdtemp()) >>> for hour, ground in [("2024011500", -8.0), ("2024011512", -5.0)]: ... pd.DataFrame( ... { ... "height": [1289.0, 5100.0], ... "temperature": [ground, -30.0], ... "station": "SLC", ... "time": pd.to_datetime(hour, format="%Y%m%d%H"), ... "elevation": 1289.0, ... } ... ).to_csv(folder / f"SLC_{hour}.csv", index=False) >>> ds = get_soundings(sounding_dir=str(folder)) >>> ds.temperature.sizes Frozen({'time': 2, 'height': 372}) >>> ds.temperature.sel(height=1289.0).values array([-8., -5.])