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.

An inventory holds a flux on a grid, one variable per sector, with pint units. The subclasses (EDGARv8 and the others) read a product’s files; this class also takes a dataset of your own.

Time labels mark the start of each time step, whatever the provider uses: Jan 1 for annual data, the 1st of the month for monthly, 00:00 for daily and the top of the hour for hourly. So sel(time="2020-01-01") selects January 2020 in every monthly inventory.

Each parameter but data and standardize_units is also an attribute of the same name.

Parameters:
  • data (str | Path | xr.Dataset) – The inventory data. If a string or Path, the path to the data. If an xr.Dataset, the data itself. Data should have dimensions of time, lat, lon and each variable should be a different emissions sector. If the source data is not in the correct format, the _process method should be overridden.

  • pollutant (str) – The pollutant, as a chemical formula ('CH4'). An all-lowercase name is upper-cased ('ch4'); a mixed-case one is kept ('NOx').

  • src_units (str, optional) – The source units of the data, by default None. If given, every variable is taken to be in these units. If None, each variable’s own units attribute is used (and every variable must have one). Variables in different units are kept as they are, but the totals (total_emissions, integrate()) raise a ValueError until they are converted to one unit: standardize_units=True, or convert_units().

  • time_step (str, optional) – The time step of the data, by default ‘annual’: 'annual', 'monthly', 'quarterly', 'biweekly', 'daily' or 'hourly'. absolute_emissions multiplies by its length.

  • crs (str, optional) – The CRS of the data, by default ‘EPSG:4326’.

  • version (str, optional) – The version of the inventory, by default None.

  • standardize_units (bool, optional) – Whether to standardize the units of all variables to the same units, by default False. If True, all variables are assumed to be emissions and are converted to DST_UNITS (kg km-2 d-1) as convert_units() converts them. If False, the units of each variable are retained as-is.

Raises:
  • FileNotFoundError – If data is a path with no files.

  • ValueError – If data is neither a path nor a Dataset, or a variable has no units.

See also

EDGARv8

An inventory read from EDGAR’s files.

sum_sectors

The sum of the sectors.

Examples

An inventory of your own: one sector, a flux of 1e-9 kg m-2 s-1 on four cells of 0.1 degree, in 2019 and 2020:

>>> import numpy as np
>>> import pandas as pd
>>> import xarray as xr
>>> from lair.inventories import Inventory
>>> ds = xr.Dataset(
...     {"energy": (("time", "lat", "lon"), np.full((2, 2, 2), 1e-9))},
...     coords={
...         "time": pd.date_range("2019-01-01", periods=2, freq="YS"),
...         "lat": [40.05, 40.15],
...         "lon": [-111.95, -111.85],
...     },
... )
>>> inv = Inventory(ds, pollutant="CH4", src_units="kg m-2 s-1")
>>> inv.get_units()
('kg', 'm**2', 's')
>>> (inv.integrate() / 1e3).values.round()  # tonnes; 2020 has a day more
array([11943., 11976.])

Attributes

absolute_emissions

The mass emitted in each grid cell in each time step, sector by sector.

collapsed

Collapse the inventory data to a single variable.

data

The inventory data.

total_emissions

The flux in each grid cell, summed over the sectors.

Methods

convert_units(dst_units[, inplace])

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

get_files()

Get the inventory files.

get_standard_name()

Get the standard name of the inventory.

get_units([pint])

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

integrate()

Return the total mass emitted over the whole grid in each time step.

plot([ax, time, sector])

Plot the inventory data.

quantify()

Quantify the data using pint units for each variable.

regrid(out_grid[, method, inplace])

Regrid the data to a new grid.

reproject(resolution[, regrid_method, inplace])

Reproject the data to a lat lon rectilinear grid.

resample(resolution[, regrid_method, inplace])

Resample the data to a new resolution.

Inherited

From BaseGrid: clip, copy, gridcell_area