Browse Source

Fix bugs in singapore BUR5

Johannes Gütschow 9 months ago
parent
commit
f624781488

+ 63 - 2
src/unfccc_ghg_data/unfccc_reader/Singapore/config_sgp_bur5.py

@@ -199,6 +199,36 @@ table_def_templates = {
             "unit": ["", "GgCO2eq", "GgCO2eq", "GgCO2eq", "GgCO2eq"],
         },
     },
+    "100_2": {  # 95
+        "area": ["666,731,1103,149"],
+        "cols": ["829,903,971,1048"],
+        "drop_rows": [0, 1, 2, 3, 4, 5],
+        "rows_to_fix": {
+            2: [
+                "3C - Aggregate Sources and Non-CO2",
+            ],
+            3: [
+                "Total (Net)",
+                "1A2 Manufacturing Industries",
+                "2 — INDUSTRIAL PROCESSES",
+                "3 — AGRICULTURE, FORESTRY",
+                "4C - Incineration and Open",
+                "Clinical Waste",
+                "4D - Wastewater Treatment",
+                "CO2 from Biomass Combustion for",
+            ],
+        },
+        "header": {
+            "entity": [
+                "Greenhouse Gas Source and Sink Categories",
+                "PFCs",
+                "SF6",
+                "NF3",
+                "Total (Net) National Emissions",
+            ],
+            "unit": ["", "GgCO2eq", "GgCO2eq", "GgCO2eq", "GgCO2eq"],
+        },
+    },
 }
 
 table_defs = {
@@ -341,7 +371,7 @@ table_defs = {
         "coords_value_mapping": "other",
     },
     "100": {
-        "templates": ["95_1", "95_2"],
+        "templates": ["95_1", "100_2"],
         "category_col": "Greenhouse Gas Source and Sink Categories",
         "year": 1994,
         # "unit_info": unit_info_2018,
@@ -482,10 +512,16 @@ aggregate_sectors = {
     },
     "M.3.C.1.AG": {
         "sources": ["3.C.1.b", "3.C.1.c"],
+        "filter": {
+            "entity": ["CO2", "CH4", "N2O"],
+        },
         # "name": "Emissions from Biomass Burning (Agriculture)",
     },
     "M.3.C.1.LU": {
         "sources": ["3.C.1.a", "3.C.1.d"],
+        "filter": {
+            "entity": ["CO2", "CH4", "N2O"],
+        },
         # "name": "Emissions from Biomass Burning (LULUCF)",
     },
     "M.3.C.AG": {
@@ -499,18 +535,30 @@ aggregate_sectors = {
             "3.C.7",
             "3.C.8",
         ],
+        "filter": {
+            "entity": ["CO2", "CH4", "N2O"],
+        },
         # "name": "Aggregate sources and non-CO2 emissions sources on land (Agriculture)",
     },
     "M.AG.ELV": {
         "sources": ["M.3.C.AG"],
+        "filter": {
+            "entity": ["CO2", "CH4", "N2O"],
+        },
         # "name": "Agriculture excluding livestock emissions",
     },
     "M.AG": {
         "sources": ["M.AG.ELV", "3.A"],
+        "filter": {
+            "entity": ["CO2", "CH4", "N2O"],
+        },
         # "name": "Agriculture"
     },
     "M.LULUCF": {
         "sources": ["M.3.C.1.LU", "3.B", "3.D"],
+        "filter": {
+            "entity": ["CO2", "CH4", "N2O"],
+        },
         # "name": "Land Use, Land Use Change, and Forestry",
     },
     "M.0.EL": {
@@ -523,6 +571,7 @@ aggregate_sectors = {
     },
 }
 
+sectors_to_drop = ["M.4.C.1", "M.4.C.2"]
 
 processing_info_step1 = {
     # aggregate IPPU which is missing for individual fgases so it can be used in the
@@ -536,8 +585,20 @@ processing_info_step1 = {
     "tolerance": 1,  # because ch4 is inconsistent
 }
 
+gas_baskets_step1 = {
+    "KYOTOGHG (AR5GWP100)": [
+        "CO2",
+        "CH4",
+        "N2O",
+        "SF6",
+        "NF3",
+        "HFCS (AR5GWP100)",
+        "PFCS (AR5GWP100)",
+    ],
+}
+
 processing_info_step2 = {
-    "aggregate_cats": aggregate_sectors,
+    "aggregate_coords": {"category": aggregate_sectors},
     "downscale": {
         "sectors": {
             "IPPU": {

+ 7 - 1
src/unfccc_ghg_data/unfccc_reader/Singapore/read_SGP_BUR5_from_pdf.py

@@ -35,6 +35,7 @@ from unfccc_ghg_data.unfccc_reader.Singapore.config_sgp_bur5 import (
     meta_data,
     processing_info_step1,
     processing_info_step2,
+    sectors_to_drop,
     table_def_templates,
     table_defs,
     values_replacement,
@@ -277,11 +278,15 @@ if __name__ == "__main__":
     terminology_proc = coords_terminologies["category"]
 
     # actual processing
+    sectors = data_proc_pm2.coords[f"category ({terminology_proc})"].to_numpy()
+    sectors_to_keep = [sector for sector in sectors if sector not in sectors_to_drop]
+
     data_proc_pm2 = process_data_for_country(
         data_proc_pm2,
         entities_to_ignore=[],
-        gas_baskets={},
+        gas_baskets={},  # gas_baskets_step1,  # build KyotoGHG AR5
         processing_info_country=processing_info_step1,
+        sectors_out=sectors_to_keep,
     )
 
     data_proc_pm2 = process_data_for_country(
@@ -299,6 +304,7 @@ if __name__ == "__main__":
     current_source = data_proc_pm2.coords["source"].to_numpy()[0]
     data_temp = data_proc_pm2.pr.loc[{"source": current_source}]
     data_proc_pm2 = data_proc_pm2.pr.set("source", "BUR_NIR", data_temp)
+    data_proc_pm2 = data_proc_pm2.pr.loc[{"source": ["BUR_NIR"]}]
 
     # ###
     # save data to IF and native format