|
@@ -26,10 +26,167 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
|
|
|
/ "v2024-11-14/FAOSTAT_Agrifood_system_emissions_v2024-11-14_raw.nc"
|
|
|
)
|
|
|
ds = pm2.open_dataset(ds_fao)
|
|
|
-
|
|
|
+ # consistency check in original categorisation
|
|
|
# drop UNFCCC data
|
|
|
ds = ds.drop_sel(source="UNFCCC")
|
|
|
|
|
|
+ # Checking consistency of category tree in FAO categorisation
|
|
|
+ # There are discrepancies of up to 100% due to rounding errors for small values
|
|
|
+ # theoretical example, 0.0001 (rounded from 0.00006) + 0.0004 (rounded from 0.00036)
|
|
|
+ # = 0.00042 which is then rounded to 0.0004, while the consistency check expects 0.0005
|
|
|
+ agg_info_fao = {
|
|
|
+ "category (FAOSTAT)": {
|
|
|
+ "1": {
|
|
|
+ "tolerance": 0.01,
|
|
|
+ "sources": [
|
|
|
+ "1.A",
|
|
|
+ "1.B",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O", "CH4"]},
|
|
|
+ },
|
|
|
+ # 1.A.1 wheat
|
|
|
+ # rounding errors
|
|
|
+ "1.A.1.a": {
|
|
|
+ "tolerance": 1,
|
|
|
+ "sources": [
|
|
|
+ "1.A.1.a.i",
|
|
|
+ "1.A.1.a.ii",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ "1.A.1": {
|
|
|
+ "tolerance": 0.01,
|
|
|
+ "sources": [
|
|
|
+ "1.A.1.a",
|
|
|
+ "1.A.1.b",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O", "CH4"]},
|
|
|
+ },
|
|
|
+ # 1.A.2 rice
|
|
|
+ # rounding errors
|
|
|
+ "1.A.2.a": {
|
|
|
+ "tolerance": 1,
|
|
|
+ "sources": [
|
|
|
+ "1.A.2.a.i",
|
|
|
+ "1.A.2.a.ii",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ "1.A.2": {
|
|
|
+ "tolerance": 0.01,
|
|
|
+ "sources": [
|
|
|
+ "1.A.2.a",
|
|
|
+ "1.A.2.b",
|
|
|
+ "1.A.2.c", # rice cultivation CH4
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O", "CH4"]},
|
|
|
+ },
|
|
|
+ # "1.A" : {
|
|
|
+ # "tolerance" : 0.01,
|
|
|
+ # "sources" : [
|
|
|
+ # "1.A.1",
|
|
|
+ # "1.A.2",
|
|
|
+ # "1.A.3",
|
|
|
+ # "1.A.4",
|
|
|
+ # "1.A.5",
|
|
|
+ # "1.A.6",
|
|
|
+ # "1.A.7",
|
|
|
+ # "1.A.8",
|
|
|
+ # "1.A.9",
|
|
|
+ # "1.A.10",
|
|
|
+ # "1.A.10",
|
|
|
+ # ],
|
|
|
+ # },
|
|
|
+ # potatoes
|
|
|
+ "1.A.3.a": {
|
|
|
+ "tolerance": 1,
|
|
|
+ "sources": [
|
|
|
+ "1.A.3.a.i",
|
|
|
+ "1.A.3.a.ii",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ "1.A.3": {
|
|
|
+ "tolerance": 0.01,
|
|
|
+ "sources": [
|
|
|
+ "1.A.3.a",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ # millet
|
|
|
+ "1.A.4.a": {
|
|
|
+ "tolerance": 1,
|
|
|
+ "sources": [
|
|
|
+ "1.A.4.a.i",
|
|
|
+ "1.A.4.a.ii",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ "1.A.4": {
|
|
|
+ "tolerance": 0.01,
|
|
|
+ "sources": [
|
|
|
+ "1.A.4.a",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ # barley
|
|
|
+ "1.A.5.a": {
|
|
|
+ "tolerance": 1,
|
|
|
+ "sources": [
|
|
|
+ "1.A.5.a.i",
|
|
|
+ "1.A.5.a.ii",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ "1.A.5": {
|
|
|
+ "tolerance": 0.01,
|
|
|
+ "sources": [
|
|
|
+ "1.A.5.a",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ # barley
|
|
|
+ "1.A.6.a": {
|
|
|
+ "tolerance": 1,
|
|
|
+ "sources": [
|
|
|
+ "1.A.6.a.i",
|
|
|
+ "1.A.6.a.ii",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O"]},
|
|
|
+ },
|
|
|
+ "1.A.6": {
|
|
|
+ "tolerance": 0.01,
|
|
|
+ "sources": [
|
|
|
+ "1.A.6.a",
|
|
|
+ "1.A.6.b",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["N2O", "CH4"]},
|
|
|
+ },
|
|
|
+ "4": {
|
|
|
+ "tolerance": 0.01,
|
|
|
+ "sources": [
|
|
|
+ "4.A",
|
|
|
+ "4.B",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["CO2"]},
|
|
|
+ },
|
|
|
+ "6.B": {
|
|
|
+ # rounding errors, NLD looks problematic but hard to tell which value is right
|
|
|
+ "tolerance": 1,
|
|
|
+ "sources": [
|
|
|
+ "6.B.1",
|
|
|
+ "6.B.2",
|
|
|
+ "6.B.3",
|
|
|
+ "6.B.4",
|
|
|
+ "6.B.5",
|
|
|
+ ],
|
|
|
+ "sel": {"variable": ["CH4", "N2O", "CO2"]},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ds_checked = ds.pr.add_aggregates_coordinates(agg_info=agg_info_fao) # noqa: F841
|
|
|
+
|
|
|
+ # ds_checked_if = ds_checked.pr.to_interchange_format()
|
|
|
# We need a comversion CSV file for each entity
|
|
|
# That's a temporary workaround until convert function can filter for data variables (entities)
|
|
|
conv = {}
|
|
@@ -61,11 +218,12 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
|
|
|
},
|
|
|
"M.3.C.AG": {
|
|
|
"sources": [
|
|
|
- "3.C.1.b",
|
|
|
- "3.C.1.c",
|
|
|
- "3.C.4",
|
|
|
- "3.C.5",
|
|
|
- ], # savanna, cropland fires
|
|
|
+ "3.C.1.b", # Biomass Burning In Croplands
|
|
|
+ "3.C.1.c", # Biomass Burning in Grasslands
|
|
|
+ "3.C.4", # Direct N2O Emissions from Managed Soils
|
|
|
+ "3.C.5", # Indirect N2O Emissions from Managed Soils
|
|
|
+ "3.C.6", # Indirect N2O Emissions from Manure Management
|
|
|
+ ],
|
|
|
},
|
|
|
"M.AG.ELV": {
|
|
|
"sources": ["M.3.C.AG"], # "M.3.D.AG" is zero
|
|
@@ -126,7 +284,12 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
|
|
|
# "M.3.D.LU": {"sources": ["3.D.1"]},
|
|
|
# For LULUCF Forest Land, Cropland, Grassland, is all we have
|
|
|
"M.LULUCF": {
|
|
|
- "sources": ["3.B.1", "3.B.2", "3.B.3", "3.C.1.a"]
|
|
|
+ "sources": [
|
|
|
+ "3.B.1", # Carbon stock change in forests
|
|
|
+ "3.B.2", # Drained grassland
|
|
|
+ "3.B.3", # Drained cropland
|
|
|
+ "3.C.1.a", # Biomass Burning In Forests
|
|
|
+ ]
|
|
|
}, # forest fires
|
|
|
"3": {"sources": ["M.AG", "M.LULUCF"]},
|
|
|
}
|
|
@@ -160,13 +323,13 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
|
|
|
|
|
|
def test_read(tmp_path):
|
|
|
domains_and_releases_to_read = [
|
|
|
- ("farm_gate_agriculture_energy", "2024-11-14"),
|
|
|
- ("farm_gate_emissions_crops", "2024-11-14"),
|
|
|
- ("farm_gate_livestock", "2024-11-14"),
|
|
|
- ("land_use_drained_organic_soils", "2024-11-14"),
|
|
|
- ("land_use_fires", "2024-11-14"),
|
|
|
- ("land_use_forests", "2024-11-14"),
|
|
|
- ("pre_post_agricultural_production", "2024-11-14"),
|
|
|
+ # ("farm_gate_agriculture_energy", "2024-11-14"),
|
|
|
+ # ("farm_gate_emissions_crops", "2024-11-14"),
|
|
|
+ # ("farm_gate_livestock", "2024-11-14"),
|
|
|
+ # ("land_use_drained_organic_soils", "2024-11-14"),
|
|
|
+ ("land_use_fires", "2023-11-09"),
|
|
|
+ # ("land_use_forests", "2024-11-14"),
|
|
|
+ # ("pre_post_agricultural_production", "2024-11-14"),
|
|
|
]
|
|
|
|
|
|
read_data(
|