am-python¶
Python bindings for Scott Paine’s am atmospheric model, via Rust (PyO3).
Install¶
Pre-built wheels are available on PyPI for Linux:
uv pip install am-python
From source¶
Requires the am source code (tested on v14.0), a C compiler, and a Rust toolchain.
curl -fsSL "https://zenodo.org/records/13748403/files/am-14.0.tgz?download=1" | tar -xz
export AM_SRC_DIR=$PWD/am-14.0/src
uv pip install .
Usage¶
Single model¶
import am
m = am.Model("SPole_JJA_75.amc", [0, "GHz", 350, "GHz", 0.01, "GHz", 35, "deg", 1.0])
m.compute()
# numpy array, GHz
m.frequency
# dict of computed outputs
m.outputs
# Rayleigh-Jeans brightness temperature, K
m.outputs["tb_rj"]
Parameter sweep¶
import xarray as xr
import am
params = xr.Dataset(coords={
"elevation": [30, 45, 60, 75], # deg
"pwv": [0.5, 1.0, 2.0], # mm
})
ds = am.ModelGrid(
"SPole_JJA_75.amc",
params,
args_fn=lambda elevation, pwv: [
0, "GHz", 350, "GHz", 0.5, "GHz", elevation, "deg", pwv
],
).compute()
# xr.Dataset with dims (elevation, pwv, frequency)
ds["tb_rj"].sel(elevation=45, pwv=1.0)
For irregular grids (e.g. a set of specific elevation/PWV pairs), use variables on a shared dimension instead:
import numpy as np
params = xr.Dataset({
"elevation": ("obs", elev_array),
"pwv": ("obs", pwv_array),
})
Development¶
This project uses just to orchestrate common tasks and pre-commit for local checks.
# install deps
just sync
# run tests
just test
just test py
just test rs
# run formatting/lint checks
just fmt
just fmt-check
just lint
just typecheck
# build docs
just docs
just docs py
just docs rs
# run pre-commit hooks on all files
just precommit
just prepush
Internal Rust crate documentation is available here.