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:
BaseGridBase class for inventories.
An inventory holds a flux on a grid, one variable per sector, with pint units. The subclasses (
EDGARv8and 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
dataandstandardize_unitsis 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
unitsattribute is used (and every variable must have one). Variables in different units are kept as they are, but the totals (total_emissions,integrate()) raise aValueErroruntil they are converted to one unit:standardize_units=True, orconvert_units().time_step (str, optional) – The time step of the data, by default ‘annual’:
'annual','monthly','quarterly','biweekly','daily'or'hourly'.absolute_emissionsmultiplies 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) asconvert_units()converts them. If False, the units of each variable are retained as-is.
- Raises:
FileNotFoundError – If
datais a path with no files.ValueError – If
datais neither a path nor a Dataset, or a variable has no units.
See also
EDGARv8An inventory read from EDGAR’s files.
sum_sectorsThe 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
The mass emitted in each grid cell in each time step, sector by sector. |
|
Collapse the inventory data to a single variable. |
|
The inventory data. |
|
The flux in each grid cell, summed over the sectors. |
Methods
|
Convert the units of the data to the desired output units. |
Get the inventory files. |
|
Get the standard name of the inventory. |
|
|
Get the quantity, area, and time units of the inventory data. |
Return the total mass emitted over the whole grid in each time step. |
|
|
Plot the inventory data. |
|
Quantify the data using pint units for each variable. |
|
Regrid the data to a new grid. |
|
Reproject the data to a lat lon rectilinear grid. |
|
Resample the data to a new resolution. |
Inherited
From BaseGrid: clip, copy, gridcell_area