lair.air.stilt#

Stochastic Time-Inverted Lagrangian Transport (STILT) Model.

Functions

Lin2021(dCH4, footprints[, weight, filter_sims])

Estimate basin emissions using Lin et al. 2021 method.

extract_simulation_id(simulation)

Extract simulation id from simulation name

fix_sim_links(old_out_dir, new_out_dir)

Fix sim symlinks if stilt wd was changed

init_project(project[, repo, branch])

Initialize STILT project

Classes

Footprints(footprint_dir[, subset, engine, ...])

Footprints class for STILT simulations.

Receptors(loc, times)

Receptors class for STILT simulations.

STILT(project[, directory, symlink_dir])

STILT class for running STILT simulations.

lair.air.stilt.init_project(project, repo='https://github.com/jmineau/stilt', branch='main')[source]#

Initialize STILT project

Python implementation of Rscript -e “uataq::stilt_init(‘project’)”

Parameters:
projectstr

Name/path of STILT project.

repostr, optional

URL of STILT project repo. The default is jmineau/stilt.

branchstr, optional

Branch of STILT project repo. The default is main.

lair.air.stilt.extract_simulation_id(simulation)[source]#

Extract simulation id from simulation name

Parameters:
simulationstr

Name of simulation.

Returns:
sim_iddict

Dictionary with keys: time, lati, long, zagl.

Fix sim symlinks if stilt wd was changed

Parameters:
old_out_dirstr

old out directory where symlinks currently point to and shouldnt.

new_out_dirstr

new out directory where symlinks should point to.

Returns:
None.
class lair.air.stilt.Receptors(loc, times)[source]#

Receptors class for STILT simulations.

__init__(loc, times)[source]#
generate(loc, times: Series)[source]#

Generate receptor dataframe when given a location and list of datetimes

update(receptors)[source]#

Update data with more receptors from a different Receptors instance

class lair.air.stilt.Footprints(footprint_dir: str, subset: list | bool = False, engine: str = 'rasterio', cache: str | bool = False, reload_cache: bool = False)[source]#

Footprints class for STILT simulations.

Attributes

footprint_dir

(str) Directory containing footprint files.

files

(list[str]) List of footprint files.

cache

(bool | str) Whether to cache the footprints. If True, path to cache file.

foots

(xarray.Dataset) Footprints dataset.

__init__(footprint_dir: str, subset: list | bool = False, engine: str = 'rasterio', cache: str | bool = False, reload_cache: bool = False)[source]#
read(footprint_dir: str, subset: bool | list, engine: str)[source]#

Read footprints from footprint_dir.

Parameters:
footprint_dirstr

Directory containing footprint.

subsetlist | bool

Bounds to subset the footprints. If False, no subsetting.

enginestr

Engine to use to read the footprints.

Returns:
footsxarray.Dataset

Footprints dataset.

sub(subset: list[float])[source]#

Subset the footprints.

Parameters:
subsetlist[float]

Bounds to subset the footprints.

Returns:
xr.Dataset

The subsetted footprints.

get_receptors_locs()[source]#

Get the locations of the receptors.

Returns:
list[dict]

list of dictionaries containing the locations of the receptors.

property area: DataArray#

Calculate the area of the footprints grid.

Returns:
xr.DataArray

Area of the footprints grid.

apply_weights() Dataset[source]#

Apply cosine weights to the footprints.

Returns:
xr.Dataset

Footprints with cosine weights applied.

static get_files(footprint_dir) list[str][source]#

Get footprint files in footprint dir.

Parameters:
footprint_dirstr

Directory containing footprint files.

Returns:
list[str]

List of footprint files.

static plot(foot: DataArray, ax: plt.Axes | None = None, crs: ccrs.CRS | None = None, label_deci: int = 1, tiler=None, tiler_zoom: int = 9, bounds=None, x_buff: float = 0.1, y_buff: float = 0.1, labelsize: int | None = None, more_lon_ticks: int = 0, more_lat_ticks: int = 0) plt.Axes[source]#

Plot footprints on cartopy axes.

Parameters:
footxr.DataArray

Footprints to plot.

axplt.Axes, optional

Cartopy axes, by default None

crsccrs.CRS , optional

Cartopy CRS, by default None

label_deciint, optional

Log 10 decimals, by default 1

tilercartopy.io.img_tiles.GoogleTiles,

Tiler to use for background map, by default None

tiler_zoomint, optional

Zoom level of tiler, by default 9

boundslist[float], optional

Bounds to plot, by default None

x_bufffloat, optional

x buffer, by default 0.1

y_bufffloat, optional

y buffer, by default 0.1

labelsizeint | None, optional

Label size, by default None

more_lon_ticksint, optional

Number of additional longitude ticks, by default 0

more_lat_ticksint, optional

Number of additional latitude ticks, by default 0

Returns:
plt.Axes

Cartopy axes.

class lair.air.stilt.STILT(project: str, directory: str | None = None, symlink_dir: str | None = None)[source]#

STILT class for running STILT simulations.

I don’t think this is ready…

Attributes

project

(str) Name of STILT project.

stilt_wd

(str) Working directory of STILT project.

receptors

(Receptors) Receptors instance.

Methods

generate_receptors(loc, times)

Generate receptors.

get_sims(id_dir)

Get simulations.

get_missing_sims(receptors, id_dir)

Get missing simulations.

read_footprints(footprint_dir, subset, engine, cache, reload_cache)

Read footprints.

get_foots(footprint_dir, subset, engine, cache, reload_cache)

Get footprints.

__init__(project: str, directory: str | None = None, symlink_dir: str | None = None)[source]#

Initialize STILT project.

Parameters:
projectstr

Name of STILT project.

directorystr, optional

Directory to initialize project in, by default None

symlink_dirstr, optional

Directory to create symlink to STILT project, by default None

generate_receptors(loc, times)[source]#

Generate receptors - not ready

get_sims(id_dir: str | None = None) DataFrame[source]#

Get simulations from STILT output directory.

Parameters:
id_dirstr, optional

Directory containing simulations, by default None

Returns:
pd.DataFrame

Simulations.

get_missing_sims(receptors: DataFrame, id_dir=None)[source]#

Get missing simulations from STILT output directory.

Parameters:
receptorspd.DataFrame

Receptors used to generate simulations.

id_dirstr, optional

Directory containing simulations, by default None

Returns:
pd.DataFrame

Missing simulations.

read_footprints(footprint_dir: str | None = None, subset: bool | list = False, engine: str = 'rasterio', cache: bool | str = False, reload_cache: bool = False) Footprints[source]#

_summary_

Parameters:
footprint_dirstr, optional

Directory containing footprint files, by default None

subsetbool | list, optional

Bounds to subset the footprints, by default False

enginestr, optional

Engine to use to read the footprints, by default ‘rasterio’

cachebool | str, optional

Whether to cache the footprints. If True, path to cache file, by default False

reload_cachebool, optional

Whether to reload the cache, by default False

Returns:
Footprints

Footprints instance.

get_foots(footprint_dir: str | None = None, subset: bool | list = False, engine: str = 'rasterio', cache: bool | str = False, reload_cache: bool = False) DataArray[source]#

Get footprints from STILT output directory.

Parameters:
footprint_dirstr | None, optional

Directory containing footprint files, by default None.

subsetbool | list, optional

Bounds to subset the footprints, by default False.

enginestr, optional

Engine to use to read the footprints, by default ‘rasterio’.

cachebool | str, optional

Whether to cache the footprints. If True, path to cache file, by default False.

reload_cachebool, optional

Whether to reload the cache, by default False.

Returns
——-
xr.DataArray

Footprints.

lair.air.stilt.Lin2021(dCH4: Series, footprints: Footprints, weight: bool = False, filter_sims: bool = False) DataFrame[source]#

Estimate basin emissions using Lin et al. 2021 method.

Following this logic, we estimate the Basin-averaged CH4 emissions Φ by dividing the CH4 enhancement measured at HPL by the total footprint integrating over all gridcells i within the Uinta Basin (defined as between 39.9N to 40.5N and 110.6W to 109W), where Φ at daily timescales was determined by dividing the ∆CH4 averaged over the afternoon (13:00–16:00 MST) by the total footprint averaged over the same hours.

Parameters:
dCH4pd.Series

Time series of CH4 enhancements.

footprintsFootprints

Footprints instance.

weightbool, optional

Whether to weight the footprints by area, by default False

filter_simsbool, optional

Whether to filter simulations, by default False.

Returns:
pd.DataFrame

Estimated emissions