pypsa-eur/scripts/retrieve_sector_databundle.py

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

40 lines
943 B
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
"""
Retrieve and extract sector data bundle.
"""
import logging
logger = logging.getLogger(__name__)
import os
import sys
import tarfile
from pathlib import Path
# Add pypsa-eur scripts to path for import of _helpers
sys.path.insert(0, os.getcwd() + "/../pypsa-eur/scripts")
from _helpers import configure_logging, progress_retrieve
if __name__ == "__main__":
configure_logging(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("sector-bundle.tar.gz")
to_fn = Path("data")
logger.info(f"Downloading databundle from '{url}'.")
progress_retrieve(url, tarball_fn)
logger.info(f"Extracting databundle.")
tarfile.open(tarball_fn).extractall(to_fn)
tarball_fn.unlink()
logger.info(f"Databundle available in '{to_fn}'.")