pypsa-eur/scripts/retrieve_jrc_idees.py

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

47 lines
1.2 KiB
Python
Raw Permalink Normal View History

2024-07-18 13:39:27 +00:00
# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: : 2024- The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Retrieve and extract JRC IDEES 2021 data.
"""
import logging
2024-07-18 13:39:27 +00:00
import os
import zipfile
from pathlib import Path
2024-07-19 08:20:19 +00:00
from _helpers import configure_logging, progress_retrieve, set_scenario_config
2024-07-18 13:39:27 +00:00
logger = logging.getLogger(__name__)
# Define the base URL
url_jrc = "https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/JRC-IDEES/JRC-IDEES-2021_v1/JRC-IDEES-2021.zip"
2024-07-18 13:39:27 +00:00
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
2024-07-18 13:39:27 +00:00
snakemake = mock_snakemake("retrieve_jrc_idees")
rootpath = ".."
else:
rootpath = "."
2024-07-18 13:39:27 +00:00
configure_logging(snakemake)
set_scenario_config(snakemake)
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
2024-07-19 08:20:19 +00:00
to_fn = snakemake.output[0]
to_fn_zp = to_fn + ".zip"
2024-07-19 08:20:19 +00:00
# download .zip file
logger.info(f"Downloading JRC IDEES from {url_jrc}.")
2024-07-19 08:20:19 +00:00
progress_retrieve(url_jrc, to_fn_zp, disable=disable_progress)
2024-07-19 08:20:19 +00:00
# extract
logger.info("Extracting JRC IDEES data.")
with zipfile.ZipFile(to_fn_zp, "r") as zip_ref:
zip_ref.extractall(to_fn)
logger.info(f"JRC IDEES data available in '{to_fn}'.")