Browse Source

first sector table

Daniel Busch 8 months ago
parent
commit
772e3e3296

+ 30 - 0
src/unfccc_ghg_data/unfccc_reader/Saint_Kitts_and_Nevis/__init__.py

@@ -0,0 +1,30 @@
+"""Saint Kitts and Nevis' BURs, NIRs, NCs
+
+Scripts and configurations to read Argentina's submissions to the UNFCCC.
+Currently, the following submissions and datasets are available (all datasets
+including DI (red using the DI-reader) and legacy BUR/NIR (no code)):
+
+.. exec_code::
+    :hide_code:
+
+    from unfccc_ghg_data.helper.functions import (get_country_datasets,
+                                                  get_country_submissions)
+    country = 'KNA'
+    # print available submissions
+    print("="*15 + " Available submissions " + "="*15)
+    get_country_submissions(country, True)
+    print("")
+
+    #print available datasets
+    print("="*15 + " Available datasets " + "="*15)
+    get_country_datasets(country, True)
+
+You can also obtain this information running
+
+.. code-block:: bash
+
+    poetry run doit country_info country=KNA
+
+See below for a listing of scripts for BUR/NIR reading including links.
+
+"""

+ 14 - 0
src/unfccc_ghg_data/unfccc_reader/Saint_Kitts_and_Nevis/config_kna_bur1.py

@@ -0,0 +1,14 @@
+"""
+Configuration file to read Saint Kitts and Nevis' BUR 1.
+"""
+
+conf = {
+    "energy": {
+        "page_defs": {
+            "149": {"skip_rows_start": 0},
+            "150": {"skip_rows_start": 0},
+            "151": {"skip_rows_start": 0},
+            "152": {"skip_rows_start": 0},
+        }
+    }
+}

+ 59 - 0
src/unfccc_ghg_data/unfccc_reader/Saint_Kitts_and_Nevis/read_KNA_BUR1_from_pdf.py

@@ -0,0 +1,59 @@
+"""
+Read Saint Kitts and Nevis' BUR1 from pdf
+"""
+import camelot
+import pandas as pd
+
+from unfccc_ghg_data.helper import downloaded_data_path, extracted_data_path
+from unfccc_ghg_data.unfccc_reader.Saint_Kitts_and_Nevis.config_kna_bur1 import conf
+
+if __name__ == "__main__":
+    # ###
+    # configuration
+    # ###
+
+    input_folder = downloaded_data_path / "UNFCCC" / "Saint_Kitts_and_Nevis" / "BUR1"
+    output_folder = extracted_data_path / "UNFCCC" / "Saint_Kitts_and_Nevis"
+    if not output_folder.exists():
+        output_folder.mkdir()
+
+    pdf_file = "First_BUR_St.Kitts_Nevis.pdf"
+    output_filename = "KNA_BUR1_2023_"
+    compression = dict(zlib=True, complevel=9)
+
+    def repl(m):  # noqa: D103
+        return m.group("code")
+
+    # ###
+    # 1. Read in main tables
+    # ###
+
+    df_main = None
+    for sector in conf.keys():
+        print("-" * 45)
+        print(f"Reading table for {sector}.")
+
+        df_sector = None
+        for page in conf[sector]["page_defs"].keys():
+            tables_inventory_original = camelot.read_pdf(
+                str(input_folder / pdf_file),
+                pages=page,
+                flavor="lattice",
+                # split_text=True,
+            )
+
+            df_page = tables_inventory_original[0].df
+
+            if df_sector is None:
+                df_sector = df_page
+            else:
+                df_sector = pd.concat(
+                    [
+                        df_sector,
+                        df_page,
+                    ],
+                    axis=0,
+                    join="outer",
+                ).reset_index(drop=True)
+
+        pass