pypsa-eur/scripts/retrieve_databundle.py

50 lines
1.7 KiB
Python
Raw Normal View History

2019-11-06 11:04:01 +00:00
## Copyright 2019 Fabian Hofmann (FIAS)
2019-11-06 13:50:59 +00:00
"""
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.3517935.svg
:target: https://doi.org/10.5281/zenodo.3517935
The data bundle (1.4 GB) contains common GIS datasets like NUTS3 shapes, EEZ shapes, CORINE Landcover, Natura 2000 and also electricity specific summary statistics like historic per country yearly totals of hydro generation, GDP and POP on NUTS3 levels and per-country load time-series.
This rule downloads the data bundle from `zenodo <https://doi.org/10.5281/zenodo.3517935>`_ and extracts it in the ``data`` sub-directory, such that all files of the bundle are stored in the ``data/bundle`` subdirectory.
The :ref:`tutorial` uses a smaller `data bundle <https://zenodo.org/record/3517921/files/pypsa-eur-tutorial-data-bundle.tar.xz>`_ than required for the full model (19 MB)
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.3517921.svg
:target: https://doi.org/10.5281/zenodo.3517921
**Relevant Settings**
.. code:: yaml
tutorial:
.. seealso::
Documentation of the configuration file ``config.yaml`` at
:ref:`toplevel_cf`
**Outputs**
- ``cutouts/bundle``: input data collected from various sources
"""
2019-11-05 11:53:21 +00:00
import logging, os, tarfile
from _helpers import progress_retrieve
logger = logging.getLogger(__name__)
2019-11-06 13:50:59 +00:00
if __name__ == "__main__":
if snakemake.config['tutorial']:
url = "https://zenodo.org/record/3517921/files/pypsa-eur-tutorial-data-bundle.tar.xz"
else:
url = "https://zenodo.org/record/3517935/files/pypsa-eur-data-bundle.tar.xz"
2019-11-05 11:53:21 +00:00
2019-11-06 13:50:59 +00:00
tarball_fn = "./bundle.tar.xz"
2019-11-05 11:53:21 +00:00
2019-11-06 13:50:59 +00:00
progress_retrieve(url, tarball_fn)
2019-11-05 11:53:21 +00:00
2019-11-06 13:50:59 +00:00
tarfile.open(tarball_fn).extractall('./data')
2019-11-05 11:53:21 +00:00
2019-11-06 13:50:59 +00:00
os.remove(tarball_fn)