lair.inventories.Inventory#

class lair.inventories.Inventory(data, pollutant, src_units=None, time_step='annual', crs='EPSG:4326', version=None, standardize_units=False)[source]#

Bases: BaseGrid

Base class for inventories.

Parameters:
  • data (str | Path | Dataset)

  • pollutant (str)

  • src_units (str | Unit)

  • time_step (str)

  • crs (str)

  • version (str | None)

  • standardize_units (bool)

get_standard_name()[source]#

Get the standard name of the inventory.

Returns:

str – The standard name.

Return type:

str

get_files()[source]#

Get the inventory files.

Returns:

None | list[Path] – The inventory files.

Return type:

None | list[Path]

get_units(pint=False)[source]#

Get the quantity, area, and time units of the inventory data.

Parameters:

pint (bool, optional) – Whether to return pint units, by default False.

Returns:

tuple[Any, Any, Any] – The quantity, area, and time units.

Return type:

tuple[Any, Any, Any]

property absolute_emissions: Dataset#

Calculate the absolute emissions (total per gridcell for time step by variable).

Returns:

xr.DataArray – The absolute emissions.

property total_emissions: DataArray#

Calculate the total emissions by summation over all variables.

Returns:

xr.DataArray – The total emissions.

property collapsed: DataArray#

Collapse the inventory data to a single variable.

Returns:

xr.DataArray – The collapsed data.

property data: Dataset#

The inventory data.

Note

pint units have been dequantified and stored in variable attributes.

Returns:

xr.DataArray | xr.Dataset – The inventory data.

quantify()[source]#

Quantify the data using pint units for each variable.

Returns:

xr.Dataset – The quantified data.

Return type:

Dataset

convert_units(dst_units, inplace=False)[source]#

Convert the units of the data to the desired output units.

Parameters:
  • dst_units (Any) – The destination units.

  • inplace (bool, optional) – Whether to modify the data in place, by default False.

Returns:

Inventory – The inventory with converted units. If inplace=True returns self, otherwise returns a new Inventory copy.

Return type:

Self

integrate()[source]#

Integrate the data over the spatial dimensions to get the total emissions per time step.

Returns:

xr.DataArray – The integrated data.

Return type:

DataArray

regrid(out_grid, method='conservative', inplace=False)[source]#

Regrid the data to a new grid. Uses xesmf for regridding.

Note

At present, xesmf only supports regridding lat-lon grids. self.data must be on a lat-lon grid. Possibly could use xesmf.frontend.BaseRegridder to regrid to a generic grid.

Warning

xarray.Dataset.cf.add_bounds is known to have issues, including near the 180th meridian. Care should be taken when using this method, especially with global datasets.

Parameters:
  • out_grid (xr.DataArray) – The new grid to resample to. Must be a lat-lon grid.

  • method (str, optional) –

    The regridding method, by default ‘conservative’.

    Note

    Other xesmf regrid methods can be passed, but it is highly encouraged to use a conservative method for fluxes.

  • inplace (bool, optional) – Whether to modify the data in place, by default False.

Returns:

Inventory – The regridded inventory. If inplace=True returns self, otherwise returns a new Inventory copy.

Return type:

Self

resample(resolution, regrid_method='conservative', inplace=False)[source]#

Resample the data to a new resolution.

Parameters:
  • resolution (float | tuple[x_res, y_res]) – The new resolution in degrees. If a single value is provided, the resolution is assumed to be the same in both dimensions.

  • regrid_method (str, optional) – The regridding method, by default ‘conservative’.

  • inplace (bool)

Returns:

BaseGrid – The resampled grid

Return type:

Self

reproject(resolution, regrid_method='conservative', inplace=False)[source]#

Reproject the data to a lat lon rectilinear grid.

Parameters:
  • resolution (float | tuple[x_res, y_res]) – The new resolution in degrees. If a single value is provided, the resolution is assumed to be the same in both dimensions.

  • regrid_method (str, optional) – The regridding method, by default ‘conservative’.

  • inplace (bool)

Returns:

BaseGrid – The reprojected grid

Return type:

Self

plot(ax=None, time='mean', sector=None, **kwargs)[source]#

Plot the inventory data.

Parameters:
  • ax (matplotlib.axes.Axes) – The axes to plot on.

  • time (str | int, optional) – The time step to plot, by default ‘mean’. If ‘mean’, the mean emissions are plotted. Otherwise pass a string selector or integer index.

  • sector (str, optional) – The sector to plot, by default None. If None, the total emissions are plotted.

  • kwargs (dict) – Additional keyword arguments to pass to xarray’s plot method.

Returns:

matplotlib.axes.Axes – The axes with the plot.

Return type:

Axes