Your First Footprint#
You will make the footprint of one measurement, a map of where its air came from, with two function calls in Python. Then you will run the same measurement as a project, which is how you run thousands of them and keep the results. The command-line version of the project is at the end.
Before you start#
STILT moves particles with wind fields from a weather model, stored as ARL-format files. You need files covering your measurement time and every hour of the run before it: for a 24-hour backward run, from 24 hours before the measurement to just after it. A simulation with a file missing fails, naming the hours.
If you already have ARL files, for example in a group archive, tell PYSTILT the folder they are in. Each file’s header says which times it holds, so their names do not matter:
met = "/path/to/arl/hrrr"
If you don’t have ARL files, PYSTILT can download them from NOAA’s archive
into a folder you choose. This needs pip install "pystilt[download]".
met = {
"download": "hrrr", # which NOAA ARL archive
"directory": "/path/to/download/folder",
"subgrid_enable": True, # keep only your region
"subgrid_bounds": {"xmin": -114, "xmax": -110, "ymin": 39, "ymax": 42},
}
Warning
NOAA’s files cover whole continents, so the first download for a given period is several gigabytes even though only your region is kept. Downloaded files are reused on later runs. See Meteorology for the available products.
Step 1: Describe your measurement#
A release (receptor) is where and when you measured. This one is a sensor 10 m above the ground on the University of Utah campus, at noon local time (19:00 UTC) on 14 January 2021:
In [1]: import stilt
In [2]: release = stilt.PointRelease(
...: time="2021-01-14 19:00", # UTC
...: longitude=-111.848,
...: latitude=40.766,
...: altitude=10, # meters above ground level
...: )
...:
Step 2: Follow the particles#
stilt.run_trajectories() releases particles at the release and
follows them back in time through the meteorology:
In [3]: particles = stilt.run_trajectories(
...: release,
...: met,
...: n_hours=-12, # follow the air 12 hours back in time
...: numpar=200, # number of particles to release
...: krand=2, # the random numbers a seed can fix
...: seed=42, # same seed, same particles
...: )
...:
n_hoursHow far back in time to follow the air. Negative means backward, which is what you want for measurements. 24 to 72 hours is typical. This page uses 12 because its met files start 13 hours before the measurement.
numparHow many particles to release. More particles give a smoother footprint but take longer. 200 is enough to see the shape. For results you will publish we use 1000, STILT-R’s default, because a footprint from fewer particles is noisy far from the release.
krandandseedHYSPLIT draws random numbers for the turbulence that moves each particle.
krand=2with aseedmakes the draws the same on every run, so your particles match the ones on this page. A project’s config setskrand: 4, STILT-R’s value, under which every run draws its own, and the particles and the footprint change a little from run to run.
Every other HYSPLIT setting takes HYSPLIT’s own default here. A few of those differ from the values STILT-R runs HYSPLIT with, such as whether particles mix by convection. A project, below, writes STILT-R’s values into its config.
This runs HYSPLIT, the transport model, and usually takes a minute or two.
The particles are a pandas.DataFrame, one row per particle per
time step:
In [4]: particles.head()
Out[4]:
age particle lon ... mlht pres time
0 -1.0 1.0 -111.8497 ... 1029.05 854.49 2021-01-14 18:59:00
1 -1.0 2.0 -111.8501 ... 1029.05 857.53 2021-01-14 18:59:00
2 -1.0 3.0 -111.8497 ... 1029.05 856.78 2021-01-14 18:59:00
3 -1.0 4.0 -111.8494 ... 1029.05 857.53 2021-01-14 18:59:00
4 -1.0 5.0 -111.8490 ... 1029.05 857.38 2021-01-14 18:59:00
[5 rows x 21 columns]
In [5]: particles.stilt.plot.map();
The particles start at the release and spread out. The met files here cover
only a small region around Salt Lake, and a particle that leaves the met stops
there. This is how many hours they went (age is in minutes):
In [6]: print(f"{particles['age'].abs().max() / 60:.1f} hours")
12.0 hours
If that is short of n_hours, the footprint covers only those hours.
Checking A Run says when that matters.
Step 3: Calculate the footprint#
The footprint is calculated on a grid. Make it big enough to include the areas upwind of your site. Here the cells are 0.01°, about 1 km:
In [7]: grid = stilt.Grid(
...: xmin=-113.0, xmax=-110.5, # longitude range
...: ymin=40.0, ymax=42.0, # latitude range
...: xres=0.01, yres=0.01, # grid cell size in degrees
...: )
...:
In [8]: foot = stilt.calc_footprint(particles, release, grid)
In [9]: foot.stilt.plot.map();
The footprint starts at the release and stretches in the direction the air came from, here to the north-northwest and then curving west. The map shows the footprint summed over time, on a log scale. Cells with more color influenced the measurement more.
The footprint is an xarray.DataArray with dimensions
(time, lat, lon), in units of ppm per (µmol m⁻² s⁻¹). It has one map for
each hour the particles were still inside the met files. Sum it over time with
xarray:
In [10]: foot.sizes
Out[10]: Frozen({'time': 12, 'lat': 200, 'lon': 250})
In [11]: foot.sum("time").sizes
Out[11]: Frozen({'lat': 200, 'lon': 250})
PYSTILT’s own methods on the particles and the footprint are under
.stilt.
Step 4: Run it as a project#
Two calls are enough for one release. For many releases, make a
Project: a folder that holds your releases and settings,
runs every release, and keeps the results. Project.init creates the folder and writes both to it. The
settings are the ones above, each in the block of what it belongs to: the
transport model’s under models, and the footprint’s under stages,
in a block that names the footprint stage as its class:
In [12]: project = stilt.Project.init(
....: "./my_first_project",
....: releases=[release],
....: mets={"hrrr": met}, # "hrrr" is a name you choose
....: models={
....: "hysplit": {"n_hours": -12, "numpar": 200, "krand": 2, "seed": 42}
....: },
....: stages={
....: "footprint": {"class": "stilt.footprint.FootprintStage", "grid": grid}
....: },
....: variants={"hrrr": {}}, # one variant: these settings, met hrrr
....: )
....:
Before running, check the project. project.check() looks for what would
stop a run before it starts: met files missing for a release’s hours, a
release outside the grid, and a met folder that does not exist. It returns a
table with a row for each thing found, so an empty table means nothing is in
the way:
In [13]: project.check()
Out[13]:
Empty DataFrame
Columns: [check, variant, release, message]
Index: []
The check looks for files, not inside them, so a run that passes it can still fail later, if a met file is damaged. Checking A Run says how to tell.
In [14]: project.run();
run() runs the particles and the footprint of every release, and
returns when they are done.
PYSTILT runs each release once per variant. With the settings above
there is one variant, named hrrr after the met. One release under
one variant is a simulation. Look yours up by the release’s id and
the variant name:
In [15]: sim = project.simulation(release.id, "hrrr")
In [16]: sim.particles.head()
Out[16]:
age particle lon ... sigw tlgr time
0 -1.0 1.0 -111.8497 ... 0.912 1.9972 2021-01-14 18:59:00
1 -1.0 2.0 -111.8501 ... 0.912 1.9972 2021-01-14 18:59:00
2 -1.0 3.0 -111.8497 ... 0.912 1.9972 2021-01-14 18:59:00
3 -1.0 4.0 -111.8494 ... 0.912 1.9972 2021-01-14 18:59:00
4 -1.0 5.0 -111.8490 ... 0.912 1.9972 2021-01-14 18:59:00
[5 rows x 13 columns]
In [17]: sim.footprint.stilt.plot.map();
This footprint can differ a little from the one in Step 3. The seed is the
same, but Project.init wrote STILT-R’s HYSPLIT values into the project’s
config.yaml where they differ from HYSPLIT’s own defaults, which
run_trajectories used in Step 2. Open the file to see them;
Coming From STILT-R lists them.
What PYSTILT wrote#
Your inputs are in the project folder, and the results in its output
folder:
my_first_project/
config.yaml # your settings
releases.csv # your releases
output/
particles/ # where each particle went, one file per simulation
footprint/ # the footprints, one file per simulation
logs/ # HYSPLIT's log of each run
Each result is kept under the settings it was made with. Change a setting and the next run writes new files beside the old ones, so nothing is overwritten. Output Layout has the full layout.
Your settings and releases are saved in the folder, so you can open the project again later without repeating them:
project = stilt.Project("./my_first_project")
Project.init runs once per project. It stops with a
FileExistsError if the folder already has a config.yaml. To change a
setting later, edit config.yaml.
If you call project.run() again, nothing happens. PYSTILT sees that the
outputs already exist and skips them. If you add releases with
project.add_releases(...), only the new ones run.
The same run from the command line#
Create a project folder with a starter config.yaml and releases.csv:
stilt init ./my_first_project
Open my_first_project/config.yaml and set the meteorology folder and the
footprint grid. The blocks are the same as in the Python example
above:
mets:
hrrr: /path/to/arl/hrrr
models:
hysplit:
n_hours: -12
numpar: 200
krand: 2
seed: 42
stages:
footprint:
class: stilt.footprint.FootprintStage
grid:
xmin: -113.0
xmax: -110.5
ymin: 40.0
ymax: 42.0
xres: 0.01
yres: 0.01
variants:
hrrr: {}
Add your release to my_first_project/releases.csv below the header
line, so the file reads:
time,longitude,latitude,altitude
2021-01-14 19:00:00,-111.848,40.766,10
Then check the project, run it, and look at the result:
stilt check ./my_first_project
stilt run ./my_first_project
stilt status ./my_first_project
stilt check lists what would stop a run, such as a met file that is not
there, and exits with 1 when it lists anything. When everything is in place it
prints No problems found. and exits with 0.
Next steps#
Run many releases: Tutorial: A Day Of Tower Footprints
Understand the different release types: Releases (receptors)
More plotting and analysis: Footprints And Particles
Run thousands of simulations on a cluster: On An HPC Cluster (Slurm)