pypsa-eur/scripts/retrieve_sector_databundle.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2023-03-06 17:49:23 +00:00
# SPDX-FileCopyrightText: : 2021-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
2023-03-09 11:45:43 +00:00
Retrieve and extract data bundle for sector-coupled studies.
"""
import logging
logger = logging.getLogger(__name__)
import tarfile
from pathlib import Path
2023-08-15 13:02:41 +00:00
from _helpers import configure_logging, progress_retrieve, set_scenario_config
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake("retrieve_databundle")
rootpath = ".."
else:
rootpath = "."
configure_logging(snakemake)
2023-08-15 13:02:41 +00:00
set_scenario_config(snakemake)
2022-01-06 09:29:59 +00:00
url = "https://zenodo.org/record/5824485/files/pypsa-eur-sec-data-bundle.tar.gz"
tarball_fn = Path(f"{rootpath}/sector-bundle.tar.gz")
to_fn = Path(rootpath) / Path(snakemake.output[0]).parent.parent
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)
2023-03-07 16:21:00 +00:00
logger.info("Extracting databundle.")
tarfile.open(tarball_fn).extractall(to_fn)
tarball_fn.unlink()
logger.info(f"Databundle available in '{to_fn}'.")