Daniel Busch преди 2 месеца
родител
ревизия
d075bcc26d
променени са 1 файла, в които са добавени 17 реда и са изтрити 39 реда
  1. 17 39
      tests/unit/test_conversion.py

+ 17 - 39
tests/unit/test_conversion.py

@@ -46,7 +46,6 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
         da_dict[var] = ds[var].pr.convert(
             dim="category (FAOSTAT)",
             conversion=conv[var],
-            # auxiliary_dimensions={"gas": "entity"},
         )
 
     result = xr.Dataset(da_dict)
@@ -57,17 +56,17 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
 
     result = pm2.pm2io.from_interchange_format(result_if)
 
-    country_processing_step1 = {
-        "tolerance": 0.01,
-        "aggregate_cats": {
-            # "M.3.D.AG" : {"sources" : ["3.D.2"]}, we don't have 3.D.2
+    agg_info = {
+        "category (IPCC2006_PRIMAP)": {
+            "3.C.1": {
+                "sources": ["3.C.1.a", "3.C.1.b", "3.C.1.c"],
+            },
             "M.3.C.AG": {
                 "sources": ["3.C.1", "3.C.4", "3.C.5"],
             },
             "M.AG.ELV": {
                 "sources": ["M.3.C.AG"],  # "M.3.D.AG" is zero
             },
-            "3.C.1": {"sources": ["3.C.1.a", "3.C.1.b"]},
             "3.C": {
                 "sources": [
                     "3.C.1",
@@ -80,12 +79,12 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
                 ]
             },
             # "3.D" : {"sources" : ["3.D.1", "3.D.2"]}, # we don't have it
-            "3.A.1.a": {
+            "3.A.1.a": {  # cattle (dairy) + cattle (non-dairy)
                 "sources": [
                     "3.A.1.a.i",
                     "3.A.1.a.ii",
                 ]
-            },  # cattle (dairy) + cattle (non-dairy)
+            },
             "3.A.1": {
                 "sources": [
                     "3.A.1.a",
@@ -95,16 +94,16 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
                     "3.A.1.e",
                     "3.A.1.f",
                     "3.A.1.g",
-                    "3.A.1.h",  # what happened to 3.A.1.i
+                    "3.A.1.h",  # 3.A.1.i poultry left out because it is a group of categories
                     "3.A.1.j",
                 ]
             },
-            "3.A.2.a": {
+            "3.A.2.a": {  # decomposition of manure cattle (dairy) + cattle (non-dairy)
                 "sources": [
                     "3.A.2.a.i",
                     "3.A.2.a.ii",
                 ]
-            },  # cattle (dairy) + cattle (non-dairy)
+            },
             "3.A.2": {
                 "sources": [
                     "3.A.2.a",
@@ -121,38 +120,17 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
             },
             "3.A": {"sources": ["3.A.1", "3.A.2"]},
             "M.AG": {"sources": ["3.A", "M.AG.ELV"]},
-            # M.AG.ELV
-            # AFOLU
             # "M.3.D.LU": {"sources": ["3.D.1"]},
-            "M.LULUCF": {"sources": ["3.B"]},  # , "M.3.D.LU"]},
-        },
+            # Forest Land + Cropland + Grassland, all we have
+            "M.LULUCF": {"sources": ["3.B.1", "3.B.2", "3.B.3"]},
+            "M.AFOLU": {"sources": ["M.AG", "M.LULUCF"]},
+        }
     }
 
-    # prep input to add_aggregates_coordinates
-    agg_info = {"category": country_processing_step1["aggregate_cats"]}
-
-    agg_tolerance = country_processing_step1["tolerance"]
-
-    df_list = []
-    for iso3_code in result.coords["area (ISO3)"].to_numpy():
-        result_per_country = result.pr.loc[
-            {
-                "area (ISO3)": iso3_code,
-            }
-        ]
-
-        result_per_country = result_per_country.pr.add_aggregates_coordinates(
-            agg_info=agg_info,
-            tolerance=agg_tolerance,
-            skipna=True,
-            min_count=1,
-        )
-
-        result_per_country_if = result_per_country.pr.to_interchange_format()
-
-        df_list.append(result_per_country_if)
+    result_proc = result.pr.add_aggregates_coordinates(agg_info=agg_info)
 
-    # df_all = pd.concat(df_list, axis=0, join="outer", ignore_index=True)
+    result_proc_if = result_proc.pr.to_interchange_format()
+    assert result_proc_if
 
     # df_all = pd.concat([ds_if, result_if], axis=0, join="outer", ignore_index=True)
     #