Browse Source

[DATALAD] Recorded changes

Daniel Busch 4 months ago
parent
commit
d2af9dcadd

+ 106 - 3
src/faostat_data_primap/helper/definitions.py

@@ -94,6 +94,31 @@ read_config_all: Any = {
                 "Emissions (CH4)": "CH4",
                 "Emissions (N2O)": "N2O",
             },
+            "category_mapping_item_element": {
+                "Electricity - Emissions (CO2)": "2.B",
+                "Electricity - Emissions (CH4)": "2.B",
+                "Electricity - Emissions (N2O)": "2.B",
+                "Total Energy - Emissions (CO2)": "2",
+                "Total Energy - Emissions (CH4)": "2",
+                "Total Energy - Emissions (N2O)": "2",
+                "Petroleum products - Emissions (CO2)": "2.E",
+                "Petroleum products - Emissions (CH4)": "2.E",
+                "Petroleum products - Emissions (N2O)": "2.E",
+                "Natural gas - Emissions (CO2)": "2.A",
+                "Natural gas - Emissions (CH4)": "2.A",
+                "Natural gas - Emissions (N2O)": "2.A",
+                "Coal - Emissions (CO2)": "2.C",
+                "Coal - Emissions (CH4)": "2.C",
+                "Coal - Emissions (N2O)": "2.C",
+                "Heat - Emissions (CO2)": "2.D",
+                "Heat - Emissions (CH4)": "2.D",
+                "Heat - Emissions (N2O)": "2.D",
+            },
+            "items-elements_to_remove": [
+                "Total Energy (excl.eletricity & heat) - Emissions (CO2)",
+                "Total Energy (excl.eletricity & heat) - Emissions (CH4)",
+                "Total Energy (excl.eletricity & heat) - Emissions (N2O)",
+            ],
             "columns_to_drop": [
                 "Element",
                 "Element Code",
@@ -137,7 +162,7 @@ read_config_all: Any = {
                     "(Synthetic fertilizers)"
                 ): "N2O",
             },
