Operators¶
Inventory Operators¶
- emiproc.inventories.utils.add_inventories(inv: Inventory, other_inv: Inventory) Inventory¶
Add inventories together.
The following conditions must be required:
if the two invs have a gdf, they must be on the same grid
- Parameters:
inv – The first inventory.
other_inv – The second inventory.
- emiproc.inventories.utils.combine_inventories(
- inv_inside: Inventory,
- inv_outside: Inventory,
- separated_shape: Polygon,
- output_grid: Grid | None = None,
Combine two inventories and use a shape as the boundary between the two inventories.
Note
This is not implemented yet. One should be careful about this implementation steps. Some comments are already in the code for what should be done.
- emiproc.inventories.utils.scale_inventory(
- inv: Inventory,
- scaling_dict: dict[str, dict[str, float]] | float,
Get the total emissions from the inventory.
- Parameters:
inv – The inventory from which to get the total emissions.
scaling_dict –
A dictionary mapping substances to another dictionary which maps categories to values. The values must be scaling factor, which will multiply all the objects from the inventory with matching categories and substance.
If a category/substance is not in the dict, it will not be scaled. For exemple
{ "CO2": { "cat1": 1.3, "cat2": 0.7, }, "CH4": { "cat2": 1.2, }, }
Alternatively, a float can be given, which will scale all the emissions.
If you have a gridded inventory (no gdfs emissions), you can also scale each grid cell individually by giving arrays of the same length as the number of grid cells.
- Returns:
A new inventory with its emission values rescaled.
- emiproc.inventories.utils.get_total_emissions(inv: Inventory) dict[str, dict[str, float]]¶
Get the total emissions from the inventory.
- Parameters:
inv – The inventory from which to get the total emissions.
- Returns:
A dictionary mapping substances to another dictionary which maps categories to values. A ‘__total__’ key will be created in each substnace mapping with the total of all the categories.
For exemple
{ "CO2": { "cat1": 3.2, "cat2": 4.3, "__total__": 7.5, }, "CH4": { "cat2": 2.1, "__total__": 2.1, }, ... }
- emiproc.inventories.utils.drop(
- inv: Inventory,
- substances: list[Substance] = [],
- categories: list[Category] = [],
- keep_instead_of_drop: bool = False,
Drop substances and categories from an inventory.
This will drop all the emissions related to the substances and categories from the inventory.
If both substances and categories are specified, the emissions will be dropped if they are in any of the two lists.
- Parameters:
inv – The inventory to drop from.
substances – The substances to drop.
categories – The categories to drop.
keep_instead_of_drop – If True, the substances and categories will be kept instead of being dropped.
Profiles Operators¶
A set of operators to manipulate profiles in inventories.
- emiproc.inventories.utils.country_to_cells(
- inv: Inventory,
- country_mask_kwargs: dict[str, Any] = {},
- ignore_missing_countries: bool = False,
- fraction_method: bool = False,
Convert the country profiles of an inventory to cell profiles.
This will convert the country profiles to cell profiles, such that the emissions are distributed over the cells of the grid. The country profiles are assumed to be in the gdf of the inventory.
This uses the
emiproc.profiles.operators.profiles_country_to_cells()function internally.- Parameters:
inv – The inventory to convert.
country_mask_kwargs – Additional keyword arguments to pass to the
emiproc.profiles.operators.profiles_country_to_cells()function.ignore_missing_countries – If True, the function will ignore missing countries in the profiles. If False, it will raise an error if some countries are missing in the profiles.
- Returns:
A new inventory with the country profiles converted to cell profiles.
- emiproc.inventories.utils.interpolate_temporal_profiles(
- inv: Inventory,
- interpolation_method: str = 'linear',
- output_type: TemporalProfilesInterpolated = TemporalProfilesInterpolated.HOUR_OF_YEAR,
Interpolate the temporal profiles of an inventory.
This will interpolate the temporal profiles of the inventory to create a new inventory with the interpolated profiles.
This function uses
emiproc.profiles.temporal.operators.interpolate_profiles()internally. Have a look for more details on the interpolation.- Parameters:
inv – The inventory to interpolate.
interpolation_method – The method to use for the interpolation.
output_type – The output type of the interpolation.
- Returns:
A new inventory with the interpolated temporal profiles.
Geometric Transformations¶
- emiproc.inventories.utils.crop_with_shape(
- inv: Inventory,
- shape: Polygon,
- keep_outside: bool = False,
- weight_file: PathLike | None = None,
- modify_grid: bool = False,
Crop the inventory with the provided shape.
Keeps only the part of the emissions that is included inside the shape. Emissions at the boundary with the shapes will see their values based on the fraction which is inside the shape.
Point sources located exactly at the boundary will have their emissions value divided by 2.
This might removes categories and substances from the inventory, if they are not present anymore !
- Parameters:
inv – The inventory to crop.
shape – The shape around which to crop the inv.
keep_outside – Whether to keep only the emissions outside of the shape.
weight_file – A file in which to store the weights. If modify_grid is True, this will also save the shapes of the output. However saving/reading those shape can be slower than computing them.
modify_grid – Whether the main grid (the gdf) should be modified. Grid cells cropped will disappear. Grid cells intersected will be replaced by the intersection with the shape.
Warning
Make sure your shape is in the same crs as the inventory.
- emiproc.inventories.utils.clip_box(
- inv: Inventory,
- minx: float,
- miny: float,
- maxx: float,
- maxy: float,
Clip an inventory to a bounding box.
- Parameters:
inv – The inventory to clip.
minx – The minimum x coordinate of the bounding box.
miny – The minimum y coordinate of the bounding box.
maxx – The maximum x coordinate of the bounding box.
maxy – The maximum y coordinate of the bounding box.
- Returns:
A new inventory clipped to the bounding box.
- emiproc.regrid.remap_inventory(
- inv: Inventory,
- grid: Grid | gpd.GeoSeries,
- weights_file: PathLike | None = None,
- method: str = 'new',
- keep_gdfs: bool = False,
- weigths_file: PathLike | None = None,
- dont_remap_profiles: bool = False,
Remap any inventory on the desired grid.
This will also remap the additional gdfs of the inventory on that grid.
- Parameters:
inv – The inventory from which to remap.
grid – The grid to remap to.
weights_file – The file storing the weights.
method – The method to use for remapping. See
calculate_weights_mapping().keep_gdfs – Whether to keep the additional gdfs (shaped emissions) of the inventory.
dont_remap_profiles – Whether to not merge the profiles when remapping them. see
remap_profiles()for more information.
Warning
To make sure the grid is defined on the same crs as the inventory, this funciton will call geopandas.to_crs to the grid geometries.