PyPSA / PyPSA/pypsa-eur

Use `country_codes` to make country mapping less hard-coded

Open
#588 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
615
Forks
459
Avg merge
4d 14h
Merged PRs (30d)
6

Description

First step is to write a conversion function for the different datasets:

import pandas as pd
import country_converter as coco

def country_converter():
    """
    Returns a patched CountryConverter() object
    with conversion options for the country codes
    in the following datasets:
    
    - eurostat energy balances
    - UNFCCC emissions database
    - JRC IDEES database
    """
    
    cc = coco.CountryConverter()

    # patch The Netherlands for hotmaps database
    idx = (cc.data.name_short == 'Netherlands').idxmax()
    cc.data.at[idx, "regex"] = cc.data.at[idx, 'regex'][:-1]

    # eurostat country codes from ISO2
    to_replace = {
        'MT': 'MA',
        'TR': 'TU',
        'XK': 'KO',
        'MD': 'MO',
        'UA': 'UK'
    }
    cc.data['eurostat'] = cc.data.ISO2.replace(to_replace)

    # JRC IDEES country codes from ISO2
    to_replace = {
        'GB': 'UK',
        'GR': 'EL'
    }
    cc.data['idees'] = cc.data.ISO2.replace(to_replace)

    # UNFCCC country codes from ISO2
    to_replace = {
        'GB': 'UK',
    }
    cc.data['unfccc'] = cc.data.ISO2.replace(to_replace)

    return coco.CountryConverter(cc.data)

Example use:

cc = country_converter()

rename = {
    "Austriae" : "AT",
    "Bulgaria" : "BG",
    "Belgiume" : "BE",
    "Czechia" : "CZ",
    "Germany" : "DE",
    "Greece" : "GR",
    "United Kingdom" : "GB",
}

cc.convert(rename.keys(), to='eurostat')

cc.EU28as('ISO2').ISO2.values

cc.EEAas('idees').idees.values

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named in the issue. Start by locating the existing country-mapping code and the entry points for the Eurostat energy balances, UNFCCC emissions database, and JRC IDEES data. Done means a reusable CountryConverter setup handles the listed dataset-specific codes and supports the shown conversion examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.