-            "category_mapping": {
+            "category_mapping_item_element": {
                 "Barley - Crop residues (Emissions N2O)": "1.A.5.a",
                 "Barley - Crop residues (Direct emissions N2O)": "1.A.5.a.i",
                 "Barley - Crop residues (Indirect emissions N2O)": "1.A.5.a.ii",
@@ -239,6 +264,15 @@ read_config_all: Any = {
                 "Serbia and Montenegro",
                 "European Union (27)",
             ],
+            "items_to_remove": [
+                # we don't need aggregates
+                "Camels and Llamas",
+                "Cattle",  # dairy and non-dairy
+                # mistake by FAO, should be "Mules, hinnies, and asses"
+                "Mules and Asses",
+                "Sheep and Goats",
+                "Swine",  # breeding and market
+            ],
             "elements_to_remove": [
                 "Stocks",  # number of animals
                 "Manure management (manure treated, N content)",
@@ -248,6 +282,10 @@ read_config_all: Any = {
                 "Manure applied to soils (N content)",
                 "Manure applied to soils that leaches (N content)",
                 "Manure applied to soils that volatilises (N content)",
+                # sum of direct and direct manure management emissions
+                # would add another level in the category tree, but
+                # is not needed (see miro)
+                "Manure management (Emissions N2O)",
             ],
             "entity_mapping": {
                 "Livestock total (Emissions N2O)": "N2O",
@@ -268,6 +306,73 @@ read_config_all: Any = {
                 "Indirect emissions (N2O that volatilises) (Manure applied)": "N2O",
                 "Manure applied to soils (Indirect emissions N2O)": "N2O",
             },
+            "category_mapping_item": {
+                "Asses": "3.A",
+                "Camels": "3.B",
+                "Cattle, dairy": "3.C",
+                "Cattle, non-dairy": "3.D",
+                "Chickens, broilers": "3.E",
+                "Chickens, layers": "3.F",
+                "Goats": "3.G",
+                "Horses": "3.H",
+                "Mules and hinnies": "3.I",
+                "Sheep": "3.J",
+                "Llamas": "3.K",
+                "Chickens": "3.L",
+                "Poultry Birds": "3.M",
+                "Buffalo": "3.N",
+                "Ducks": "3.O",
+                "Swine, breeding": "3.P",
+                "Swine, market": "3.Q",
+                "Turkeys": "3.R",
+            },
+            "category_mapping_element": {
+                "Livestock total (Emissions N2O)": "",
+                "Livestock total (Emissions CH4)": "",
+                "Enteric fermentation (Emissions CH4)": ".1",
+                "Manure management (Emissions CH4)": ".2.a",
+                # "Manure management (Emissions N2O)": ".2.b",
+                "Manure management (Direct emissions N2O)": ".2.b",
+                "Manure management (Indirect emissions N2O)": ".2.c",
+                "Manure left on pasture (Emissions N2O)": ".3",
+                "Manure left on pasture (Direct emissions N2O)": ".3.a",
+                "Indirect emissions (N2O that leaches) (Manure on pasture)": ".3.b.i",
+                (
+                    "Indirect emissions (N2O that volatilises) " "(Manure on pasture)"
+                ): ".3.b.ii",
+                "Manure left on pasture (Indirect emissions N2O)": ".3.b",
+                "Emissions (N2O) (Manure applied)": ".4",
+                "Manure applied to soils (Direct emissions N2O)": ".4.a",
+                ("Indirect emissions (N2O that leaches) " "(Manure applied)"): ".4.b.i",
+                "Indirect emissions (N2O that volatilises) (Manure applied)": ".4.b.ii",
+                "Manure applied to soils (Indirect emissions N2O)": ".4.b",
+            },
+            "items-elements_to_remove": [
+                # we only keep All animals total CH4 and total N2O
+                "All Animals - Enteric fermentation (Emissions CH4)",
+                "All Animals - Manure management (Emissions CH4)",
+                "All Animals - Manure management (Direct emissions N2O)",
+                "All Animals - Manure management (Indirect emissions N2O)",
+                "All Animals - Manure left on pasture (Emissions N2O)",
+                "All Animals - Manure left on pasture (Direct emissions N2O)",
+                (
+                    "All Animals - Indirect emissions (N2O that leaches) "
+                    "(Manure on pasture)"
+                ),
+                (
+                    "All Animals - Indirect emissions (N2O that volatilises) "
+                    "(Manure on pasture)"
+                ),
+                "All Animals - Manure left on pasture (Indirect emissions N2O)",
+                "All Animals - Emissions (N2O) (Manure applied)",
+                "All Animals - Manure applied to soils (Direct emissions N2O)",
+                "All Animals - Indirect emissions (N2O that leaches) (Manure applied)",
+                (
+                    "All Animals - Indirect emissions (N2O that volatilises) "
+                    "(Manure applied)"
+                ),
+                "All Animals - Manure applied to soils (Indirect emissions N2O)",
+            ],
             "columns_to_drop": [
                 "Element",
                 "Element Code",
@@ -516,5 +621,3 @@ domains_and_releases_to_read = {
         ("pre_post_agricultural_production", "2024-11-14"),
     ]
 }
-
-FAO_climate_categories = []

+ 33 - 5
src/faostat_data_primap/read.py

@@ -64,7 +64,7 @@ def get_latest_release(domain_path: pathlib.Path) -> str:
 
 
 # TODO split out functions to avoid PLR0915
-def read_data(  # noqa: PLR0915
+def read_data(  # noqa: PLR0915 PLR0912
     read_path: pathlib.Path,
     domains_and_releases_to_read: list[tuple[str, str]],
     save_path: pathlib.Path,
@@ -92,6 +92,11 @@ def read_data(  # noqa: PLR0915
         # There are some non-utf8 characters
         df_domain = pd.read_csv(dataset_path, encoding="ISO-8859-1")
 
+        if "items_to_remove" in read_config.keys():
+            df_domain = df_domain[
+                ~df_domain["Item"].isin(read_config["items_to_remove"])
+            ]
+
         # remove rows by element
         if "elements_to_remove" in read_config.keys():
             df_domain = df_domain[
@@ -122,9 +127,31 @@ def read_data(  # noqa: PLR0915
 
         # create category column (combination of Item and Element works best)
         df_domain["Item - Element"] = df_domain["Item"] + " - " + df_domain["Element"]
-        df_domain["category"] = df_domain["Item - Element"].map(
-            read_config["category_mapping"]
-        )
+
+        if "category_mapping_item_element" in read_config.keys():
+            df_domain["category"] = df_domain["Item - Element"].map(
+                read_config["category_mapping"]
+            )
+        # sometimes there are too many categories per domain to write
+        # everything in the config file
+        # TODO we could do this for crops as well, but it's not necessary
+        elif ("category_mapping_element" in read_config.keys()) and (
+            "category_mapping_item" in read_config.keys()
+        ):
+            # split steps for easier debugging
+            df_domain["mapped_item"] = df_domain["Item"].map(
+                read_config["category_mapping_item"]
+            )
+            df_domain["mapped_element"] = df_domain["Element"].map(
+                read_config["category_mapping_element"]
+            )
+            df_domain["category"] = (
+                df_domain["mapped_item"] + df_domain["mapped_element"]
+            )
+        else:
+            msg = f"Could not find mapping for {domain=}."
+            raise ValueError(msg)
+
         # some rows can only be removed by Item - Element column
         if "items-elements_to_remove" in read_config.keys():
             df_domain = df_domain[
@@ -132,7 +159,8 @@ def read_data(  # noqa: PLR0915
                     read_config["items-elements_to_remove"]
                 )
             ]
-        # check if all Item-Element combinations are now be converted to category codes
+
+        # check if all Item-Element combinations are now converted to category codes
         fao_categories = list(spec["categories"].keys())
         unknown_categories = [
             i for i in df_domain.category.unique() if i not in fao_categories

+ 651 - 3
tests/unit/FAO.py

@@ -421,84 +421,732 @@ spec = {
             "comment": "Petroleum",
             "info": {"gases": ["CH4", "N2O", "CO2"]},
         },
+        "3.A.4": {
+            "title": "Asses enteric fermentation",
+            "comment": "Asses enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
+        },
         "3.A": {
             "title": "Asses",
             "comment": "Asses",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.A.1", "3.A.2", "3.A.3", "3.A.4"]],
+        },
+        "3.A.1": {
+            "title": "Asses manure management",
+            "comment": "Asses manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.A.1.a", "3.A.1.b", "3.A.1.c"]],
+        },
+        "3.A.1.a": {
+            "title": "Asses decomposition of organic matter",
+            "comment": "Asses decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.A.1.b": {
+            "title": "Asses manure management (Direct emissions N2O)",
+            "comment": "Asses manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.A.1.c": {
+            "title": "Asses manure management (Indirect emissions N2O)",
+            "comment": "Asses manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.A.2": {
+            "title": "Asses manure left on pasture",
+            "comment": "Asses manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.A.3": {
+            "title": "Asses manure applied",
+            "comment": "Asses manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.B.4": {
+            "title": "Camels enteric fermentation",
+            "comment": "Camels enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.B": {
             "title": "Camels",
             "comment": "Camels",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.B.1", "3.B.2", "3.B.3", "3.B.4"]],
+        },
+        "3.B.1": {
+            "title": "Camels manure management",
+            "comment": "Camels manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.B.1.a", "3.B.1.b", "3.B.1.c"]],
+        },
+        "3.B.1.a": {
+            "title": "Camels decomposition of organic matter",
+            "comment": "Camels decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.B.1.b": {
+            "title": "Camels manure management (Direct emissions N2O)",
+            "comment": "Camels manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.B.1.c": {
+            "title": "Camels manure management (Indirect emissions N2O)",
+            "comment": "Camels manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.B.2": {
+            "title": "Camels manure left on pasture",
+            "comment": "Camels manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.B.3": {
+            "title": "Camels manure applied",
+            "comment": "Camels manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.C.4": {
+            "title": "Cattle, dairy enteric fermentation",
+            "comment": "Cattle, dairy enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.C": {
             "title": "Cattle, dairy",
             "comment": "Cattle, dairy",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.C.1", "3.C.2", "3.C.3", "3.C.4"]],
+        },
+        "3.C.1": {
+            "title": "Cattle, dairy manure management",
+            "comment": "Cattle, dairy manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.C.1.a", "3.C.1.b", "3.C.1.c"]],
+        },
+        "3.C.1.a": {
+            "title": "Cattle, dairy decomposition of organic matter",
+            "comment": "Cattle, dairy decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.C.1.b": {
+            "title": "Cattle, dairy manure management (Direct emissions N2O)",
+            "comment": "Cattle, dairy manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.C.1.c": {
+            "title": "Cattle, dairy manure management (Indirect emissions N2O)",
+            "comment": "Cattle, dairy manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.C.2": {
+            "title": "Cattle, dairy manure left on pasture",
+            "comment": "Cattle, dairy manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.C.3": {
+            "title": "Cattle, dairy manure applied",
+            "comment": "Cattle, dairy manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.D.4": {
+            "title": "Cattle, non-dairy enteric fermentation",
+            "comment": "Cattle, non-dairy enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.D": {
             "title": "Cattle, non-dairy",
             "comment": "Cattle, non-dairy",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.D.1", "3.D.2", "3.D.3", "3.D.4"]],
+        },
+        "3.D.1": {
+            "title": "Cattle, non-dairy manure management",
+            "comment": "Cattle, non-dairy manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.D.1.a", "3.D.1.b", "3.D.1.c"]],
+        },
+        "3.D.1.a": {
+            "title": "Cattle, non-dairy decomposition of organic matter",
+            "comment": "Cattle, non-dairy decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.D.1.b": {
+            "title": "Cattle, non-dairy manure management (Direct emissions N2O)",
+            "comment": "Cattle, non-dairy manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.D.1.c": {
+            "title": "Cattle, non-dairy manure management (Indirect emissions N2O)",
+            "comment": "Cattle, non-dairy manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.D.2": {
+            "title": "Cattle, non-dairy manure left on pasture",
+            "comment": "Cattle, non-dairy manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.D.3": {
+            "title": "Cattle, non-dairy manure applied",
+            "comment": "Cattle, non-dairy manure applied",
+            "info": {"gases": "N2O"},
         },
         "3.E": {
             "title": "Chickens, broilers",
             "comment": "Chickens, broilers",
             "info": {"gases": ["N2O"]},
+            "children": [["3.E.1", "3.E.2", "3.E.3"]],
+        },
+        "3.E.1": {
+            "title": "Chickens, broilers manure management",
+            "comment": "Chickens, broilers manure management",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.E.1.a", "3.E.1.b", "3.E.1.c"]],
+        },
+        "3.E.1.a": {
+            "title": "Chickens, broilers decomposition of organic matter",
+            "comment": "Chickens, broilers decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.E.1.b": {
+            "title": "Chickens, broilers manure management (Direct emissions N2O)",
+            "comment": "Chickens, broilers manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.E.1.c": {
+            "title": "Chickens, broilers manure management (Indirect emissions N2O)",
+            "comment": "Chickens, broilers manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.E.2": {
+            "title": "Chickens, broilers manure left on pasture",
+            "comment": "Chickens, broilers manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.E.3": {
+            "title": "Chickens, broilers manure applied",
+            "comment": "Chickens, broilers manure applied",
+            "info": {"gases": "N2O"},
         },
         "3.F": {
             "title": "Chickens, layers",
             "comment": "Chickens, layers",
             "info": {"gases": ["N2O"]},
+            "children": [["3.F.1", "3.F.2", "3.F.3"]],
+        },
+        "3.F.1": {
+            "title": "Chickens, layers manure management",
+            "comment": "Chickens, layers manure management",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.F.1.a", "3.F.1.b", "3.F.1.c"]],
+        },
+        "3.F.1.a": {
+            "title": "Chickens, layers decomposition of organic matter",
+            "comment": "Chickens, layers decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.F.1.b": {
+            "title": "Chickens, layers manure management (Direct emissions N2O)",
+            "comment": "Chickens, layers manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.F.1.c": {
+            "title": "Chickens, layers manure management (Indirect emissions N2O)",
+            "comment": "Chickens, layers manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.F.2": {
+            "title": "Chickens, layers manure left on pasture",
+            "comment": "Chickens, layers manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.F.3": {
+            "title": "Chickens, layers manure applied",
+            "comment": "Chickens, layers manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.G.4": {
+            "title": "Goats enteric fermentation",
+            "comment": "Goats enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.G": {
             "title": "Goats",
             "comment": "Goats",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.G.1", "3.G.2", "3.G.3", "3.G.4"]],
+        },
+        "3.G.1": {
+            "title": "Goats manure management",
+            "comment": "Goats manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.G.1.a", "3.G.1.b", "3.G.1.c"]],
+        },
+        "3.G.1.a": {
+            "title": "Goats decomposition of organic matter",
+            "comment": "Goats decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.G.1.b": {
+            "title": "Goats manure management (Direct emissions N2O)",
+            "comment": "Goats manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.G.1.c": {
+            "title": "Goats manure management (Indirect emissions N2O)",
+            "comment": "Goats manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.G.2": {
+            "title": "Goats manure left on pasture",
+            "comment": "Goats manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.G.3": {
+            "title": "Goats manure applied",
+            "comment": "Goats manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.H.4": {
+            "title": "Horses enteric fermentation",
+            "comment": "Horses enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.H": {
             "title": "Horses",
             "comment": "Horses",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.H.1", "3.H.2", "3.H.3", "3.H.4"]],
+        },
+        "3.H.1": {
+            "title": "Horses manure management",
+            "comment": "Horses manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.H.1.a", "3.H.1.b", "3.H.1.c"]],
+        },
+        "3.H.1.a": {
+            "title": "Horses decomposition of organic matter",
+            "comment": "Horses decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.H.1.b": {
+            "title": "Horses manure management (Direct emissions N2O)",
+            "comment": "Horses manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.H.1.c": {
+            "title": "Horses manure management (Indirect emissions N2O)",
+            "comment": "Horses manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.H.2": {
+            "title": "Horses manure left on pasture",
+            "comment": "Horses manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.H.3": {
+            "title": "Horses manure applied",
+            "comment": "Horses manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.I.4": {
+            "title": "Mules and hinnies enteric fermentation",
+            "comment": "Mules and hinnies enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.I": {
             "title": "Mules and hinnies",
             "comment": "Mules and hinnies",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.I.1", "3.I.2", "3.I.3", "3.I.4"]],
+        },
+        "3.I.1": {
+            "title": "Mules and hinnies manure management",
+            "comment": "Mules and hinnies manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.I.1.a", "3.I.1.b", "3.I.1.c"]],
+        },
+        "3.I.1.a": {
+            "title": "Mules and hinnies decomposition of organic matter",
+            "comment": "Mules and hinnies decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.I.1.b": {
+            "title": "Mules and hinnies manure management (Direct emissions N2O)",
+            "comment": "Mules and hinnies manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.I.1.c": {
+            "title": "Mules and hinnies manure management (Indirect emissions N2O)",
+            "comment": "Mules and hinnies manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.I.2": {
+            "title": "Mules and hinnies manure left on pasture",
+            "comment": "Mules and hinnies manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.I.3": {
+            "title": "Mules and hinnies manure applied",
+            "comment": "Mules and hinnies manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.J.4": {
+            "title": "Sheep enteric fermentation",
+            "comment": "Sheep enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.J": {
             "title": "Sheep",
             "comment": "Sheep",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.J.1", "3.J.2", "3.J.3", "3.J.4"]],
+        },
+        "3.J.1": {
+            "title": "Sheep manure management",
+            "comment": "Sheep manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.J.1.a", "3.J.1.b", "3.J.1.c"]],
+        },
+        "3.J.1.a": {
+            "title": "Sheep decomposition of organic matter",
+            "comment": "Sheep decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.J.1.b": {
+            "title": "Sheep manure management (Direct emissions N2O)",
+            "comment": "Sheep manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.J.1.c": {
+            "title": "Sheep manure management (Indirect emissions N2O)",
+            "comment": "Sheep manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.J.2": {
+            "title": "Sheep manure left on pasture",
+            "comment": "Sheep manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.J.3": {
+            "title": "Sheep manure applied",
+            "comment": "Sheep manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.K.4": {
+            "title": "Llamas enteric fermentation",
+            "comment": "Llamas enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.K": {
             "title": "Llamas",
             "comment": "Llamas",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.K.1", "3.K.2", "3.K.3", "3.K.4"]],
+        },
+        "3.K.1": {
+            "title": "Llamas manure management",
+            "comment": "Llamas manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.K.1.a", "3.K.1.b", "3.K.1.c"]],
+        },
+        "3.K.1.a": {
+            "title": "Llamas decomposition of organic matter",
+            "comment": "Llamas decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.K.1.b": {
+            "title": "Llamas manure management (Direct emissions N2O)",
+            "comment": "Llamas manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.K.1.c": {
+            "title": "Llamas manure management (Indirect emissions N2O)",
+            "comment": "Llamas manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.K.2": {
+            "title": "Llamas manure left on pasture",
+            "comment": "Llamas manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.K.3": {
+            "title": "Llamas manure applied",
+            "comment": "Llamas manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.L": {
+            "title": "Chickens",
+            "comment": "Chickens",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.L.1", "3.L.2", "3.L.3"]],
+        },
+        "3.L.1": {
+            "title": "Chickens manure management",
+            "comment": "Chickens manure management",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.L.1.a", "3.L.1.b", "3.L.1.c"]],
+        },
+        "3.L.1.a": {
+            "title": "Chickens decomposition of organic matter",
+            "comment": "Chickens decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.L.1.b": {
+            "title": "Chickens manure management (Direct emissions N2O)",
+            "comment": "Chickens manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.L.1.c": {
+            "title": "Chickens manure management (Indirect emissions N2O)",
+            "comment": "Chickens manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.L.2": {
+            "title": "Chickens manure left on pasture",
+            "comment": "Chickens manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.L.3": {
+            "title": "Chickens manure applied",
+            "comment": "Chickens manure applied",
+            "info": {"gases": "N2O"},
         },
-        "3.L": {"title": "Chickens", "comment": "Chickens", "info": {"gases": ["N2O"]}},
         "3.M": {
             "title": "Poultry Birds",
             "comment": "Poultry Birds",
             "info": {"gases": ["N2O"]},
+            "children": [["3.M.1", "3.M.2", "3.M.3"]],
+        },
+        "3.M.1": {
+            "title": "Poultry Birds manure management",
+            "comment": "Poultry Birds manure management",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.M.1.a", "3.M.1.b", "3.M.1.c"]],
+        },
+        "3.M.1.a": {
+            "title": "Poultry Birds decomposition of organic matter",
+            "comment": "Poultry Birds decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.M.1.b": {
+            "title": "Poultry Birds manure management (Direct emissions N2O)",
+            "comment": "Poultry Birds manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.M.1.c": {
+            "title": "Poultry Birds manure management (Indirect emissions N2O)",
+            "comment": "Poultry Birds manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.M.2": {
+            "title": "Poultry Birds manure left on pasture",
+            "comment": "Poultry Birds manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.M.3": {
+            "title": "Poultry Birds manure applied",
+            "comment": "Poultry Birds manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.N.4": {
+            "title": "Buffalo enteric fermentation",
+            "comment": "Buffalo enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.N": {
             "title": "Buffalo",
             "comment": "Buffalo",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.N.1", "3.N.2", "3.N.3", "3.N.4"]],
+        },
+        "3.N.1": {
+            "title": "Buffalo manure management",
+            "comment": "Buffalo manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.N.1.a", "3.N.1.b", "3.N.1.c"]],
+        },
+        "3.N.1.a": {
+            "title": "Buffalo decomposition of organic matter",
+            "comment": "Buffalo decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.N.1.b": {
+            "title": "Buffalo manure management (Direct emissions N2O)",
+            "comment": "Buffalo manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.N.1.c": {
+            "title": "Buffalo manure management (Indirect emissions N2O)",
+            "comment": "Buffalo manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.N.2": {
+            "title": "Buffalo manure left on pasture",
+            "comment": "Buffalo manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.N.3": {
+            "title": "Buffalo manure applied",
+            "comment": "Buffalo manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.O": {
+            "title": "Ducks",
+            "comment": "Ducks",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.O.1", "3.O.2", "3.O.3"]],
+        },
+        "3.O.1": {
+            "title": "Ducks manure management",
+            "comment": "Ducks manure management",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.O.1.a", "3.O.1.b", "3.O.1.c"]],
+        },
+        "3.O.1.a": {
+            "title": "Ducks decomposition of organic matter",
+            "comment": "Ducks decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.O.1.b": {
+            "title": "Ducks manure management (Direct emissions N2O)",
+            "comment": "Ducks manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.O.1.c": {
+            "title": "Ducks manure management (Indirect emissions N2O)",
+            "comment": "Ducks manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.O.2": {
+            "title": "Ducks manure left on pasture",
+            "comment": "Ducks manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.O.3": {
+            "title": "Ducks manure applied",
+            "comment": "Ducks manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.P.4": {
+            "title": "Swine, breeding enteric fermentation",
+            "comment": "Swine, breeding enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
-        "3.O": {"title": "Ducks", "comment": "Ducks", "info": {"gases": ["N2O"]}},
         "3.P": {
             "title": "Swine, breeding",
             "comment": "Swine, breeding",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.P.1", "3.P.2", "3.P.3", "3.P.4"]],
+        },
+        "3.P.1": {
+            "title": "Swine, breeding manure management",
+            "comment": "Swine, breeding manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.P.1.a", "3.P.1.b", "3.P.1.c"]],
+        },
+        "3.P.1.a": {
+            "title": "Swine, breeding decomposition of organic matter",
+            "comment": "Swine, breeding decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.P.1.b": {
+            "title": "Swine, breeding manure management (Direct emissions N2O)",
+            "comment": "Swine, breeding manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.P.1.c": {
+            "title": "Swine, breeding manure management (Indirect emissions N2O)",
+            "comment": "Swine, breeding manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.P.2": {
+            "title": "Swine, breeding manure left on pasture",
+            "comment": "Swine, breeding manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.P.3": {
+            "title": "Swine, breeding manure applied",
+            "comment": "Swine, breeding manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.Q.4": {
+            "title": "Swine, market enteric fermentation",
+            "comment": "Swine, market enteric fermentation",
+            "info": {"gases": ["CH4", "N2O"]},
         },
         "3.Q": {
             "title": "Swine, market",
             "comment": "Swine, market",
             "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.Q.1", "3.Q.2", "3.Q.3", "3.Q.4"]],
+        },
+        "3.Q.1": {
+            "title": "Swine, market manure management",
+            "comment": "Swine, market manure management",
+            "info": {"gases": ["CH4", "N2O"]},
+            "children": [["3.Q.1.a", "3.Q.1.b", "3.Q.1.c"]],
+        },
+        "3.Q.1.a": {
+            "title": "Swine, market decomposition of organic matter",
+            "comment": "Swine, market decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.Q.1.b": {
+            "title": "Swine, market manure management (Direct emissions N2O)",
+            "comment": "Swine, market manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.Q.1.c": {
+            "title": "Swine, market manure management (Indirect emissions N2O)",
+            "comment": "Swine, market manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.Q.2": {
+            "title": "Swine, market manure left on pasture",
+            "comment": "Swine, market manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.Q.3": {
+            "title": "Swine, market manure applied",
+            "comment": "Swine, market manure applied",
+            "info": {"gases": "N2O"},
+        },
+        "3.R": {
+            "title": "Turkeys",
+            "comment": "Turkeys",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.R.1", "3.R.2", "3.R.3"]],
+        },
+        "3.R.1": {
+            "title": "Turkeys manure management",
+            "comment": "Turkeys manure management",
+            "info": {"gases": ["N2O"]},
+            "children": [["3.R.1.a", "3.R.1.b", "3.R.1.c"]],
+        },
+        "3.R.1.a": {
+            "title": "Turkeys decomposition of organic matter",
+            "comment": "Turkeys decomposition of organic matter",
+            "info": {"gases": "CH4"},
+        },
+        "3.R.1.b": {
+            "title": "Turkeys manure management (Direct emissions N2O)",
+            "comment": "Turkeys manure management (Direct emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.R.1.c": {
+            "title": "Turkeys manure management (Indirect emissions N2O)",
+            "comment": "Turkeys manure management (Indirect emissions N2O)",
+            "info": {"gases": "N2O"},
+        },
+        "3.R.2": {
+            "title": "Turkeys manure left on pasture",
+            "comment": "Turkeys manure left on pasture",
+            "info": {"gases": "N2O"},
+        },
+        "3.R.3": {
+            "title": "Turkeys manure applied",
+            "comment": "Turkeys manure applied",
+            "info": {"gases": "N2O"},
         },
-        "3.R": {"title": "Turkeys", "comment": "Turkeys", "info": {"gases": ["N2O"]}},
         "4": {
             "title": "Carbon stock change in forests",
             "comment": "Carbon stock change in forests",

+ 782 - 26
tests/unit/FAO.yaml

@@ -550,126 +550,882 @@ categories:
       - CH4
       - N2O
       - CO2
+  3.A.4:
+    title: Asses enteric fermentation
+    comment: Asses enteric fermentation
+    info:
+      gases: &id001
+      - CH4
+      - N2O
   3.A:
     title: Asses
     comment: Asses
     info:
-      gases:
+      gases: *id001
+    children:
+    - - 3.A.1
+      - 3.A.2
+      - 3.A.3
+      - 3.A.4
+  3.A.1:
+    title: Asses manure management
+    comment: Asses manure management
+    info:
+      gases: *id001
+    children:
+    - - 3.A.1.a
+      - 3.A.1.b
+      - 3.A.1.c
+  3.A.1.a:
+    title: Asses decomposition of organic matter
+    comment: Asses decomposition of organic matter
+    info:
+      gases: CH4
+  3.A.1.b:
+    title: Asses manure management (Direct emissions N2O)
+    comment: Asses manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.A.1.c:
+    title: Asses manure management (Indirect emissions N2O)
+    comment: Asses manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.A.2:
+    title: Asses manure left on pasture
+    comment: Asses manure left on pasture
+    info:
+      gases: N2O
+  3.A.3:
+    title: Asses manure applied
+    comment: Asses manure applied
+    info:
+      gases: N2O
+  3.B.4:
+    title: Camels enteric fermentation
+    comment: Camels enteric fermentation
+    info:
+      gases: &id002
       - CH4
       - N2O
   3.B:
     title: Camels
     comment: Camels
     info:
-      gases:
+      gases: *id002
+    children:
+    - - 3.B.1
+      - 3.B.2
+      - 3.B.3
+      - 3.B.4
+  3.B.1:
+    title: Camels manure management
+    comment: Camels manure management
+    info:
+      gases: *id002
+    children:
+    - - 3.B.1.a
+      - 3.B.1.b
+      - 3.B.1.c
+  3.B.1.a:
+    title: Camels decomposition of organic matter
+    comment: Camels decomposition of organic matter
+    info:
+      gases: CH4
+  3.B.1.b:
+    title: Camels manure management (Direct emissions N2O)
+    comment: Camels manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.B.1.c:
+    title: Camels manure management (Indirect emissions N2O)
+    comment: Camels manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.B.2:
+    title: Camels manure left on pasture
+    comment: Camels manure left on pasture
+    info:
+      gases: N2O
+  3.B.3:
+    title: Camels manure applied
+    comment: Camels manure applied
+    info:
+      gases: N2O
+  3.C.4:
+    title: Cattle, dairy enteric fermentation
+    comment: Cattle, dairy enteric fermentation
+    info:
+      gases: &id003
       - CH4
       - N2O
   3.C:
     title: Cattle, dairy
     comment: Cattle, dairy
     info:
-      gases:
+      gases: *id003
+    children:
+    - - 3.C.1
+      - 3.C.2
+      - 3.C.3
+      - 3.C.4
+  3.C.1:
+    title: Cattle, dairy manure management
+    comment: Cattle, dairy manure management
+    info:
+      gases: *id003
+    children:
+    - - 3.C.1.a
+      - 3.C.1.b
+      - 3.C.1.c
+  3.C.1.a:
+    title: Cattle, dairy decomposition of organic matter
+    comment: Cattle, dairy decomposition of organic matter
+    info:
+      gases: CH4
+  3.C.1.b:
+    title: Cattle, dairy manure management (Direct emissions N2O)
+    comment: Cattle, dairy manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.C.1.c:
+    title: Cattle, dairy manure management (Indirect emissions N2O)
+    comment: Cattle, dairy manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.C.2:
+    title: Cattle, dairy manure left on pasture
+    comment: Cattle, dairy manure left on pasture
+    info:
+      gases: N2O
+  3.C.3:
+    title: Cattle, dairy manure applied
+    comment: Cattle, dairy manure applied
+    info:
+      gases: N2O
+  3.D.4:
+    title: Cattle, non-dairy enteric fermentation
+    comment: Cattle, non-dairy enteric fermentation
+    info:
+      gases: &id004
       - CH4
       - N2O
   3.D:
     title: Cattle, non-dairy
     comment: Cattle, non-dairy
     info:
-      gases:
-      - CH4
-      - N2O
+      gases: *id004
+    children:
+    - - 3.D.1
+      - 3.D.2
+      - 3.D.3
+      - 3.D.4
+  3.D.1:
+    title: Cattle, non-dairy manure management
+    comment: Cattle, non-dairy manure management
+    info:
+      gases: *id004
+    children:
+    - - 3.D.1.a
+      - 3.D.1.b
+      - 3.D.1.c
+  3.D.1.a:
+    title: Cattle, non-dairy decomposition of organic matter
+    comment: Cattle, non-dairy decomposition of organic matter
+    info:
+      gases: CH4
+  3.D.1.b:
+    title: Cattle, non-dairy manure management (Direct emissions N2O)
+    comment: Cattle, non-dairy manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.D.1.c:
+    title: Cattle, non-dairy manure management (Indirect emissions N2O)
+    comment: Cattle, non-dairy manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.D.2:
+    title: Cattle, non-dairy manure left on pasture
+    comment: Cattle, non-dairy manure left on pasture
+    info:
+      gases: N2O
+  3.D.3:
+    title: Cattle, non-dairy manure applied
+    comment: Cattle, non-dairy manure applied
+    info:
+      gases: N2O
   3.E:
     title: Chickens, broilers
     comment: Chickens, broilers
     info:
-      gases:
+      gases: &id005
       - N2O
+    children:
+    - - 3.E.1
+      - 3.E.2
+      - 3.E.3
+  3.E.1:
+    title: Chickens, broilers manure management
+    comment: Chickens, broilers manure management
+    info:
+      gases: *id005
+    children:
+    - - 3.E.1.a
+      - 3.E.1.b
+      - 3.E.1.c
+  3.E.1.a:
+    title: Chickens, broilers decomposition of organic matter
+    comment: Chickens, broilers decomposition of organic matter
+    info:
+      gases: CH4
+  3.E.1.b:
+    title: Chickens, broilers manure management (Direct emissions N2O)
+    comment: Chickens, broilers manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.E.1.c:
+    title: Chickens, broilers manure management (Indirect emissions N2O)
+    comment: Chickens, broilers manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.E.2:
+    title: Chickens, broilers manure left on pasture
+    comment: Chickens, broilers manure left on pasture
+    info:
+      gases: N2O
+  3.E.3:
+    title: Chickens, broilers manure applied
+    comment: Chickens, broilers manure applied
+    info:
+      gases: N2O
   3.F:
     title: Chickens, layers
     comment: Chickens, layers
     info:
-      gases:
+      gases: &id006
+      - N2O
+    children:
+    - - 3.F.1
+      - 3.F.2
+      - 3.F.3
+  3.F.1:
+    title: Chickens, layers manure management
+    comment: Chickens, layers manure management
+    info:
+      gases: *id006
+    children:
+    - - 3.F.1.a
+      - 3.F.1.b
+      - 3.F.1.c
+  3.F.1.a:
+    title: Chickens, layers decomposition of organic matter
+    comment: Chickens, layers decomposition of organic matter
+    info:
+      gases: CH4
+  3.F.1.b:
+    title: Chickens, layers manure management (Direct emissions N2O)
+    comment: Chickens, layers manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.F.1.c:
+    title: Chickens, layers manure management (Indirect emissions N2O)
+    comment: Chickens, layers manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.F.2:
+    title: Chickens, layers manure left on pasture
+    comment: Chickens, layers manure left on pasture
+    info:
+      gases: N2O
+  3.F.3:
+    title: Chickens, layers manure applied
+    comment: Chickens, layers manure applied
+    info:
+      gases: N2O
+  3.G.4:
+    title: Goats enteric fermentation
+    comment: Goats enteric fermentation
+    info:
+      gases: &id007
+      - CH4
       - N2O
   3.G:
     title: Goats
     comment: Goats
     info:
-      gases:
+      gases: *id007
+    children:
+    - - 3.G.1
+      - 3.G.2
+      - 3.G.3
+      - 3.G.4
+  3.G.1:
+    title: Goats manure management
+    comment: Goats manure management
+    info:
+      gases: *id007
+    children:
+    - - 3.G.1.a
+      - 3.G.1.b
+      - 3.G.1.c
+  3.G.1.a:
+    title: Goats decomposition of organic matter
+    comment: Goats decomposition of organic matter
+    info:
+      gases: CH4
+  3.G.1.b:
+    title: Goats manure management (Direct emissions N2O)
+    comment: Goats manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.G.1.c:
+    title: Goats manure management (Indirect emissions N2O)
+    comment: Goats manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.G.2:
+    title: Goats manure left on pasture
+    comment: Goats manure left on pasture
+    info:
+      gases: N2O
+  3.G.3:
+    title: Goats manure applied
+    comment: Goats manure applied
+    info:
+      gases: N2O
+  3.H.4:
+    title: Horses enteric fermentation
+    comment: Horses enteric fermentation
+    info:
+      gases: &id008
       - CH4
       - N2O
   3.H:
     title: Horses
     comment: Horses
     info:
-      gases:
+      gases: *id008
+    children:
+    - - 3.H.1
+      - 3.H.2
+      - 3.H.3
+      - 3.H.4
+  3.H.1:
+    title: Horses manure management
+    comment: Horses manure management
+    info:
+      gases: *id008
+    children:
+    - - 3.H.1.a
+      - 3.H.1.b
+      - 3.H.1.c
+  3.H.1.a:
+    title: Horses decomposition of organic matter
+    comment: Horses decomposition of organic matter
+    info:
+      gases: CH4
+  3.H.1.b:
+    title: Horses manure management (Direct emissions N2O)
+    comment: Horses manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.H.1.c:
+    title: Horses manure management (Indirect emissions N2O)
+    comment: Horses manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.H.2:
+    title: Horses manure left on pasture
+    comment: Horses manure left on pasture
+    info:
+      gases: N2O
+  3.H.3:
+    title: Horses manure applied
+    comment: Horses manure applied
+    info:
+      gases: N2O
+  3.I.4:
+    title: Mules and hinnies enteric fermentation
+    comment: Mules and hinnies enteric fermentation
+    info:
+      gases: &id009
       - CH4
       - N2O
   3.I:
     title: Mules and hinnies
     comment: Mules and hinnies
     info:
-      gases:
+      gases: *id009
+    children:
+    - - 3.I.1
+      - 3.I.2
+      - 3.I.3
+      - 3.I.4
+  3.I.1:
+    title: Mules and hinnies manure management
+    comment: Mules and hinnies manure management
+    info:
+      gases: *id009
+    children:
+    - - 3.I.1.a
+      - 3.I.1.b
+      - 3.I.1.c
+  3.I.1.a:
+    title: Mules and hinnies decomposition of organic matter
+    comment: Mules and hinnies decomposition of organic matter
+    info:
+      gases: CH4
+  3.I.1.b:
+    title: Mules and hinnies manure management (Direct emissions N2O)
+    comment: Mules and hinnies manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.I.1.c:
+    title: Mules and hinnies manure management (Indirect emissions N2O)
+    comment: Mules and hinnies manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.I.2:
+    title: Mules and hinnies manure left on pasture
+    comment: Mules and hinnies manure left on pasture
+    info:
+      gases: N2O
+  3.I.3:
+    title: Mules and hinnies manure applied
+    comment: Mules and hinnies manure applied
+    info:
+      gases: N2O
+  3.J.4:
+    title: Sheep enteric fermentation
+    comment: Sheep enteric fermentation
+    info:
+      gases: &id010
       - CH4
       - N2O
   3.J:
     title: Sheep
     comment: Sheep
     info:
-      gases:
+      gases: *id010
+    children:
+    - - 3.J.1
+      - 3.J.2
+      - 3.J.3
+      - 3.J.4
+  3.J.1:
+    title: Sheep manure management
+    comment: Sheep manure management
+    info:
+      gases: *id010
+    children:
+    - - 3.J.1.a
+      - 3.J.1.b
+      - 3.J.1.c
+  3.J.1.a:
+    title: Sheep decomposition of organic matter
+    comment: Sheep decomposition of organic matter
+    info:
+      gases: CH4
+  3.J.1.b:
+    title: Sheep manure management (Direct emissions N2O)
+    comment: Sheep manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.J.1.c:
+    title: Sheep manure management (Indirect emissions N2O)
+    comment: Sheep manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.J.2:
+    title: Sheep manure left on pasture
+    comment: Sheep manure left on pasture
+    info:
+      gases: N2O
+  3.J.3:
+    title: Sheep manure applied
+    comment: Sheep manure applied
+    info:
+      gases: N2O
+  3.K.4:
+    title: Llamas enteric fermentation
+    comment: Llamas enteric fermentation
+    info:
+      gases: &id011
       - CH4
       - N2O
   3.K:
     title: Llamas
     comment: Llamas
     info:
-      gases:
-      - CH4
-      - N2O
+      gases: *id011
+    children:
+    - - 3.K.1
+      - 3.K.2
+      - 3.K.3
+      - 3.K.4
+  3.K.1:
+    title: Llamas manure management
+    comment: Llamas manure management
+    info:
+      gases: *id011
+    children:
+    - - 3.K.1.a
+      - 3.K.1.b
+      - 3.K.1.c
+  3.K.1.a:
+    title: Llamas decomposition of organic matter
+    comment: Llamas decomposition of organic matter
+    info:
+      gases: CH4
+  3.K.1.b:
+    title: Llamas manure management (Direct emissions N2O)
+    comment: Llamas manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.K.1.c:
+    title: Llamas manure management (Indirect emissions N2O)
+    comment: Llamas manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.K.2:
+    title: Llamas manure left on pasture
+    comment: Llamas manure left on pasture
+    info:
+      gases: N2O
+  3.K.3:
+    title: Llamas manure applied
+    comment: Llamas manure applied
+    info:
+      gases: N2O
   3.L:
     title: Chickens
     comment: Chickens
     info:
-      gases:
+      gases: &id012
       - N2O
+    children:
+    - - 3.L.1
+      - 3.L.2
+      - 3.L.3
+  3.L.1:
+    title: Chickens manure management
+    comment: Chickens manure management
+    info:
+      gases: *id012
+    children:
+    - - 3.L.1.a
+      - 3.L.1.b
+      - 3.L.1.c
+  3.L.1.a:
+    title: Chickens decomposition of organic matter
+    comment: Chickens decomposition of organic matter
+    info:
+      gases: CH4
+  3.L.1.b:
+    title: Chickens manure management (Direct emissions N2O)
+    comment: Chickens manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.L.1.c:
+    title: Chickens manure management (Indirect emissions N2O)
+    comment: Chickens manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.L.2:
+    title: Chickens manure left on pasture
+    comment: Chickens manure left on pasture
+    info:
+      gases: N2O
+  3.L.3:
+    title: Chickens manure applied
+    comment: Chickens manure applied
+    info:
+      gases: N2O
   3.M:
     title: Poultry Birds
     comment: Poultry Birds
     info:
-      gases:
+      gases: &id013
+      - N2O
+    children:
+    - - 3.M.1
+      - 3.M.2
+      - 3.M.3
+  3.M.1:
+    title: Poultry Birds manure management
+    comment: Poultry Birds manure management
+    info:
+      gases: *id013
+    children:
+    - - 3.M.1.a
+      - 3.M.1.b
+      - 3.M.1.c
+  3.M.1.a:
+    title: Poultry Birds decomposition of organic matter
+    comment: Poultry Birds decomposition of organic matter
+    info:
+      gases: CH4
+  3.M.1.b:
+    title: Poultry Birds manure management (Direct emissions N2O)
+    comment: Poultry Birds manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.M.1.c:
+    title: Poultry Birds manure management (Indirect emissions N2O)
+    comment: Poultry Birds manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.M.2:
+    title: Poultry Birds manure left on pasture
+    comment: Poultry Birds manure left on pasture
+    info:
+      gases: N2O
+  3.M.3:
+    title: Poultry Birds manure applied
+    comment: Poultry Birds manure applied
+    info:
+      gases: N2O
+  3.N.4:
+    title: Buffalo enteric fermentation
+    comment: Buffalo enteric fermentation
+    info:
+      gases: &id014
+      - CH4
       - N2O
   3.N:
     title: Buffalo
     comment: Buffalo
     info:
-      gases:
-      - CH4
-      - N2O
+      gases: *id014
+    children:
+    - - 3.N.1
+      - 3.N.2
+      - 3.N.3
+      - 3.N.4
+  3.N.1:
+    title: Buffalo manure management
+    comment: Buffalo manure management
+    info:
+      gases: *id014
+    children:
+    - - 3.N.1.a
+      - 3.N.1.b
+      - 3.N.1.c
+  3.N.1.a:
+    title: Buffalo decomposition of organic matter
+    comment: Buffalo decomposition of organic matter
+    info:
+      gases: CH4
+  3.N.1.b:
+    title: Buffalo manure management (Direct emissions N2O)
+    comment: Buffalo manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.N.1.c:
+    title: Buffalo manure management (Indirect emissions N2O)
+    comment: Buffalo manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.N.2:
+    title: Buffalo manure left on pasture
+    comment: Buffalo manure left on pasture
+    info:
+      gases: N2O
+  3.N.3:
+    title: Buffalo manure applied
+    comment: Buffalo manure applied
+    info:
+      gases: N2O
   3.O:
     title: Ducks
     comment: Ducks
     info:
-      gases:
+      gases: &id015
+      - N2O
+    children:
+    - - 3.O.1
+      - 3.O.2
+      - 3.O.3
+  3.O.1:
+    title: Ducks manure management
+    comment: Ducks manure management
+    info:
+      gases: *id015
+    children:
+    - - 3.O.1.a
+      - 3.O.1.b
+      - 3.O.1.c
+  3.O.1.a:
+    title: Ducks decomposition of organic matter
+    comment: Ducks decomposition of organic matter
+    info:
+      gases: CH4
+  3.O.1.b:
+    title: Ducks manure management (Direct emissions N2O)
+    comment: Ducks manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.O.1.c:
+    title: Ducks manure management (Indirect emissions N2O)
+    comment: Ducks manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.O.2:
+    title: Ducks manure left on pasture
+    comment: Ducks manure left on pasture
+    info:
+      gases: N2O
+  3.O.3:
+    title: Ducks manure applied
+    comment: Ducks manure applied
+    info:
+      gases: N2O
+  3.P.4:
+    title: Swine, breeding enteric fermentation
+    comment: Swine, breeding enteric fermentation
+    info:
+      gases: &id016
+      - CH4
       - N2O
   3.P:
     title: Swine, breeding
     comment: Swine, breeding
     info:
-      gases:
+      gases: *id016
+    children:
+    - - 3.P.1
+      - 3.P.2
+      - 3.P.3
+      - 3.P.4
+  3.P.1:
+    title: Swine, breeding manure management
+    comment: Swine, breeding manure management
+    info:
+      gases: *id016
+    children:
+    - - 3.P.1.a
+      - 3.P.1.b
+      - 3.P.1.c
+  3.P.1.a:
+    title: Swine, breeding decomposition of organic matter
+    comment: Swine, breeding decomposition of organic matter
+    info:
+      gases: CH4
+  3.P.1.b:
+    title: Swine, breeding manure management (Direct emissions N2O)
+    comment: Swine, breeding manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.P.1.c:
+    title: Swine, breeding manure management (Indirect emissions N2O)
+    comment: Swine, breeding manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.P.2:
+    title: Swine, breeding manure left on pasture
+    comment: Swine, breeding manure left on pasture
+    info:
+      gases: N2O
+  3.P.3:
+    title: Swine, breeding manure applied
+    comment: Swine, breeding manure applied
+    info:
+      gases: N2O
+  3.Q.4:
+    title: Swine, market enteric fermentation
+    comment: Swine, market enteric fermentation
+    info:
+      gases: &id017
       - CH4
       - N2O
   3.Q:
     title: Swine, market
     comment: Swine, market
     info:
-      gases:
-      - CH4
-      - N2O
+      gases: *id017
+    children:
+    - - 3.Q.1
+      - 3.Q.2
+      - 3.Q.3
+      - 3.Q.4
+  3.Q.1:
+    title: Swine, market manure management
+    comment: Swine, market manure management
+    info:
+      gases: *id017
+    children:
+    - - 3.Q.1.a
+      - 3.Q.1.b
+      - 3.Q.1.c
+  3.Q.1.a:
+    title: Swine, market decomposition of organic matter
+    comment: Swine, market decomposition of organic matter
+    info:
+      gases: CH4
+  3.Q.1.b:
+    title: Swine, market manure management (Direct emissions N2O)
+    comment: Swine, market manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.Q.1.c:
+    title: Swine, market manure management (Indirect emissions N2O)
+    comment: Swine, market manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.Q.2:
+    title: Swine, market manure left on pasture
+    comment: Swine, market manure left on pasture
+    info:
+      gases: N2O
+  3.Q.3:
+    title: Swine, market manure applied
+    comment: Swine, market manure applied
+    info:
+      gases: N2O
   3.R:
     title: Turkeys
     comment: Turkeys
     info:
-      gases:
+      gases: &id018
       - N2O
+    children:
+    - - 3.R.1
+      - 3.R.2
+      - 3.R.3
+  3.R.1:
+    title: Turkeys manure management
+    comment: Turkeys manure management
+    info:
+      gases: *id018
+    children:
+    - - 3.R.1.a
+      - 3.R.1.b
+      - 3.R.1.c
+  3.R.1.a:
+    title: Turkeys decomposition of organic matter
+    comment: Turkeys decomposition of organic matter
+    info:
+      gases: CH4
+  3.R.1.b:
+    title: Turkeys manure management (Direct emissions N2O)
+    comment: Turkeys manure management (Direct emissions N2O)
+    info:
+      gases: N2O
+  3.R.1.c:
+    title: Turkeys manure management (Indirect emissions N2O)
+    comment: Turkeys manure management (Indirect emissions N2O)
+    info:
+      gases: N2O
+  3.R.2:
+    title: Turkeys manure left on pasture
+    comment: Turkeys manure left on pasture
+    info:
+      gases: N2O
+  3.R.3:
+    title: Turkeys manure applied
+    comment: Turkeys manure applied
+    info:
+      gases: N2O
   '4':
     title: Carbon stock change in forests
     comment: Carbon stock change in forests

+ 67 - 6
tests/unit/test_conversion.py

@@ -9,8 +9,8 @@ from src.faostat_data_primap.read import read_data
 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"),
+        # ("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"),
@@ -259,7 +259,7 @@ def test_make_dict_comprehension_for_faster_typing():  # noqa: PLR0912 PLR0915
             "info": {"gases": ["CH4", "N2O", "CO2"]},
         }
 
-    # livestock
+    # 3 livestock
     animals = [
         "Asses",
         "Camels",
@@ -301,13 +301,74 @@ def test_make_dict_comprehension_for_faster_typing():  # noqa: PLR0912 PLR0915
     for animal, code in zip(animals, codes_animals):
         if animal in enteric_fermentation:
             gases = ["CH4", "N2O"]
+            animal_children = [f"{code}.{i}" for i in "1234"]
+            categories[f"{code}.4"] = {
+                "title": f"{animal} enteric fermentation",
+                "comment": f"{animal} enteric fermentation",
+                # "alternative_codes" : code.replace(".", ""),
+                "info": {"gases": gases},
+            }
         else:
             gases = ["N2O"]
+            animal_children = [f"{code}.{i}" for i in "123"]
+
         categories[code] = {
             "title": animal,
             "comment": animal,
             # "alternative_codes" : code.replace(".", ""),
             "info": {"gases": gases},
+            "children": [animal_children],
+        }
+
+        # manure management branch
+        manure_management_children = [f"{code}.1.{i}" for i in "abc"]
+        categories[f"{code}.1"] = {
+            "title": f"{animal} manure management",
+            "comment": f"{animal} manure management",
+            # "alternative_codes" : code.replace(".", ""),
+            "info": {"gases": gases},
+            "children": [manure_management_children],
+        }
+
+        categories[f"{code}.1.a"] = {
+            "title": f"{animal} decomposition of organic matter",
+            "comment": f"{animal} decomposition of organic matter",
+            # "alternative_codes" : code.replace(".", ""),
+            "info": {"gases": "CH4"},
+        }
+
+        categories[f"{code}.1.b"] = {
+            "title": f"{animal} manure management (Direct emissions N2O)",
+            "comment": f"{animal} manure management (Direct emissions N2O)",
+            # "alternative_codes" : code.replace(".", ""),
+            "info": {"gases": "N2O"},
+        }
+
+        categories[f"{code}.1.c"] = {
+            "title": f"{animal} manure management (Indirect emissions N2O)",
+            "comment": f"{animal} manure management (Indirect emissions N2O)",
+            # "alternative_codes" : code.replace(".", ""),
+            "info": {"gases": "N2O"},
+        }
+
+        # manure left on pasture
+        # manure_left_on_pasture_children = [f"{code}.2.{i}" for i in "ab"]
+        categories[f"{code}.2"] = {
+            "title": f"{animal} manure left on pasture",
+            "comment": f"{animal} manure left on pasture",
+            # "alternative_codes" : code.replace(".", ""),
+            "info": {"gases": "N2O"},
+            # "children" : [manure_left_on_pasture_children],
+        }
+
+        # manure left on pasture
+        # manure_applied_children = [f"{code}.3.{i}" for i in "ab"]
+        categories[f"{code}.3"] = {
+            "title": f"{animal} manure applied",
+            "comment": f"{animal} manure applied",
+            # "alternative_codes" : code.replace(".", ""),
+            "info": {"gases": "N2O"},
+            # "children" : [manure_applied_children],
         }
 
     # forests
@@ -467,10 +528,10 @@ def test_make_dict_comprehension_for_faster_typing():  # noqa: PLR0912 PLR0915
     }
 
     spec["categories"] = categories
-    cat = cc.HierarchicalCategorization.from_spec(spec.copy())
+    fao_cats = cc.HierarchicalCategorization.from_spec(spec.copy())
     # run print(cat.show_as_tree())
-    cat.to_python("FAO.py")
-    cat.to_yaml("FAO.yaml")
+    fao_cats.to_python("FAO.py")
+    fao_cats.to_yaml("FAO.yaml")
     pass