Exporting

emiproc.exports.netcdf.nc_cf_attributes(
author: str = 'emiproc',
contact: str = 'https://emiproc.readthedocs.io/en/master/support.html#contact',
title: str = 'emiproc generated file',
source: str = '',
comment: str = '',
institution: str = 'Empa, Swiss Federal Laboratories for Materials Science and Technology',
history: str = '',
references: str = 'Produced by emiproc.',
script: PathLike | None = None,
additional_attributes: dict[str, str] | None = None,
) dict[str, str]

Create attributes for a nc file based on cf conventions.

Most of the following instructions at https://cfconventions.org/Data/cf-conventions/cf-conventions-1.10/cf-conventions.html#_attributes

Some additional fields to the cf-conventions (author, contact) are added for simplifying data sharing.

Parameters:
  • author – The author of the file.

  • contact – The contact address (email) of a person that can be contacted if one has questions about the file.

  • title – A succinct description of what is in the dataset.

  • institution – Specifies where the original data was produced.

  • source – The method of production of the original data. If it was model-generated, source should name the model and its version, as specifically as could be useful. If it is observational, source should characterize it (e.g., “surface observation” or “radiosonde”).

  • history – Provides an audit trail for modifications to the original data. Well-behaved generic netCDF filters will automatically append their name and the parameters with which they were invoked to the global history attribute of an input netCDF file We recommend that each line begin with a timestamp indicating the date and time of day that the program was executed.

  • references – Published or web-based references that describe the data or methods used to produce it.

  • comment – Miscellaneous information about the data or methods used to produce it.

  • script – The path to the script that was used to generate the file.

  • additional_attributes – Any attribute you want to add to the netcdf file produced.

emiproc.exports.icon.export_icon_oem(
inv: Inventory,
icon_grid_file: PathLike,
output_dir: PathLike,
group_dict: dict[str, list[str]] = {},
temporal_profiles_type: TemporalProfilesTypes = TemporalProfilesTypes.THREE_CYCLES,
nc_attributes: dict[str, str] = {'Conventions': 'CF-1.10', 'author': 'emiproc', 'comment': 'This file was automatically generated by emiproc', 'contact': 'https://emiproc.readthedocs.io/en/latest/support.html#contact', 'creation_time': '2026-05-28 14:10:34', 'history': '2026-05-28 14:10:34: created by emiproc ;\n', 'institution': 'Empa, Swiss Federal Laboratories for Materials Science and Technology', 'references': 'Produced by emiproc.', 'source': 'unspecified', 'title': 'emiproc generated file'},
substances: list[str] | None = None,
correct_tz_shift: bool = True,
year: int | None = None,
)

Export to a netcdf file for ICON OEM.

The inventory should have already been remapped to the emiproc.grids.ICONGrid .

For ICON-OEM you will need to add in the ICON namelist the path the files produced by this module:

! oem_nml: online emission module ---------------------------------------------
&oemctrl_nml
gridded_emissions_nc        =   '${OEMDIR}/oem_gridded_emissions.nc'
vertical_profile_nc         =   '${OEMDIR}/vertical_profiles.nc'
hour_of_day_nc              =   '${OEMDIR}/hourofday.nc'
day_of_week_nc              =   '${OEMDIR}/dayofweek.nc'
month_of_year_nc            =   '${OEMDIR}/monthofyear.nc'
! If you use the hour of year profile, use this instead of the three above
! hour_of_year_nc             =   '${OEMDIR}/hourofyear.nc'
/

Values will be converted from emiproc units: kg/y to OEM units kg/m2/s . The grid cell area given in the icon grid file is used for this conversion, and 365.25 days per year.

Temporal profiles are adapted to the different countries present in the data. Shifts for local time are applied to the countries individually. Grid cells are assigned to a country using the timezone mask from emiproc.utilities.get_timezone_mask() and country ids are set as the country_id attribute of the output NetCDF file.

