Преглед на файлове

Fix metadata and terminologies for CRT data

Johannes Gütschow преди 8 месеца
родител
ревизия
1ff17f6032

+ 28 - 6
src/unfccc_ghg_data/unfccc_crf_reader/unfccc_crf_reader_core.py

@@ -37,6 +37,7 @@ def convert_crf_table_to_pm2if(  # noqa: PLR0913
     filter_remove_input: dict[str, dict[str, str | list]] | None = None,
     filter_remove_input: dict[str, dict[str, str | list]] | None = None,
     filter_keep_input: dict[str, dict[str, str | list]] | None = None,
     filter_keep_input: dict[str, dict[str, str | list]] | None = None,
     meta_data_input: dict[str, str] | None = None,
     meta_data_input: dict[str, str] | None = None,
+    type: str = "CRF",
 ) -> pd.DataFrame:
 ) -> pd.DataFrame:
     """
     """
     Convert a given pandas long format crf table to PRIMAP2 interchange format
     Convert a given pandas long format crf table to PRIMAP2 interchange format
@@ -60,6 +61,8 @@ def convert_crf_table_to_pm2if(  # noqa: PLR0913
     meta_data_input: Optional[Dict[str,str]]
     meta_data_input: Optional[Dict[str,str]]
         Meta data information. If values filled by this function automatically
         Meta data information. If values filled by this function automatically
         are given as input the automatic values are overwritten.
         are given as input the automatic values are overwritten.
+    type: str default = "CRF"
+        read CRF or CRF data
 
 
     Returns
     Returns
     -------
     -------
@@ -67,6 +70,10 @@ def convert_crf_table_to_pm2if(  # noqa: PLR0913
         Pandas DataFrame containing the data in PRIMAP2 interchange format
         Pandas DataFrame containing the data in PRIMAP2 interchange format
         Metadata is stored as attrs in the DataFrame
         Metadata is stored as attrs in the DataFrame
     """
     """
+    # check type
+    if type not in ["CRF", "CRT"]:
+        raise ValueError("Type must be CRF or CRT")  # noqa: TRY003
+
     coords_cols = {
     coords_cols = {
         "category": "category",
         "category": "category",
         "entity": "entity",
         "entity": "entity",
@@ -76,21 +83,37 @@ def convert_crf_table_to_pm2if(  # noqa: PLR0913
         "data": "data",
         "data": "data",
     }
     }
 
 
+    # set scenario and terminologies
+    if type == "CRF":
+        category_terminology = f"CRF2013_{submission_year}"
+        class_terminology = "CRF2013"
+        scenario = f"CRF{submission_year}"
+        title = f"Data submitted in {submission_year} to the UNFCCC in the common "
+        "reporting format (CRF)"
+    else:
+        category_terminology = f"CRT{submission_year}"
+        class_terminology = f"CRT{submission_year}"
+        scenario = f"CRT{submission_year}"
+        title = (
+            f"Data submitted in {submission_year} to the UNFCCC using the "
+            f"common reporting tables (CRT)"
+        )
+
     add_coords_cols = {
     add_coords_cols = {
         #    "orig_cat_name": ["orig_cat_name", "category"],
         #    "orig_cat_name": ["orig_cat_name", "category"],
     }
     }
-
+    # TODO: fix this for CRT
     coords_terminologies = {
     coords_terminologies = {
         "area": "ISO3",
         "area": "ISO3",
-        "category": f"CRF2013_{submission_year}",
+        "category": category_terminology,
         "scenario": "PRIMAP",
         "scenario": "PRIMAP",
-        "class": "CRF2013",
+        "class": class_terminology,
     }
     }
 
 
     coords_defaults = {
     coords_defaults = {
         "source": "UNFCCC",
         "source": "UNFCCC",
         "provenance": "measured",
         "provenance": "measured",
-        "scenario": f"CRF{submission_year}",
+        "scenario": scenario,
     }
     }
     if coords_defaults_input is not None:
     if coords_defaults_input is not None:
         for key in coords_defaults_input.keys():
         for key in coords_defaults_input.keys():
@@ -125,8 +148,7 @@ def convert_crf_table_to_pm2if(  # noqa: PLR0913
         f"{submission_year}",
         f"{submission_year}",
         "rights": "",
         "rights": "",
         "contact": "mail@johannes-guetschow.de",
         "contact": "mail@johannes-guetschow.de",
-        "title": f"Data submitted in {submission_year} to the UNFCCC in the common "
-        f"reporting format (CRF)",
+        "title": title,
         "comment": "Read fom xlsx file by Johannes Gütschow",
         "comment": "Read fom xlsx file by Johannes Gütschow",
         "institution": "United Nations Framework Convention on Climate Change "
         "institution": "United Nations Framework Convention on Climate Change "
         "(www.unfccc.int)",
         "(www.unfccc.int)",

+ 1 - 0
src/unfccc_ghg_data/unfccc_crf_reader/unfccc_crf_reader_devel.py

@@ -180,6 +180,7 @@ def read_year_to_test_specs(  # noqa: PLR0912, PLR0915
                             f"Submission date: {submission_date}"
                             f"Submission date: {submission_date}"
                         },
                         },
                         entity_mapping=entity_mapping,
                         entity_mapping=entity_mapping,
+                        type=type,
                     )
                     )
 
 
                     # now convert to native PRIMAP2 format
                     # now convert to native PRIMAP2 format

+ 1 - 0
src/unfccc_ghg_data/unfccc_crf_reader/unfccc_crf_reader_prod.py

@@ -177,6 +177,7 @@ def read_crf_for_country(  # noqa: PLR0912, PLR0915
                     f"Submission date: {submission_date}"
                     f"Submission date: {submission_date}"
                 },
                 },
                 entity_mapping=entity_mapping,
                 entity_mapping=entity_mapping,
+                type=type,
             )
             )
 
 
             # now convert to native PRIMAP2 format
             # now convert to native PRIMAP2 format