
runtraj runs particle dispersion models at scale. You describe where and when particles are
released and the settings to run them under, and it runs the transport model once for each,
on your machine or as a Slurm job array, and keeps the particles where you can find them again.
You choose the transport model and install it yourself. runtraj supports the two below; any
other model, and what is made from the particles afterwards, plug in by the import path of a class.
runtraj is not a model: it runs one, for every release and every set of settings, and
keeps track of what is done.
The guides and the API reference are at https://jmineau.github.io/runtraj.
Status
runtraj is alpha software. There are no backward compatibility guarantees before v1.0, and the
public API may still change.
Installation
Install it from PyPI:
pip install runtraj
For plotting and for downloading meteorology from NOAA, add the complete extra
(runtraj[complete]).
runtraj runs NOAA's HYSPLIT program, hycs_std, but does not include it or its data tables.
It supports HYSPLIT 5.0 and later. Download HYSPLIT from NOAA's Air Resources Laboratory,
which asks you to accept the
HYSPLIT terms of use first. Unpack it, then
set directory under models: hysplit: in config.yaml to the folder it makes, or put that
folder's exec/ on PATH:
models:
hysplit:
directory: /path/to/hysplit
Quickstart
A release is the time and place a run starts from. Run the transport model for one:
import runtraj
release = runtraj.PointRelease(
time="2023-07-15 18:00", # UTC
longitude=-111.848,
latitude=40.766,
altitude=10, # meters above ground
)
met = "/data/hrrr" # a folder of ARL files; their headers say what they hold
particles = runtraj.run_trajectories(release, met, model="hysplit", n_hours=-24, numpar=100)
particles is a pandas DataFrame, one row per particle per step. A negative n_hours follows
the particles backward in time, a positive one forward.
For many releases, a project runs each one and keeps the results:
project = runtraj.Project.init(
"./my_project",
releases=[release],
mets={"hrrr": met},
models={"hysplit": {"n_hours": -24, "numpar": 100}},
variants={"hrrr": {}},
)
project.run() # returns when the run is done
sim = project.simulation(release.id, "hrrr")
sim.particles
Everything is saved in ./my_project. Later, open it again with
runtraj.Project("./my_project"). A second run() only runs what is missing. To change a
setting, edit config.yaml.
Command line
runtraj check ./my_project # list what would stop a run, before any run
runtraj run ./my_project # run every release that is not done yet
runtraj run ./my_project --cpus 8 # the same, eight releases at a time
runtraj submit ./my_project --backend slurm # the same, as a Slurm job array
runtraj status ./my_project # what has finished, and the settings folders
runtraj run exits with 0 when every simulation it ran is complete, 1 when some failed, and 3
when it was stopped, or a connection error stopped some, before they finished.
Variants
A variant is a named set of settings. Every release runs once under each variant, and a
variant's results are in a folder named for its settings, so a changed setting never
overwrites an earlier run. Variants can run different transport models in one project, each
naming its model block:
mets:
hrrr: /data/hrrr # ARL files, for HYSPLIT
era5: /data/era5 # GRIB files from flex_extract, for FLEXPART
models:
hysplit: {directory: /path/to/hysplit, n_hours: -24, numpar: 100}
flexpart: {directory: /path/to/flexpart, eta: true, n_hours: -24, numpar: 100}
variants:
hrrr: {model: hysplit}
hrrr-long: {model: hysplit, n_hours: -72}
era5: {model: flexpart}
Plug-ins
A transport model in another package runs as HYSPLIT and FLEXPART do, and a stage makes one file per
release from the particles after the model runs. config.yaml names each by the import path
of its class, so runtraj imports neither until a project asks for it:
stages:
footprint:
class: stilt.footprint.FootprintStage # PYSTILT's footprint
Citing
If you use runtraj in published work, please cite it through its
Zenodo DOI, which always points to the latest release.
GitHub's "Cite this repository" gives the reference from CITATION.cff.
Use of AI coding agents
This project is developed with the help of AI coding agents, directed and reviewed by the
maintainer, who owns the design and the science.
License
MIT. See LICENSE.