2022-09-16 13:04:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-04-15 12:48:34 +00:00
|
|
|
# Copyright 2019-2024 Fabian Hofmann (TUB, FIAS), Fabian Neumann (TUB)
|
2024-02-19 15:21:48 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2024 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
|
|
|
"""
|
2024-09-13 09:09:27 +00:00
|
|
|
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.3517934.svg
|
|
|
|
:target: https://doi.org/10.5281/zenodo.3517934
|
2019-11-06 13:50:59 +00:00
|
|
|
|
2024-04-15 12:48:34 +00:00
|
|
|
The data bundle 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 population
|
|
|
|
data on NUTS3 levels and energy balances.
|
2019-11-06 13:50:59 +00:00
|
|
|
|
2024-04-15 12:48:34 +00:00
|
|
|
This rule downloads the data bundle from `zenodo
|
2024-09-13 09:09:27 +00:00
|
|
|
<https://doi.org/10.5281/zenodo.3517934>`_ and extracts it in the ``data``
|
2024-04-15 12:48:34 +00:00
|
|
|
sub-directory, such that all files of the bundle are stored in the
|
|
|
|
``data/bundle`` subdirectory.
|
2019-11-06 13:50:59 +00:00
|
|
|
|
|
|
|
**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
|
|
|
|
|
2024-02-12 10:53:20 +00:00
|
|
|
from _helpers import (
|
|
|
|
configure_logging,
|
|
|
|
progress_retrieve,
|
|
|
|
set_scenario_config,
|
|
|
|
validate_checksum,
|
2024-02-12 10:54:13 +00:00
|
|
|
)
|
2022-09-16 13:04:04 +00:00
|
|
|
|
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__":
|
2019-12-09 20:29:15 +00:00
|
|
|
if "snakemake" not in globals():
|
|
|
|
from _helpers import mock_snakemake
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2019-12-09 20:29:15 +00:00
|
|
|
snakemake = mock_snakemake("retrieve_databundle")
|
|
|
|
rootpath = ".."
|
|
|
|
else:
|
|
|
|
rootpath = "."
|
2024-02-12 10:53:20 +00:00
|
|
|
configure_logging(snakemake)
|
|
|
|
set_scenario_config(snakemake)
|
2019-11-28 07:22:52 +00:00
|
|
|
|
2024-09-13 09:09:27 +00:00
|
|
|
url = "https://zenodo.org/records/13757228/files/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-05-17 16:43:30 +00:00
|
|
|
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
|
2023-03-07 19:37:47 +00:00
|
|
|
progress_retrieve(url, tarball_fn, disable=disable_progress)
|
2019-11-05 11:53:21 +00:00
|
|
|
|
2023-12-29 11:34:14 +00:00
|
|
|
validate_checksum(tarball_fn, url)
|
|
|
|
|
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
|
|
|
|
2024-04-15 12:48:34 +00:00
|
|
|
logger.info("Unlinking tarball.")
|
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}'.")
|