From d348544609bd541a40dd6a1404f782570cba9a04 Mon Sep 17 00:00:00 2001 From: David Almeida <58078834+dc-almeida@users.noreply.github.com> Date: Thu, 3 Oct 2024 09:39:44 +0200 Subject: [PATCH] Update countries attributes (#57) * Update countries attributes * Fix square bracket * Fix square brackets * Correct India and Japan * Update copyright * Bump nomenclature requirement version * Add Ruff * Add closing empty line --- .github/workflows/ruff.yml | 8 ++++ README.md | 3 +- attachments/variable_mapping.ipynb | 2 +- db-admin/db-docs.ipynb | 6 +-- db-admin/db-setup.ipynb | 10 ++--- definitions/region/regions.yaml | 62 +++++++++++++++--------------- requirements.txt | 3 +- workflow.py | 8 +++- 8 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/ruff.yml diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000..ef06d34 --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,8 @@ +name: Ruff +on: [ push, pull_request ] +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 diff --git a/README.md b/README.md index 7072d72..f94cc7a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # ADIADNE project - scenario processing workflow +Copyright (c) 2021-2024 IIASA and the ARIADNE consortium -Copyright (c) 2021 IIASA and the ARIADNE consortium +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) This repository is released under the [APACHE 2.0 license](LICENSE). ![GitHub](https://img.shields.io/github/license/iiasa/ariadne-intern-workflow) diff --git a/attachments/variable_mapping.ipynb b/attachments/variable_mapping.ipynb index 05c833f..976a052 100644 --- a/attachments/variable_mapping.ipynb +++ b/attachments/variable_mapping.ipynb @@ -36,7 +36,7 @@ "outputs": [], "source": [ "nomenclature.create_yaml_from_xlsx(\n", - " source=file, \n", + " source=file,\n", " target=definition_path / \"variable\" / \"variables.yaml\",\n", " sheet_name=\"variable_definitions\",\n", " col=\"Variable\",\n", diff --git a/db-admin/db-docs.ipynb b/db-admin/db-docs.ipynb index 144c6b9..bd45611 100644 --- a/db-admin/db-docs.ipynb +++ b/db-admin/db-docs.ipynb @@ -20,10 +20,8 @@ "metadata": {}, "outputs": [], "source": [ - "import yaml\n", "import pandas as pd\n", - "import ixmp\n", - "import pyam" + "import ixmp" ] }, { @@ -32,7 +30,7 @@ "metadata": {}, "outputs": [], "source": [ - "#mp = ixmp.Platform('ariadne-intern')\n", + "# mp = ixmp.Platform('ariadne-intern')\n", "mp = ixmp.Platform(\"ariadne\")" ] }, diff --git a/db-admin/db-setup.ipynb b/db-admin/db-setup.ipynb index ce566f0..99fa2c4 100644 --- a/db-admin/db-setup.ipynb +++ b/db-admin/db-setup.ipynb @@ -21,9 +21,7 @@ "outputs": [], "source": [ "import yaml\n", - "import pandas as pd\n", - "import ixmp\n", - "import pyam" + "import ixmp" ] }, { @@ -32,7 +30,7 @@ "metadata": {}, "outputs": [], "source": [ - "mp = ixmp.Platform('ariadne-intern')" + "mp = ixmp.Platform(\"ariadne-intern\")" ] }, { @@ -48,7 +46,7 @@ "metadata": {}, "outputs": [], "source": [ - "with open('../regions.yaml', 'r', encoding='utf-8') as stream:\n", + "with open(\"../regions.yaml\", \"r\", encoding=\"utf-8\") as stream:\n", " region_dict = yaml.load(stream, Loader=yaml.FullLoader)" ] }, @@ -61,7 +59,7 @@ "for category, items in region_dict.items():\n", " for name, attributes in items.items():\n", " mp.add_region(name, hierarchy=category)\n", - " for a in ['iso3', 'abbr']:\n", + " for a in [\"iso3\", \"abbr\"]:\n", " if attributes is not None and a in attributes:\n", " mp.add_region_synonym(attributes[a], mapped_to=name)" ] diff --git a/definitions/region/regions.yaml b/definitions/region/regions.yaml index 07b2705..7cbe13a 100644 --- a/definitions/region/regions.yaml +++ b/definitions/region/regions.yaml @@ -9,63 +9,63 @@ - Europäische Länder: - Bulgarien: - iso3: BGR + countries: [ Bulgaria ] - Dänemark: - iso3: DNK + countries: [ Denmark ] - Deutschland: - iso3: DEU + countries: [ Germany ] - Estland: - iso3: EST + countries: [ Estonia ] - Finnland: - iso3: FIN + countries: [ Finland ] - Frankreich: - iso3: FRA + countries: [ France ] - Griechenland: - iso3: GRC + countries: [ Greece ] - Irland: - iso3: IRL + countries: [ Ireland ] - Italien: - iso3: ITA + countries: [ Italy ] - Kroatien: - iso3: HRV + countries: [ Croatia ] - Lettland: - iso3: LVA + countries: [ Latvia ] - Litauen: - iso3: LTU + countries: [ Lithuania ] - Luxemburg: - iso3: LUX + countries: [ Luxembourg ] - Malta: - iso3: MLT + countries: [ Malta ] - Niederlande: - iso3: NLD + countries: [ Netherlands ] - Österreich: - iso3: AUT + countries: [ Austria ] - Polen: - iso3: POL + countries: [ Poland ] - Portugal: - iso3: PRT + countries: [ Portugal ] - Rumänien: - iso3: ROU + countries: [ Romania ] - Schweden: - iso3: SWE + countries: [ Sweden ] - Slowakei: - iso3: SVK + countries: [ Slovakia ] - Slowenien: - iso3: SVN + countries: [ Slovenia ] - Spanien: - iso3: ESP + countries: [ Spain ] - Tschechien: - iso3: CZE + countries: [ Czechia ] - Ungarn: - iso3: HUN + countries: [ Hungary ] - Zypern: - iso3: CYP + countries: [ Cyprus ] - Vereinigtes Königreich: - iso3: GBR + countries: [ United Kingdom ] - Norwegen: - iso3: NOR + countries: [ Norway ] - Schweiz: - iso3: CHE + countries: [ Switzerland ] - Europäische Regionen: - EU_East: definition: Polen, Tschechien, Slowakei, Estland, Lettland, Litauen @@ -105,9 +105,9 @@ - China (inkl. Hongkong, Macao, Taiwan): abbr: CHN_HKG_MAC_TWN - Indien: - iso3: IND + countries: [ India ] - Japan: - iso3: JPN + countries: [ Japan ] - USA - Regionen außerhalb Europas: - CAN_NZL_AUS: diff --git a/requirements.txt b/requirements.txt index b996262..28c9cfc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -pyam-iamc>=1.0 # the pyam package is released on pypi.org under this name -nomenclature-iamc >= 0.18.1 +nomenclature-iamc >= 0.19.0 # use the latest release on PyPI diff --git a/workflow.py b/workflow.py index ab5eaf9..68e2b24 100644 --- a/workflow.py +++ b/workflow.py @@ -15,7 +15,11 @@ # datetime must be in Central European Time (CET) EXP_TZ = "UTC+01:00" EXP_TIME_OFFSET = timedelta(seconds=3600) -OE_SUBANNUAL_FORMAT = lambda x: x.strftime("%m-%d %H:%M%z").replace("+0100", "+01:00") + + +def oe_subannual_format(x): + return x.strftime("%m-%d %H:%M%z").replace("+0100", "+01:00") + # allowed values for required meta columns, use first of list as default REQUIRED_META_ARIADNE = { @@ -98,7 +102,7 @@ def _validate(df: pyam.IamDataFrame) -> pyam.IamDataFrame: # convert to subannual format if data provided in datetime format if df.time_col == "time": logger.info('Re-casting from "time" column to categorical "subannual" format') - df = df.swap_time_for_year(subannual=OE_SUBANNUAL_FORMAT) + df = df.swap_time_for_year(subannual=oe_subannual_format) # check that any datetime-like items in "subannual" are valid datetime and UTC+01:00 if "subannual" in df.dimensions: