Ver Fonte

fix for China BUR3 and NC4, add timeseries move functionality to processing function

Johannes Gütschow há 4 meses atrás
pai
commit
566567af0d

+ 16 - 0
src/unfccc_ghg_data/helper/functions.py

@@ -182,6 +182,22 @@ def process_data_for_country(  # noqa PLR0913, PLR0912, PLR0915
                 time=processing_info_country["remove_years"]
             )
 
+        # move timeseries if desired
+        if "move_ts" in processing_info_country:
+            for case in processing_info_country["move_ts"]:
+                move_info = copy.deepcopy(processing_info_country["move_ts"][case])
+                entities = move_info["entities"]
+                dim = move_info["dim"]
+                sel = move_info["sel"].copy()
+                sel.update({dim: move_info["from"]})
+                to_val = move_info["to"]
+                for entity in entities:
+                    ts_to_move = data_country[entity].pr.loc[sel]
+                    data_country[entity] = data_country[entity].pr.set(
+                        dim, to_val, ts_to_move
+                    )
+                    data_country[entity].pr.loc[sel] *= np.nan
+
         # subtract categories
         if "subtract_cats" in processing_info_country:
             subtract_cats_current = processing_info_country["subtract_cats"]

+ 7 - 7
src/unfccc_ghg_data/unfccc_reader/China/config_chn_bur3_nc4.py

@@ -347,37 +347,37 @@ category_conversion = {
             "3.B.1": {
                 "sources": ["3.B.1.a"],
                 "filter": {
-                    "entity": ["CO2"],
+                    "entity": ["CO2", "CH4", "N2O"],
                 },
             },
             "3.C.1": {
                 "sources": ["3.C.1.b", "3.C.1.c"],
                 "filter": {
-                    "entity": ["CH4"],
+                    "entity": ["CH4", "N2O"],
                 },
             },
             "M.3.C.1.AG": {
                 "sources": ["3.C.1.c"],
                 "filter": {
-                    "entity": ["CH4"],
+                    "entity": ["CH4", "N2O"],
                 },
             },
             "M.3.C.AG": {
                 "sources": ["M.3.C.1.AG", "M.3.C.45.AG", "3.C.7"],
                 "filter": {
-                    "entity": ["CH4"],
+                    "entity": ["CH4", "N2O"],
                 },
             },
             "3.C": {
                 "sources": ["M.3.C.AG"],
                 "filter": {
-                    "entity": ["CH4"],
+                    "entity": ["CH4", "N2O"],
                 },
             },
             "M.AG.ELV": {
                 "sources": ["M.3.C.AG"],
                 "filter": {
-                    "entity": ["CH4"],
+                    "entity": ["CH4", "N2O"],
                 },
             },
             "M.AG": {  # check consistency (not consistent in table)
@@ -737,7 +737,7 @@ config_bur3 = {
                 "source_GWP": gwp_to_use,
             },
         },
-        "CHN": {  # TODO: doesn't work for NC4. Change config
+        "CHN": {
             "basket_copy": {  # needed for 2005
                 "GWPs_to_add": ["AR4GWP100", "AR5GWP100", "AR6GWP100"],
                 "entities": ["HFCS", "PFCS"],