2022-09-16 13:04:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-07-26 13:32:48 +00:00
|
|
|
# Copyright 2019-2022 Fabian Hofmann (TUB, FIAS)
|
2023-02-16 10:50:55 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
|
2020-05-29 07:50:55 +00:00
|
|
|
#
|
2021-09-14 14:37:41 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
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.
|
|
|
|
|
2022-06-30 07:01:49 +00:00
|
|
|
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 (188 MB)
|
2019-11-06 13:50:59 +00:00
|
|
|
|
|
|
|
.. 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::
|
2023-04-21 08:41:44 +00:00
|
|
|
Documentation of the configuration file ``config/config.yaml`` at
|
2019-11-06 13:50:59 +00:00
|
|
|
:ref:`toplevel_cf`
|
|
|
|
|
|
|
|
**Outputs**
|
|
|
|
|
2022-07-04 09:49:55 +00:00
|
|
|
- ``data/bundle``: input data collected from various sources
|
2019-11-06 13:50:59 +00:00
|
|
|
|
|
|
|
"""
|
2019-11-05 11:53:21 +00:00
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
import logging
|
|
|
|
import tarfile
|
2020-12-03 18:50:53 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
from _helpers import configure_logging, progress_retrieve
|
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2019-11-05 11:53:21 +00:00
|
|
|
|
2019-11-06 13:50:59 +00:00
|
|
|
if __name__ == "__main__":
|
2022-09-16 13:04:04 +00:00
|
|
|
if "snakemake" not in globals():
|
2019-12-09 20:29:15 +00:00
|
|
|
from _helpers import mock_snakemake
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
snakemake = mock_snakemake("retrieve_databundle")
|
|
|
|
rootpath = ".."
|
2019-12-09 20:29:15 +00:00
|
|
|
else:
|
2022-09-16 13:04:04 +00:00
|
|
|
rootpath = "."
|
|
|
|
configure_logging(
|
|
|
|
snakemake
|
|
|
|
) # TODO Make logging compatible with progressbar (see PR #102)
|
2019-11-28 07:22:52 +00:00
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
if snakemake.config["tutorial"]:
|
2019-11-06 13:50:59 +00:00
|
|
|
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-12-09 20:29:15 +00:00
|
|
|
tarball_fn = Path(f"{rootpath}/bundle.tar.xz")
|
2023-05-12 11:59:41 +00:00
|
|
|
to_fn = Path(rootpath) / Path(snakemake.output[0]).parent.parent
|
2019-11-05 11:53:21 +00:00
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
logger.info(f"Downloading databundle from '{url}'.")
|
2023-03-07 19:37:47 +00:00
|
|
|
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
|
|
|
|
progress_retrieve(url, tarball_fn, disable=disable_progress)
|
2019-11-05 11:53:21 +00:00
|
|
|
|
2023-03-07 16:21:00 +00:00
|
|
|
logger.info("Extracting databundle.")
|
2019-11-28 07:22:52 +00:00
|
|
|
tarfile.open(tarball_fn).extractall(to_fn)
|
2019-12-09 20:29:15 +00:00
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
tarball_fn.unlink()
|
2019-12-09 20:29:15 +00:00
|
|
|
|
|
|
|
logger.info(f"Databundle available in '{to_fn}'.")
|