Parameters:
  • inv – The inventory to export.

  • icon_grid_file – The icon grid file.

  • output_dir – The output directory.

  • group_dict – If you groupped some categories, you can optionally add the groupping in the metadata.

  • country_resolution – The resolution can be either ‘10m’, ‘50m’ or ‘110m’

  • temporal_profiles_type – The type of temporal profiles to use. Can be either HOUR_OF_YEAR or THREE_CYCLES

  • year – The year to use for the temporal profiles. This is mandatory only with temporal_profiles_type set to HOUR_OF_YEAR

  • nc_attributes – The attributes to add to the netcdf file.

  • substances – The substances to export. If None, all substances of the inv.

emiproc.exports.icon.make_icon_time_profiles(
catsubs: dict[tuple[Category, Substance], str],
time_profiles: CompositeTemporalProfiles,
inv: Inventory,
profiles_indexes: DataArray | None,
regions: DataArray,
profiles_type: TemporalProfilesTypes = TemporalProfilesTypes.THREE_CYCLES,
out_dir: PathLike | None = None,
nc_attrs: dict[str, str] = {'Conventions': 'CF-1.10', 'author': 'emiproc', 'comment': 'This file was automatically generated by emiproc', 'contact': 'https://emiproc.readthedocs.io/en/latest/support.html#contact', 'creation_time': '2026-05-28 14:10:34', 'history': '2026-05-28 14:10:34: created by emiproc ;\n', 'institution': 'Empa, Swiss Federal Laboratories for Materials Science and Technology', 'references': 'Produced by emiproc.', 'source': 'unspecified', 'title': 'emiproc generated file'},
correct_tz_shift: bool = True,
) dict[str, Dataset]

Make the profiles in the format for icon oem.

Parameters:
  • time_profiles – A dictionary with the names of variables in the file as keys and the profiles as values.

  • time_zones – A list with valid timezones names that have to be included.

  • profiles_type – The type of profiles to use.

  • year – Used for the HOUR_OF_YEAR option.

  • out_dir – The directory where to export the files. If None, the files are not saved and dataset returned.

Note

OEM can differentiate profiles based on the grid cell. It tries to group grid cells in what it calls “countries”. This should not be mixed with the real countries. The countries identifiers should match between the emission files.

Warning

Currently the same profiles are used for all the countries. Only the shifts are different.

emiproc.exports.icon.make_icon_vertical_profiles(
vertical_profiles: dict[str, VerticalProfile],
out_dir: PathLike | None = None,
nc_attrs: dict[str, str] = {'Conventions': 'CF-1.10', 'author': 'emiproc', 'comment': 'This file was automatically generated by emiproc', 'contact': 'https://emiproc.readthedocs.io/en/latest/support.html#contact', 'creation_time': '2026-05-28 14:10:34', 'history': '2026-05-28 14:10:34: created by emiproc ;\n', 'institution': 'Empa, Swiss Federal Laboratories for Materials Science and Technology', 'references': 'Produced by emiproc.', 'source': 'unspecified', 'title': 'emiproc generated file'},
) Dataset

Create the vertical profiles in the icon format.

enum emiproc.exports.icon.TemporalProfilesTypes(value)

Possible temporal profiles for OEM.

Parameters:
  • HOUR_OF_YEAR – Every hour gets a scaling factor

  • THREE_CYCLES – Three cycles (hour of day, day of week, month of year)

Valid values are as follows:

HOUR_OF_YEAR = <TemporalProfilesTypes.HOUR_OF_YEAR: <TemporalProfilesInterpolated.HOUR_OF_YEAR: 'hour_of_year'>>
THREE_CYCLES = <TemporalProfilesTypes.THREE_CYCLES: <TemporalProfilesInterpolated.THREE_CYCLES: 'three_cycles'>>
emiproc.exports.rasters.export_raster_netcdf(
inv: Inventory,
path: PathLike,
grid: RegularGrid | None = None,
netcdf_attributes: dict[str, str] | None = None,
weights_path: PathLike | None = None,
lon_name: str = 'lon',
lat_name: str = 'lat',
var_name_format: str | None = None,
unit: Units = Units.KG_PER_YEAR,
group_categories: bool = False,
add_totals: bool = True,
categories_description: dict[str, str] | None = None,
) Path

