EDGAR Inventory Processing¶
This tutorial demonstrates how to process EDGAR inventory data.
We will perform the following steps:
Load the data
Create a grid for the output
Remap the inventory to the grid
Process the data
Save the output
EDGAR Files¶
In this section, we will examine the EDGAR NetCDF files.
These files can be downloaded directly from the EDGAR website. However, the most convenient method is to use the download_edgar_files function provided by emiproc, as demonstrated below.
[1]:
from pathlib import Path
from emiproc.inventories.edgar import download_edgar_files
year = 2022
local_dir = Path("./edgar") / str(year)
local_dir.mkdir(exist_ok=True, parents=True)
[2]:
download_edgar_files(local_dir, year=year, substances=["CH4", "CO2", "CO2bio"])
Downloaded 53 files.
Let’s examine one of the downloaded files.
[3]:
import xarray as xr
path_edgar_file = local_dir / "EDGAR_2024_GHG_CH4_2022_ENE_emi.nc"
ds = xr.open_dataset(path_edgar_file)
ds
[3]:
<xarray.Dataset> Size: 26MB
Dimensions: (lat: 1800, lon: 3600)
Coordinates:
* lat (lat) float64 14kB -89.95 -89.85 -89.75 ... 89.75 89.85 89.95
* lon (lon) float64 29kB -179.9 -179.8 -179.8 ... 179.8 179.8 179.9
Data variables:
emissions (lat, lon) float32 26MB ...
Attributes:
institution: European Commission, Joint Research Centre
source: https://edgar.jrc.ec.europa.eu/dataset_ghg2024
how_to_cite: https://edgar.jrc.ec.europa.eu/dataset_ghg2024#howtocite
copyright_notice: https://edgar.jrc.ec.europa.eu/dataset_ghg2024#conditions
contacts: https://edgar.jrc.ec.europa.eu/dataset_ghg2024#info JR...Creating code to parse inventory files for every project can be cumbersome.
The goal of emiproc is to provide a straightforward interface for reading emissions inventories. In this case, you can use the EDGARv8 class, which reads the EDGAR files and loads them as an Inventory object.
[4]:
from emiproc.inventories.edgar import EDGARv8
# Load the edgar inventory
inv = EDGARv8(local_dir / "EDGAR_*.nc", year=year)
inv
[4]:
Inventory(EDGARv8)
Visualizing the Inventory¶
Let’s examine the contents of our inventory.
emiproc provides several functions to assist us in this process.
[5]:
# We can look at the total emissions of the inventory (units are in kg/year)
inv.total_emissions.T
[5]:
| CH4 | CO2 | CO2bio | |
|---|---|---|---|
| Agricultural soils | 3.678327e+10 | 1.430920e+11 | NaN |
| Agricultural waste burning | 2.359133e+09 | NaN | 1.323736e+12 |
| Chemical processes | 3.591839e+08 | 7.536434e+11 | NaN |
| Power Industry | 5.637066e+08 | 1.469337e+13 | 8.824078e+11 |
| Enteric fermentation | 1.127170e+11 | NaN | NaN |
| Combustion for manufacturing | 6.869048e+08 | 6.223605e+12 | 1.980250e+12 |
| Iron and steel production | 1.648024e+08 | 2.898203e+11 | 2.250683e+08 |
| Manure management | 1.237949e+10 | NaN | NaN |
| Fuel exploitation | 9.676207e+10 | 3.818153e+11 | 2.763252e+11 |
| Energy for buildings | 9.904553e+09 | 3.385634e+12 | 2.975195e+12 |
| Oil refineries and Transformation industry | 6.970340e+09 | 2.220603e+12 | 4.190084e+11 |
| Solid waste incineration | 1.634158e+09 | 1.786001e+10 | 7.102761e+09 |
| Solid waste landfills | 3.855265e+10 | NaN | NaN |
| Aviation climbing_and_descent | 1.967106e+06 | 2.808891e+11 | 1.820282e+06 |
| Aviation cruise | 2.653998e+06 | 3.789719e+11 | 2.455900e+06 |
| Aviation landing_and_takeoff | 6.291362e+05 | 8.983632e+10 | 5.821781e+05 |
| Railways, pipelines, off-road transport | 9.078780e+06 | 2.732929e+11 | 2.795448e+09 |
| Shipping | 8.084582e+07 | 8.810432e+11 | 1.611196e+09 |
| Road transportation | 9.797972e+08 | 6.039474e+12 | 2.933062e+11 |
| Waste water handling | 2.412476e+10 | NaN | NaN |
| __total__ | 3.450370e+11 | 3.824663e+13 | 8.161967e+12 |
| Non energy use of fuels | NaN | 2.767136e+10 | NaN |
| Non-ferrous metals production | NaN | 1.228438e+11 | NaN |
| Non-metallic minerals production | NaN | 1.980856e+12 | NaN |
| Solvents and products use | NaN | 6.231152e+10 | NaN |
Plot the inventory using built-in functions.
[6]:
import matplotlib.pyplot as plt
from emiproc.plots import plot_inventory
plt.style.use("default")
plot_inventory(inv, total_only=True)
From these results, we can observe how emissions are distributed globally.
In the totals, the largest categories of methane emissions are Enteric fermentation and Fuel exploitation. For CO2, the Power Industry is the largest category, followed by Road Transportation, Combustion for manufacturing, and Energy for buildings.
Most of these categories can be mitigated through the electrification of the economy and the adoption of renewable power sources. However, Enteric fermentation, which refers to the emissions from cows and other ruminants digesting food, presents a unique challenge that can be relatively easier and faster to address by simply reducing or stopping meat consumption.
It is also important to note that many “natural” CO2 emissions are associated with meat production due to deforestation (not accounted for in EDGAR), making dietary changes a doubly beneficial approach.
Processing the Inventory¶
In this step, we will demonstrate some standard operations that can be performed on the inventory.
Remapping the Inventory¶
In this section, we will remap the inventory to a grid.
Suppose we want to perform a simulation over Australia. First, we need to create a custom grid.
[7]:
from emiproc.grids import RegularGrid
# The grid can be defined by various parameters
# See the documentation for more details
# https://emiproc.readthedocs.io/en/master/api/grids.html#emiproc.grids.RegularGrid
australian_grid = RegularGrid(xmin=110, xmax=160, ymin=-45, ymax=-10, nx=200, ny=160)
australian_grid
[7]:
RegularGrid(unnamed)_nx(200)_ny(160)_dx(0.25)_dy(0.21875)_x(110,160.0)_y(-45,-10.0)_
In some cases, you may already have a grid for your simulation, which you could import into emiproc with appropriate code. A tutorial for developper is available.
[8]:
# Remap the inventory on the grid
from emiproc.regrid import remap_inventory
remapped = remap_inventory(inv, australian_grid)
remapped
C:\Users\coli\Documents\emiproc\emiproc\regrid.py:251: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
gdf_weights.geometry_inter.area / gdf_weights.geometry.area
[8]:
Inventory(Inventory)
Let’s examine our remapped inventory.
[9]:
plot_inventory(remapped, total_only=True)
For this domain, the panorama is quite different. For example, waste is well-managed in Australia, so its fraction of the total emissions is smaller. Maybe Australia exports its waste to other regions such as Asia or Africa ? Who knows ?
Grouping Categories¶
Many categories are similar and have very small emissions.
In such cases, we can group some categories together to reduce the number of emission sectors.
[10]:
from emiproc.inventories.utils import group_categories
grouped = group_categories(
remapped,
categories_group={
"agriculture": [
"Agricultural soils",
"Agricultural waste burning",
"Manure management",
],
"industry": [
"Chemical processes",
"Power Industry",
"Oil refineries and Transformation industry",
"Fuel exploitation",
"Energy for buildings",
"Combustion for manufacturing",
"Iron and steel production",
"Non energy use of fuels",
"Solvents and products use",
"Non-ferrous metals production",
"Non-metallic minerals production",
],
"livestock": ["Enteric fermentation"],
"waste": [
"Waste water handling",
"Solid waste incineration",
"Solid waste landfills",
],
"transportation": [
"Aviation climbing_and_descent",
"Aviation cruise",
"Aviation landing_and_takeoff",
"Railways, pipelines, off-road transport",
"Shipping",
"Road transportation",
],
},
)
grouped.total_emissions.T
[10]:
| CO2bio | CH4 | CO2 | |
|---|---|---|---|
| agriculture | 1.436499e+10 | 2.274178e+08 | 3.350383e+09 |
| industry | 4.741786e+10 | 1.683938e+09 | 2.830813e+11 |
| transportation | 5.580335e+08 | 8.589536e+06 | 1.137983e+11 |
| __total__ | 6.234089e+10 | 4.749143e+09 | 4.002463e+11 |
| livestock | NaN | 2.403860e+09 | NaN |
| waste | NaN | 4.253374e+08 | 1.629228e+07 |
Merging CO2 Emissions¶
Ultimately, we aim to obtain the total CO2 emissions.
To achieve this, we will sum the biogenic CO2 with the fossil CO2 emissions.
[11]:
from emiproc.speciation import merge_substances
merged = merge_substances(grouped, {"CO2": ["CO2", "CO2bio"]})
merged.total_emissions.T
[11]:
| CH4 | CO2 | |
|---|---|---|
| agriculture | 2.274178e+08 | 1.771538e+10 |
| industry | 1.683938e+09 | 3.304992e+11 |
| livestock | 2.403860e+09 | NaN |
| waste | 4.253374e+08 | 1.629228e+07 |
| transportation | 8.589536e+06 | 1.143563e+11 |
| __total__ | 4.749143e+09 | 4.625872e+11 |
Final Review¶
Before exporting the inventory, let’s take a final look at the results.
[12]:
plot_inventory(merged)
Exporting the Inventory¶
One of the main features of emiproc is its ability to export the inventory to various types of simulation inputs.
In this example, we will save the inventory to a NetCDF file.
[13]:
from emiproc.exports.rasters import export_raster_netcdf
export_path = local_dir / "australia.nc"
export_raster_netcdf(merged, export_path)
print("Exported")
Exported
We can open the file with xarray to examine its contents.
[14]:
ds = xr.load_dataset(export_path)
ds
[14]:
<xarray.Dataset> Size: 3MB
Dimensions: (lat: 160, lon: 200, substance: 2, category: 5,
lon_bnds: 201, lat_bnds: 161)
Coordinates:
* substance (substance) <U3 24B 'CH4' 'CO2'
* category (category) <U14 280B 'transportation' ... 'livestock'
* lon (lon) float64 2kB 110.1 110.4 110.6 ... 159.6 159.9
* lat (lat) float64 1kB -44.89 -44.67 ... -10.33 -10.11
* lon_bnds (lon_bnds) float64 2kB 110.0 110.2 ... 159.8 160.0
* lat_bnds (lat_bnds) float64 1kB -45.0 -44.78 ... -10.22 -10.0
Data variables: (12/14)
CH4_transportation (lat, lon) float64 256kB 0.3098 0.08621 ... 10.21 18.04
CH4_industry (lat, lon) float64 256kB 5.083 2.611 ... 11.31 4.261
CH4_waste (lat, lon) float64 256kB 0.0 0.0 0.0 ... 0.0 0.0 0.0
CH4_agriculture (lat, lon) float64 256kB 0.0 0.0 0.0 ... 0.0 0.0 0.0
CH4_livestock (lat, lon) float64 256kB 0.0 0.0 0.0 ... 0.0 0.0 0.0
CO2_transportation (lat, lon) float64 256kB 3.4e+03 946.1 ... 2.113e+06
... ...
CO2_agriculture (lat, lon) float64 256kB 0.0 0.0 0.0 ... 0.0 0.0 0.0
emi_CH4_all_sectors (lat, lon) float64 256kB 5.393 2.697 ... 21.51 22.3
emi_CH4_total (category) float64 40B 8.59e+06 1.684e+09 ... 2.404e+09
emi_CO2_all_sectors (lat, lon) float64 256kB 3.4e+03 946.1 ... 2.113e+06
emi_CO2_total (category) float64 40B 1.144e+11 3.305e+11 ... 0.0
cell_area (lat, lon) float64 256kB 4.801e+08 ... 6.63e+08
Attributes:
Conventions: CF-1.10
title: emiproc generated file
comment:
source:
history: 2025-04-30 15:13:02: created by emiproc ;\n
references: Produced by emiproc.
institution: Empa, Swiss Federal Laboratories for Materials Science ...
author: emiproc
contact: https://emiproc.readthedocs.io/en/master/support.html#c...
creation_time: 2025-04-30 15:13:02
emiproc_history: ["Inventory(EDGARv8) created as type:'EDGARv8'", 'Copie...
year: not specified in inventory.yearPlot with xarray to check the data
[15]:
from matplotlib.colors import LogNorm
ds["emi_CO2_all_sectors"].plot(
# use a logarithmic color scale, otherwise we only see the highest point sources.
norm=LogNorm(vmin=1e4, vmax=1e8),
cmap="viridis",
)
[15]:
<matplotlib.collections.QuadMesh at 0x226083c05f0>
Indeed, the plots generated using emiproc were more refined and visually appealing (even though art is subjective).
Conclusion¶
In this tutorial, we demonstrated how to process an emissions inventory using emiproc.
Depending on your needs, you may need to use different functions, inventories, and export options.
If you have any questions, please refer to our support page.