{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Weather Data: Renewables.ninja download notebook\n", " \n", "
This Notebook is part of the Weather Data Package of Open Power System Data.\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import shutil\n", "import zipfile\n", "\n", "import pandas as pd\n", "import requests" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dir_shapefiles = './downloads/shapefiles'\n", "dir_countries = './downloads/countries'\n", "dir_nuts = './downloads/nuts'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def save_to_disk(url, path):\n", " response = requests.get(url, stream=True)\n", " \n", " with open(path, 'wb') as f:\n", " shutil.copyfileobj(response.raw, f)\n", "\n", " del response" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for d in [dir_shapefiles, dir_countries, dir_nuts]:\n", " os.makedirs(d, exist_ok=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "base_url = 'https://www.renewables.ninja/country_downloads/'\n", "country_url_template = '{country}/ninja_weather_country_{country}_merra-2_population_weighted.csv'\n", "countries = [\n", " 'BE', 'BG', 'CH', 'CZ', 'DK', 'DE', 'EE', 'IE', 'ES', 'FR',\n", " 'AT', 'HR', 'IT', 'LV', 'LT', 'LU', 'NO', 'HU', 'NL',\n", " 'PL', 'PT', 'RO', 'SI', 'SK', 'FI', 'SE', 'GB', 'GR',\n", "]\n", "\n", "country_urls = [base_url + country_url_template.format(country=i) for i in countries]\n", "\n", "for u in country_urls:\n", " save_to_disk(u, os.path.join(dir_countries, u.split('/')[-1]))\n", "\n", " \n", "# FIXME: wind data not yet in the publicly available files on Renewables.ninja - to be added soon\n", " \n", "# FIXME: NUTS-2 weather not yet in the publicly available files on Renewables.ninja - to be added soon\n", "\n", "# nuts_url_template = '{country}/ninja_weather_{variable}_country_{country}_merra-2_nuts-2_population_weighted.csv'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# NUTS geodata\n", "# http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts\n", "\n", "save_to_disk(\n", " 'http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/download/ref-nuts-2016-20m.shp.zip',\n", " os.path.join(dir_shapefiles, 'ref-nuts-2016-20m.shp.zip')\n", ")\n", "\n", "with zipfile.ZipFile(os.path.join(dir_shapefiles, 'ref-nuts-2016-20m.shp.zip'), 'r') as f:\n", " f.extractall(dir_shapefiles)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }