stilt.footprint.FootprintAccessor.to_paris#

FootprintAccessor.to_paris(particles=None)[source]#

Return the footprint as a PARIS-format dataset, which openghg reads.

The footprint’s hourly layers go to srr_time_resolved by hours back from the release time, H_back. The layer from one hour before the release time to the release time is H_back = 1, because openghg pairs H_back = k with the flux hour that starts k hours before the footprint’s time. H_back = 0, the hour after the release time, stays zero. Only H_back 0 to 23 are resolved, since openghg reads the axis as a time span and a 24th hour would wrap to 0. Layers 24 or more hours back are summed into srr_residual, and srr is the sum of all layers. The values are PYSTILT’s: ppm per (µmol m⁻² s⁻¹) is the same quantity as the PARIS unit, (mol/mol)/(mol/m2/s).

particle_locations_n, _e, _s and _w are the fraction of the particles that first left the footprint grid through that edge, by grid cell along the edge and by 1 km height layer from the ground to 20 km. A particle that stayed inside counts nowhere. They need the particles; without them they are left out, and openghg refuses the file unless it is told not to expect them.

The layers are found from each layer’s time coordinate, not from the name of the layer dimension, so one release of project.footprints().foot works as well as sim.footprint.

Parameters:

particles (DataFrame | None) – The particles the footprint was made from, such as sim.particles. Where they left the grid comes from grid_exits() on the footprint’s grid, and the fractions are of the particles in the table.

Returns:

Dimensions time (one entry, the release time), latitude, longitude, resolution (H_back, 0 to 23 hours) and, with exits, height. A PARIS file holds one site with one entry along time per release: concatenate the datasets of many releases along time with xarray.concat() before writing them with xarray.Dataset.to_netcdf().

Return type:

Dataset

Raises:

ValueError – If the footprint’s layers are not one hour long (make it with tres: 1h), if a layer ends after the release time (a forward run), if the grid is not in longitude and latitude (a projected grid), if the footprint holds several releases or has no release id.

Examples

A footprint of three hourly layers before 18:00, each cell worth 1:

>>> import numpy as np
>>> import pandas as pd
>>> import xarray as xr
>>> release_time = pd.Timestamp("2024-01-15 18:00")
>>> layers = release_time - pd.to_timedelta([3, 2, 1], unit="h")
>>> foot = xr.DataArray(
...     np.ones((3, 2, 2)),
...     dims=("time", "lat", "lon"),
...     coords={"time": layers, "lat": [40.5, 41.5], "lon": [-112.5, -111.5]},
... ).assign_coords(release="202401151800_-111.85_40.77_5")
>>> ds = foot.stilt.to_paris()
>>> ds.srr_time_resolved.sum(["latitude", "longitude"]).values.ravel()[:5]
array([0., 4., 4., 4., 0.])
>>> float(ds.srr.sum())
12.0