Inventories¶
Inventory Class¶
- class emiproc.inventories.Inventory¶
Parent class for inventories.
- Parameters:
name – The name of the inventory. This is going to be used for adding metadata to the output files, and also for the reggridding weights files.
year – The year of the inventory. (optional)
grid – The grid on which the inventory is. Can be none if the invenotry is not defined on a grid. (only shapped emissions)
substances – The
Substancepresent in this inventory.categories – List of the categories present in the inventory.
emission_infos – Information about the emissions. Concerns only the
gdfsfeatures. This is optional, but mandatory for some models (ex. Gramm-Gral).gdf – The GeoPandas DataFrame that represent the whole inventory. The geometry column contains geometric objects for all the grid cells. The other columns should contain the emission value for the substances and the categories.
gdfs – Some inventories are given on more than one grid. For example,
MapLuftZurichis given on a grid where every category has different shape file. In this case gdf must be set to None and gdfs will be a dictionnary mapping only the categories desired.v_profiles – A vertical profiles object.
v_profiles_indexes – A
xarray.DataArraystoring the information of which vertical profile belongs to which cell/category/substance. This allow to map each single emission value from the gdf to a specific profile. See Vertical Profiles for more information.t_profiles_groups – A list of temporal profiles groups. One temporal pattern can be defined by more than one temporal profile. (ex you can combine hour of day and day of week). The main list contains the different groups of temporal profiles. Each group is a list of
TemporalProfile.t_profiles_indexes – Same as
v_profiles_indexes. For the temporal profiles, the indexes point to one of the groups.history – Stores all the operations that happened to this inventory.
- __init__() None¶
- add_gdf(
- category: Category,
- gdf: GeoDataFrame,
Add a gdf contaning emission sources to the inventory.
This will add the category to the inventory and add the data to the inventory.gdfs dictionary.
- Parameters:
category – The category to add.
gdf – The geodataframe containing the data for the category.
- property cell_areas: ndarray¶
Area of the cells in m2 .
These match the geometry from the gdf.
- copy(
- no_gdfs: bool = False,
- profiles: bool = True,
Copy the inventory.
- Parameters:
no_gdfs – Whether the gdfs should not be copied (main gdf and the gdfs).
profiles – Whether the profiles should be copied.
- classmethod from_gdf(
- gdf: GeoDataFrame | None = None,
- name: str = 'custom_from_gdf',
- gdfs: dict[str, GeoDataFrame] = {},
The gdf must be a two level gdf with (category, substance).
- set_crs(*args, **kwargs)¶
Same as geopandas.set_crs() but for inventories.
Perform the conversion in place.
- set_profile(
- profile: VerticalProfile | list[TemporalProfile],
- category: str | None = None,
- substance: str | None = None,
Set a vertical or temporal profile to a specific category and/or substance.
This happens in place. The profile is appened to the existing profiles.
If only one of ‘category’ or ‘substance’ is specified, the profile is assigned to all the categories or substances on the non specified dimension.
- Parameters:
profile – The profile to set. If Vertical profile, a vertical profile. If Temporal profile, a list of temporal profiles.
category – The category to set the profile to.
substance – The substance to set the profile to.
- set_profiles(
- profiles: VerticalProfiles | CompositeTemporalProfiles | list[list[DailyProfile | SpecificDayProfile | WeeklyProfile | MounthsProfile | HourOfYearProfile | HourOfLeapYearProfile | HourOfWeekProfile | Hour3OfDay | Hour3OfDayPerMonth | HourOfWeekPerMonthProfile | DayOfYearProfile | DayOfLeapYearProfile]],
- indexes: DataArray,
Replace the profiles of the invenotry with the new profiles given.
This checks that the indexes are correct and that the coords are matching. If they are not, gives a warning.
If the profiles given are not valid (ex. not the same number of profiles as categories), raises an error.
- to_crs(*args, **kwargs)¶
Same as geopandas.to_crs() but for inventories.
Perform the conversion in place.
- property total_emissions: DataFrame¶
Calculate the total emissions, returning a DataFrame.
Simple accessor to the function
get_total_emissions().
Available Inventories¶
- class emiproc.inventories.tno.TNO_Inventory¶
The TNO inventory.
TNO has grid cell sources and point sources. This handles both.
https://topas.tno.nl/emissions/
All the information of the inventory is stored in a netcdf file.
Each substance is a separate variable in the netcdf file. This class will read the long_name attribute of each variable to determine the substance variables. The long_name attribute should start with emission of . You can then merge the substances from the file to a new set of substances using the substances_mapping argument. A default mapping which should work for general cases is provided.
In the profile files, if you specifiy the substances, you will have to use the names created by the mapping, not the names in the nc file.
- Parameters:
tno_ds – The xarray dataset with the TNO emission data.
- __init__(
- nc_file: PathLike,
- substances_mapping: dict[str, str] = {'ch4': 'CH4', 'co2_bf': 'CO2', 'co2_ff': 'CO2', 'co_bf': 'CO', 'co_ff': 'CO', 'nmvoc': 'VOC', 'nox': 'NOx'},
- profiles_dir: PathLike = None,
- vertical_profiles_dir: PathLike = None,
- temporal_profiles_dir: PathLike = None,
- crs: str = 4326,
- engine: str | None = None,
Create a TNO_Inventory.
- Parameters:
nc_file – Path to the TNO NetCDF dataset.
substances_mapping – How to map the names from the nc files to names for emiproc. See in
TNO_Inventoryfor more information. Specifiying the mapping is important if the names in the nc file are not the same as the ones you want to use in emiproc.profiles_dir – The directory where the profiles are stored. If None the same directory as the nc_file is used.
vertical_profiles_dir – The directory where the vertical profiles are stored. If None profiles_dir is used.
temporal_profiles_dir – The directory where the temporal profiles are stored. If None profiles_dir is used.
engine – The engine to use by xarray to read the nc file. See xarray.open_dataset for more info.
- classmethod __new__(*args, **kwargs)¶
- emiproc.inventories.tno.read_tno_gridded_profiles(
- file_path: Path,
- year: int,
Read the TNO gridded profiles.
- Parameters:
file_path – The path to the file.
year – The year for which to read the profiles.
- Returns:
A tuple with the profiles, the indexes and the grid.
Profiles: The profiles from the file
Indexes: The indexes of the profiles
- Grid: The grid on which the profiles are defined. Usually not the same
as the inventory grid.
- class emiproc.inventories.edgar.EDGARv8¶
The EDGAR inventory.
Emissions Database for Global Atmospheric Research
The files are freely available. There are different versions. The one we use here is the Annual sector-specific gridmaps and we scale them over the months using the Monthly time series files.
Download the files you want to include and provide the path to the directory containing the files.
For more information about the edgar files, see
download_edgar_files().EDGAR has only grid cell sources.
- __init__(
- nc_file_pattern_or_dir: PathLike,
- year: int | None = None,
- use_short_category_names: bool = False,
Create an EDGAR Inventory from the given data files.
- Parameters:
nc_file_pattern_or_dir – Pattern or directory of files.
year – Year of the inventory.
use_short_category_names – Use short category names.
- classmethod __new__(*args, **kwargs)¶
- emiproc.inventories.edgar.download_edgar_files(
- data_dir: PathLike,
- year: int,
- categories: list[str] = ['ENE', 'REF_TRF', 'IND', 'TNR_Aviation_CDS', 'TNR_Aviation_CRS', 'TNR_Aviation_LTO', 'TNR_Aviation_SPS', 'TRO', 'TNR_Other', 'TNR_Ship', 'RCO', 'PRO_FFF', 'NMM', 'CHE', 'IRO', 'NFE', 'NEU', 'PRU_SOL', 'ENF', 'MNM', 'AWB', 'AGS', 'N2O', 'SWD_LDF', 'SWD_INC', 'WWT', 'IDE'],
- substances: list[str] = ['CO2', 'CH4', 'N2O', 'CO2bio', 'GWP_100_AR5_GHG'],
- version: str = 'v2024',
- link_template: str | None = None,
Download EDGAR files.
The files are downloaded from the EDGAR website. Using version or link_template, defines what is the link to download.
EDGAR has different links for greenhouse gases and air pollutants. If you want to donwload both, you will have to do it call this function twice, once for the GHGs and once for the APs.
- Parameters:
data_dir – Directory to download the files to.
year – Year of the inventory.
categories – List of categories to download.
substances – List of substances to download.
version – Version of the inventory. Versions that starts with “AP” are for air pollutants. Others are for greenhouse gases. Versions available: [“v8.0”, “AP_v8.1”, “v2024”]
link_template – Link template to use instead of the version.
- class emiproc.inventories.swiss.SwissRasters¶
An inventory of Switzerland based on swiss rasters.
- __init__(
- filepath_csv_totals: Path,
- filepath_point_sources: Path,
- rasters_dir: PathLike,
- rasters_str_dir: PathLike,
- requires_grid: bool = True,
- year: int = 2015,
- point_source_correction: dict[Category, PointSourceCorrection] = {'eidep': PointSourceCorrection.KEEP_RASTER_ONLY, 'eikla': PointSourceCorrection.KEEP_RASTER_ONLY, 'eipkv': PointSourceCorrection.KEEP_POINT_SOURCE_ONLY_SCALED_TO_RASTER_TOTAL, 'eiprd': PointSourceCorrection.REMOVE_POINT_SOURCE_FROM_RASTER_TOTAL, 'eipro': PointSourceCorrection.REMOVE_POINT_SOURCE_FROM_RASTER_TOTAL, 'eipzm': PointSourceCorrection.KEEP_POINT_SOURCE_ONLY_SCALED_TO_RASTER_TOTAL},
Create a swiss raster inventory.
- Parameters:
filepath_csv_totals – Csv file containing total emissions for each category/substance for different years.
filepath_point_sources – Excel file containing point sources. See in
emiproc.inventories.swiss.read_prtr()for more details.rasters_dir – The folder where the rasters are found.
rasters_str_dir – The folder where the rasters pro substance are found.
requires_grid – Whether the grid should be created as well. Creating the shapes for the swiss grid is quite expensive process. Most of the weights for remapping can be cached so if you have them generated already, set that to false.
year – The year of the inventory that should be used. This should be present in the Emissions_CH.xlsx file. The raster files are the same for all years. Only the scaling of the full raster pro substance changes.
- classmethod __new__(*args, **kwargs)¶
- emiproc.inventories.swiss.read_prtr(
- prtr_file: PathLike,
- year: int,
- substances: list[Substance] | None = None,
Read the PRTR file and return the gdfs.
If you want to change the substances or the categories, you can do it by changing the dictionaries in the emiproc.inventories.swiss module.
- Parameters:
prtr_file – Path to the PRTR file. This file must be downloaded from the Swiss PRTR website https://www.bafu.admin.ch/bafu/de/home/themen/chemikalien/zustand/schadstoffregister-swissprtr.html then go in the ‘Datenpublikation’ section and download the Excel file
year – The year of the data to use.
substances – List of substances to use. If None, all substances will be used.
- Returns:
A dictionary with the categories as keys and the GeoDataFrames as values. Can be used to create the Inventory object.
- class emiproc.inventories.zurich.MapLuftZurich¶
Inventory of Zurich based on the mapluft.gbd file.
It contains only shaped emissions for each categories.
- __init__(
- mapluft_gdb: PathLike,
- substances: list[Substance] = ['CO2', 'CO', 'PM10ex', 'PM10non', 'PM25ex', 'PM25non', 'SO2', 'NOx', 'N2O', 'NH3', 'CH4', 'BC', 'VOC', 'benzene'],
- categories: list[Category] = [],
- remove_josefstrasse_khkw: bool = False,
- convert_lines_to_polygons: bool = True,
Load the mapluft inventory.
- Parameters:
mapluft_gdb – The Mapluft file
substances – A list of substances to load. (by default all of them). Categories not contianing any of the substances are not loaded.
categories – A list of categories to load (if one is interested in only a subset). If not specified, all categories are loaded.
remove_josefstrasse_khkw – Whether the incineration plant at josefstrasse should be removed from the inventory. Emission for category ‘c2301_KHKWKehricht_Emissionen_Kanton’ at the Josefstrasse location will be removed from the inventory. It should be planned to be removed in March 2021. The other Josefstrasse category will still be present, as they account for some kinds of energy production. In case remove_josefstrasse_khkw, the emissions are not set to any other location in the inventory.
convert_lines_to_polygons – Whether this should convert line emissions to polygons. Only few models can handle line emissions. The default width of the line is 10m for all categories. This is not currently not changeable.
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.zurich.duck.DuckDBInventory¶
Inventory backed on a DuckDB SQL file.
Data is organized the following way:
a table for each category
columns for each substance
geometry column for shapes
year column if multiple years are present
- Parameters:
duckdb_filepath – Path to the duckDB file.
year – Year of the emissions to load.
skip_suffixes – List of suffixes to skip when loading tables.
- __init__(
- duckdb_filepath: PathLike,
- year: int,
- skip_suffixes: list[str] = ['_ef', '_p'],
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.netcdf_raster.NetcdfRaster¶
Netcdf inventory.
Read an inventory defined on a regular lat/lon grid.
Can read inventories created by
export_raster_netcdf().By default, it will try to read the variables in the netcdf file and infer their category and substance from the attributes. If this doesn’t work, you can provide a mapping from netcdf variable names to (category, substance) tuples via the variable_to_catsub parameter.
- Parameters:
file – Path to the netcdf file.
variable_to_catsub – Dictionary mapping variable names in the netcdf file to (category, substance) tuples.
lat_name – Name of the latitude variable in the netcdf file.
lon_name – Name of the longitude variable in the netcdf file.
time_name – Name of the time variable in the netcdf file.
unit – Unit of the variables in the netcdf file. If None, the unit will be read from the netcdf file.
temporal_profile – Temporal profile class to use for inventories with multiple time steps.
year – Year of the inventory. If None, will try to read from the netcdf file. If multiple years are present, must be specified.
- __init__(
- file: PathLike,
- variable_to_catsub: dict[str, tuple[Category, Substance]] | None = None,
- lat_name: str = 'lat',
- lon_name: str = 'lon',
- time_name: str = 'time',
- unit: str | None = None,
- temporal_profile: type[DailyProfile | SpecificDayProfile | WeeklyProfile | MounthsProfile | HourOfYearProfile | HourOfLeapYearProfile | HourOfWeekProfile | Hour3OfDay | Hour3OfDayPerMonth | HourOfWeekPerMonthProfile | DayOfYearProfile | DayOfLeapYearProfile] | None = None,
- year: int | None = None,
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.gfas.GFAS_Inventory¶
- __init__(*args, **kwargs)¶
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.gfed.GFED4_Inventory¶
Global Fire Emissions Database.
Global inventory based on satellite data, burned areas, fuel consumption.
https://www.globalfiredata.org/
You can download the input data for various year at https://www.geo.vu.nl/~gwerf/GFED/GFED4/
This uses the area inside the GFED file to calculate the total emissions, but we found out that the area is not exactly the same as the one calculated by geopandas. See
GFED_Gridfor the grid information.- The data set contains two variables:
C: Carbon emissions
DM: Dry matter emissions
Has to be specified which one to use with the use_variable argument.
Note
This inventory applies only for GFED4 . GFED5 has changed the format and is not supported by this class.
- __init__(
- gfed_filepath: PathLike,
- year: int,
- use_variable: str = 'DM',
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.lpjguess.LPJ_GUESS_Inventory¶
LPJ-GUESS inventory.
This is an implementation to read netcdf outputs from LPJ-GUESS.
https://web.nateko.lu.se/lpj-guess/
- __init__(lpj_guess_files: list[Path], year: int)¶
Initialize the inventory.
Parameters¶
- lpj_guess_files:
List of paths to the LPJ-GUESS files.
- year:
The year for which the inventory is created. Used to know if the year is leap or not.
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.saunois.SaunoisInventory¶
Inventory based on Saunois estimates of methane emissions.
https://doi.org/10.5194/essd-12-1561-2020
You can download the data there but note that the current implementation had some other files as sources, but very similar. https://www.icos-cp.eu/GCP-CH4-2024
- __init__(saunois_files: list[Path])¶
Initialize the inventory.
Parameters¶
- saunois_files :
List of paths to the Saunois files. Here each netcdf is named after the category. If you donwload from the ICOS website, you will have to rename the files. Or change the code for this inventory.
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.gral.GralInventory¶
Gral inventory.
Load the inputs of a gral simulation.
Warning
There are some things not implemented yet: - The portals file - Emission Infos (exit velocity, heights, …) - Shared utilites between thefiles (many code is duplicated accros funcitons)
- __init__(
- emissions_dir: PathLike,
- source_group_mapping: dict[int, tuple[Substance, Category]] | None = None,
- crs: str | int = 4326,
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.cams_reg_aq.CAMS_REG_AQ¶
The CAMS regional air quality inventory.
Contains gridded data of air pollutants (NOx, CO, CH4, VOC, NH3, SO2, PM2.5, PM10) from the Copernicus Atmosphere Monitoring Service (CAMS).
You can access the data at CAMS-REG-ANT v6.1-Ref2
- __init__(
- nc_dir: PathLike,
- year: int = 2022,
- substances_mapping: dict[str, str] = {'ch4': 'CH4', 'co': 'CO', 'nh3': 'NH3', 'nmvoc': 'VOC', 'nox': 'NOx', 'pm10': 'PM10', 'pm2_5': 'PM25', 'sox': 'SO2'},
- categories_mapping: dict[str, str] = {'A_PublicPower': 'A', 'B_Industry': 'B', 'C_OtherStationaryComb': 'C', 'D_Fugitives': 'D', 'E_Solvents': 'E', 'F_RoadTransport': 'F', 'G_Shipping': 'G', 'H_Aviation': 'H', 'I_OffRoad': 'I', 'J_Waste': 'J', 'K_AgriLivestock': 'K', 'L_AgriOther': 'L'},
Create a CAMS_REG_ANT-inventory.
- Parameters:
nc_dir – The directory containing the NetCDF emission datasets. One file per air pollutant.
year – Year of the inventory.
substances_mapping – How to map the names of air pollutants from the names of the NetCDF files to names for emiproc.
categories_mapping – How to map the names of the emission categories from the NetCDF files to names for emiproc.
- classmethod __new__(*args, **kwargs)¶
- class emiproc.inventories.wetcharts.WetCHARTs¶
WetCHARTs inventory.
This class is used to read the WetCHARTs file into an inventory.
More information about the WetCHARTs is available at: https://daac.ornl.gov/CMS/guides/MonthlyWetland_CH4_WetCHARTsV2.html
- Parameters:
wetcharts_file – Path to the WetCHARTs file. It can be downloaded from the link above, after creating an account.
model – Model number to select from the dataset. Few keys are available. To see the available models, please check the data specification in the link above. If None, a mean of all models is used.
category – Category name to use in the inventory.
substance – Substance name to use in the inventory.
- __init__(
- wetcharts_file: PathLike,
- model: int | None = None,
- category: str = 'wetcharts',
- substance: str = 'CH4',
- classmethod __new__(*args, **kwargs)¶