Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retrieve*: handle extraction path via snakemake.output #666

Merged
merged 4 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions scripts/retrieve_databundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
else:
url = "https://zenodo.org/record/3517935/files/pypsa-eur-data-bundle.tar.xz"

# Save locations
tarball_fn = Path(f"{rootpath}/bundle.tar.xz")
to_fn = Path(f"{rootpath}/data")
to_fn = Path(rootpath) / Path(snakemake.output[0]).parent.parent

logger.info(f"Downloading databundle from '{url}'.")
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
Expand Down
2 changes: 1 addition & 1 deletion scripts/retrieve_gas_infrastructure_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Save locations
zip_fn = Path(f"{rootpath}/IGGIELGN.zip")
to_fn = Path(f"{rootpath}/data/gas_network/scigrid-gas")
to_fn = Path(rootpath) / Path(snakemake.output[0]).parent.parent

logger.info(f"Downloading databundle from '{url}'.")
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
Expand Down
16 changes: 9 additions & 7 deletions scripts/retrieve_sector_databundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@

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__":
if "snakemake" not in globals():
from _helpers import mock_snakemake

snakemake = mock_snakemake("retrieve_databundle")
rootpath = ".."
else:
rootpath = "."
configure_logging(snakemake)

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")
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}'.")
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
Expand Down