Export the inventory to a netcdf file as a raster.

This will first remap the invenotry to a raster file using emiproc.regrid.remap_inventory() and then export the result to a netcdf file.

Parameters:
  • inv – the inventory to export

  • path – the path to the output file

  • grid – the raster grid to export to If not given, assumes the inventory is already on a raster grid.

  • netcdf_attributes – NetCDF attributes to add to the file. These can be generated using emiproc.exports.netcdf.nc_cf_attributes() .

  • weights_path – Optionally, The path to the weights file to use for regridding. If not given, the weights will be calculated on the fly.

  • lon_name – The name of the longitude dimension in the nc file.

  • lat_name – The name of the latitude dimension in the nc file.

  • var_name_format – The format string to use for the variable names. The format string should contain two named fields: substance and category.

  • unit – The unit of the emissions.

  • group_categories – If True the categories will be grouped in the output file. Intead of a variable for each pair (substance, category) there will be a variable only for each substance and the categories will be grouped in a dimension.

  • add_totals – If True, the total emissions for each substance will be added as new variables to the file. One will be the raster sum of all categories and the other will be the total sum over all cells.

  • categories_description – A dictionary with a detailed description of each categories.

emiproc.exports.profiles.export_inventory_profiles(
inv: Inventory,
output_dir: PathLike,
grid: RegularGrid,
netcdf_attributes: dict[str, str],
var_name_format: str = '{substance}_{category}',
temporal_profiles_type: TemporalProfilesTypes = TemporalProfilesTypes.THREE_CYCLES,
year: int | None = None,
) Path

Export the vertical and temporal profiles of the inventory to netcdfs.

This will export the vertical and temporal profiles of the inventory to netcdf files. The vertical profiles will be exported to a single netcdf file. The temporal profiles will be exported according to make_icon_time_profiles().

Parameters:
  • inv – the inventory to export

  • output_dir – the path to the output directory

  • grid – the raster grid to export to. This is used to calculate the country shifts for the temporal profiles.

  • netcdf_attributes – Same as in emiproc.exports.netcdf.export_raster_netcdf().

  • var_name_format – Same as in emiproc.exports.netcdf.export_raster_netcdf().

  • temporal_profiles_type – The type of temporal profiles to export. See emiproc.exports.icon.TemporalProfilesTypes for the available options.

  • year – The year of the temporal profiles.

emiproc.exports.utils.get_temporally_scaled_array(
inv: Inventory,
time_range: DatetimeIndex | int,
sum_over_cells: bool = True,
freq: str = 'D',
chunk: bool = False,
n_chunks: int = 10,
) DataArray

Transform the inventory to a temporally resolved emissions array.

Missing profiles are assumed to be constant profiles.

You can easily plot the profiles of you different category and substances of the received inventory with the following code: ` da.sum("cell").stack(catsub=["category", "substance"]).plot.line(x="time") `

Warning

If you use this function and specify a time frequency larger than the temporal resolution of the profiles, you might perform undersampling. This means for example that if you sample with a daily frequency and you have hour of day profiles, you will use the same value in the the profile, which will lead to a wrong result.

Parameters:
  • inv – the inventory to transform

  • time_range – the time range to use for the temporal resolution. If an integer is given the time range will a daily range of the given year.

  • sum_over_cells – if True the emissions are summed over the cells. This can be useful to improve the performance of the plotting.

Returns:

the temporally resolved emissions array. The units are the same as in the inventory. (kg/y/cell or kg/y if sum_over_cells is True) But now even scaled on the time axis given units are still that unit. If you want to get the emissions at your time resolution you need divide by the number of your time resolution that fits in a year.

