Categories Manipulations

emiproc.inventories.utils.validate_group(categories_groups: dict[str, list[str]], all_categories: list[str])

Check the validity of a group.

The categories_groups is a mapping from group_name: list_of_categories_in_group. all_categories is a list contaning all categories to check.

This will check that :

  • A category is not included in two groups.

  • That all categories are inside a group.

Parameters:
  • categories_groups – The mapping of how the categories are to be groupped.

  • all_categories – A list of the name of the categories in the inventar.

Raises:

ValueError – if the mapping is not valid.

emiproc.inventories.utils.group_categories(
inv: Inventory,
categories_group: dict[str, list[str]],
ignore_missing: bool = False,
chunk: bool = False,
) Inventory

Group the categories of an inventory in new categories.

Total emissions are summed among the categories. Vertical profiles are weightly averaged, such that the profiles of a category with higher emission is more taken into account. Point sources vertical profiles are not modified.

Parameters:
  • inv – The Inventory to group.

  • categories_group – A mapping of which groups should be greated out of which categries. This will be checked using validate_group() .

  • ignore_missing – If True, function will work even if some categories from the mapping are not in the inventory. Ex. {"group1": ["cat1", "cat2"], "group2": ["cat3", "cat4"]} If cat3 is not in the inventory, the function will work as if {"group1": ["cat1", "cat2"], "group2": ["cat4"]} was passed.

  • chunk – If given, will process the grouping in chunks of categories