def _fix_country_feature(feature):
    # * IDs should have three letters instead of two
    # * many country names are broken or missing
    feature["properties"]["id"] = utils.eu_country_code_to_iso3(
        feature["properties"]["id"])
    feature["properties"]["name"] = pycountry.countries.lookup(
        feature["properties"]["id"]).name
    return feature
Beispiel #2
0
def _split_links_in_index(df):
    # Index is LOC[1]-LOC[2], where LOC is is power market
    # (usually a country, but sometimes a subnational group, e.g. 6 in Italy).
    # Here we aggregate to national-level
    df.index = df.index.str.split("-", expand=True)
    df = (df.rename(index=lambda x: utils.eu_country_code_to_iso3(x[:2])).
          loc[:, "Value"].groupby(level=[0, 1]).sum().rename_axis(
              index=["loc_from", "loc_to"]))

    # Remove internal transmission for countries with several markets
    return df[df.index.get_level_values(0) != df.index.get_level_values(1)]
def _in_study_area(study_area, all_countries, feature):
    countries = [
        pycountry.countries.lookup(country) for country in all_countries
    ]
    unit = shapely.geometry.shape(feature["geometry"])
    country = pycountry.countries.lookup(
        utils.eu_country_code_to_iso3(feature["properties"]["NUTS_ID"][:2]))
    if (country in countries) and (study_area.contains(unit)
                                   or study_area.intersects(unit)):
        return True
    else:
        print("Removing {} as it is outside of study area.".format(
            feature["properties"]["NUTS_ID"]))
        return False
def _layer_features(nuts_file, crs, study_area, all_countries, layer_id):
    for feature in filter(
            _in_layer_and_in_study_area(layer_id, study_area, all_countries),
            nuts_file):
        new_feature = {}
        new_feature["properties"] = {}
        new_feature["properties"][
            "country_code"] = utils.eu_country_code_to_iso3(
                feature["properties"]["NUTS_ID"][:2])
        new_feature["properties"]["id"] = feature["properties"]["NUTS_ID"]
        new_feature["properties"]["name"] = feature["properties"]["NAME_LATN"]
        new_feature["properties"][
            "type"] = "country" if layer_id == 0 else None
        new_feature["properties"]["proper"] = True
        new_feature["geometry"] = _all_parts_in_study_area_and_crs(
            feature, nuts_file.crs, crs, study_area)
        if layer_id == 0:
            new_feature = _fix_country_feature(new_feature)
        yield new_feature
Beispiel #5
0
def test_country_code_conversion(eu_country_code, iso3166):
    assert eu_country_code_to_iso3(eu_country_code) == iso3166