lair.inventories.sum_sectors#

lair.inventories.sum_sectors(data, exclude=None)[source]#

Sum emissions from all sectors in the dataset.

What “all sectors” covers depends on the product: see each inventory’s docstring (e.g. EPA v1 annual includes Forest_Fires, EPA v2 express includes the supplemental PostMeter).

Parameters:
  • data (xr.Dataset) – The inventory data with emissions from multiple sectors as different variables, each with a units attribute, all in the same units.

  • exclude (list of str, optional) – Sectors to leave out of the sum, e.g. ["Forest_Fires"].

Returns:

xr.DataArray – The sum of emissions from the sectors, in their units.

Raises:

ValueError – If exclude names a sector that is not in data, or if the sectors that are summed are in different units (the numbers cannot be added as they are; convert them to one unit first).

Return type:

DataArray

See also

Inventory.total_emissions

This sum of an inventory’s data.

Inventory.integrate

The total over a region, as a mass.

Examples

A sector with no emission in a cell (NaN) adds nothing there:

>>> import xarray as xr
>>> from lair.inventories import sum_sectors
>>> units = {"units": "kg m-2 s-1"}
>>> data = xr.Dataset(
...     {
...         "energy": ("x", [1.0, float("nan")], units),
...         "waste": ("x", [2.0, 3.0], units),
...     }
... )
>>> sum_sectors(data).values
array([3., 3.])
>>> sum_sectors(data, exclude=["energy"]).values
array([2., 3.])