emiproc.exports.wrf.export_wrf_hourly_emissions(
inv: Inventory,
grid: WRF_Grid,
time_range: tuple[datetime | str, datetime | str],
output_dir: PathLike,
variable_name: str = 'E_{substance}_{category}',
) Path

Export the inventory to WRF chemi files.

Output units are in mole/km2/hour.

Note

When running this function on Windows, the files will be saved with the : replaced by - in the file name, because Windows does not allow : in file names.

Parameters:
  • inv – the inventory to export

  • grid – the grid of the WRF model. The inventory must be on this grid.

  • time_range – the time range to export the inventory.

  • output_dir – the directory where to save the files.

  • variable_name – the name of the variable in the netcdf file. You can use the following placeholders: - {substance} - {category} example: “E_{substance}_{category}”

Returns:

the directory where the files are saved.

emiproc.exports.fluxie.export_fluxie(
invs: Inventory | list[Inventory],
output_dir: PathLike,
transport_model: str = 'emiproc',
frequency: Literal['yearly', 'monthly'] = 'yearly',
) Path

Export emissions to Fluxie format.

https://github.com/openghg/fluxie

Fluxie is a python plotting tool for comparing inverse modeling results. As part of fluxie, it is possible to plot prior emissions.

The following conditions are required on inventories to be exported to fluxie:

  • Must have a RegularGrid.

  • Must have a year value given.

  • Must have temporal profiles if monthly frequency is used.

Fluxie files must have a specific format. The files are generated in the following way:

  • <transport_model>_<substance>_<frequency>.nc

Parameters:
  • invs – Inventory or list of inventories to export. A list of inventory assumes that you want to plot the emissions over multiple years.

  • output_dir – Parent directory to export the emissions to. A subdirectory named after the transport model will be created within this directory for the exported files.

  • transport_model – The transport model name to “fake”. (default: emiproc)

  • frequency – Frequency of the emissions to export. Can be “yearly” or “monthly”. (default: “yearly”)

Returns:

Path to the directory where the files were exported.

emiproc.exports.geopackage.export_to_geopackage(
inv: Inventory,
filepath: Path,
name_gridded: str = 'gridded_emissions',
) None

Export an inventory to a GeoPackage file.

The gridded emissions will be saved in a layer named gridded_emissions or any name given by the name_gridded parameter.

For shaped emissions, each category will be saved in a separate layer, with the name being the category name.

Parameters:
  • inv – The inventory to export.

  • filepath – The path to the output GeoPackage file.

  • name_gridded – The name of the layer for gridded emissions.

Gral

Emission generation for the GRAL model: https://gral.tugraz.at/ .

This module contains functions to prepare emissions for GRAL.

Gral only has one polluant available, but can contain more than one category.

To counter that issue, we make a source group for each substance/category.

Warning

For PM, it seems that there are some additional parameters: share_pm25,share_pm10,diamter_pm30[μm],density[kg/m3],dry_dep_vel_pm25[m/s], dry_dep_vel_pm10[m/s],dry_dep_vel_pm30[m/s],mode

We don’t use them for now.

Warning

The current version of emiproc does not support lines and portals.

4 types of emissions are supported with their respective files:

  • point sources: point.dat

  • line sources: line.dat

  • area sources: cadastre.dat

  • tunnel sources: portals.dat

Each file is optional.

The following methods are applied:

  • points: simply write the coordinates and the emission rate

  • lines: write the coordinates of the line and the emission rate

    The Multi-lines have to be split into single lines, which increases the size of the problem.

  • areas: polygons have to be rasterized into squares before writing them.

  • tunnels: not implemented

emiproc.exports.gral.export_to_gral(
inventory: Inventory,
grid: GralGrid,
path: os.PathLike,
polygon_raster_size: float = 1.0,
) None

Export an inventory to GRAL.

Note

This requires the external python package pygg to be installed.

Parameters:
  • inventory – Inventory to export.

  • path – Path where to write the emissions.

  • grid – Grid to use.