Weather Data: Renewables.ninja download notebook
This Notebook is part of the Weather Data Package of Open Power System Data.
In [ ]:
import os
import shutil
import zipfile

import pandas as pd
import requests
In [ ]:
dir_shapefiles = './downloads/shapefiles'
dir_countries = './downloads/countries'
dir_nuts = './downloads/nuts'

In [ ]:
def save_to_disk(url, path):
    response = requests.get(url, stream=True)
    
    with open(path, 'wb') as f:
        shutil.copyfileobj(response.raw, f)

    del response
In [ ]:
for d in [dir_shapefiles, dir_countries, dir_nuts]:
    os.makedirs(d, exist_ok=True)
In [ ]:
base_url = 'https://www.renewables.ninja/country_downloads/'
country_url_template = '{country}/ninja_weather_country_{country}_merra-2_population_weighted.csv'
countries = [
    'BE', 'BG', 'CH', 'CZ', 'DK', 'DE', 'EE', 'IE', 'ES', 'FR',
    'AT', 'HR', 'IT', 'LV', 'LT', 'LU', 'NO', 'HU', 'NL',
    'PL', 'PT', 'RO', 'SI', 'SK', 'FI', 'SE', 'GB', 'GR',
]

country_urls = [base_url + country_url_template.format(country=i) for i in countries]

for u in country_urls:
    save_to_disk(u, os.path.join(dir_countries, u.split('/')[-1]))

    
# FIXME: wind data not yet in the publicly available files on Renewables.ninja - to be added soon
    
# FIXME: NUTS-2 weather not yet in the publicly available files on Renewables.ninja - to be added soon

# nuts_url_template = '{country}/ninja_weather_{variable}_country_{country}_merra-2_nuts-2_population_weighted.csv'
In [ ]:
# NUTS geodata
# http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts

save_to_disk(
    'http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/download/ref-nuts-2016-20m.shp.zip',
    os.path.join(dir_shapefiles, 'ref-nuts-2016-20m.shp.zip')
)

with zipfile.ZipFile(os.path.join(dir_shapefiles, 'ref-nuts-2016-20m.shp.zip'), 'r') as f:
    f.extractall(dir_shapefiles)