2023-03-08 18:22:00 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2023 The PyPSA-Eur Authors
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2024-01-04 12:37:35 +00:00
|
|
|
import os, sys, glob
|
|
|
|
|
2024-01-04 19:18:07 +00:00
|
|
|
helper_source_path = [match for match in glob.glob("**/_helpers.py", recursive=True)]
|
2024-01-04 12:37:35 +00:00
|
|
|
|
|
|
|
for path in helper_source_path:
|
|
|
|
path = os.path.dirname(os.path.abspath(path))
|
|
|
|
sys.path.insert(0, os.path.abspath(path))
|
2023-12-29 11:38:41 +00:00
|
|
|
|
2023-12-29 11:34:14 +00:00
|
|
|
from _helpers import validate_checksum
|
2023-03-08 18:22:29 +00:00
|
|
|
|
2023-12-29 11:38:41 +00:00
|
|
|
|
2023-03-08 18:22:00 +00:00
|
|
|
def memory(w):
|
|
|
|
factor = 3.0
|
|
|
|
for o in w.opts.split("-"):
|
|
|
|
m = re.match(r"^(\d+)h$", o, re.IGNORECASE)
|
|
|
|
if m is not None:
|
|
|
|
factor /= int(m.group(1))
|
|
|
|
break
|
|
|
|
for o in w.opts.split("-"):
|
|
|
|
m = re.match(r"^(\d+)seg$", o, re.IGNORECASE)
|
|
|
|
if m is not None:
|
|
|
|
factor *= int(m.group(1)) / 8760
|
|
|
|
break
|
2023-04-27 08:10:30 +00:00
|
|
|
if w.clusters.endswith("m") or w.clusters.endswith("c"):
|
2023-07-06 17:14:01 +00:00
|
|
|
return int(factor * (55000 + 600 * int(w.clusters[:-1])))
|
2023-03-08 18:22:00 +00:00
|
|
|
elif w.clusters == "all":
|
|
|
|
return int(factor * (18000 + 180 * 4000))
|
|
|
|
else:
|
|
|
|
return int(factor * (10000 + 195 * int(w.clusters)))
|
|
|
|
|
|
|
|
|
2024-01-04 08:00:31 +00:00
|
|
|
def input_custom_extra_functionality(w):
|
|
|
|
path = config["solving"]["options"].get("custom_extra_functionality", False)
|
|
|
|
if path:
|
|
|
|
return workflow.source_path(path)
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2023-07-13 06:22:22 +00:00
|
|
|
# Check if the workflow has access to the internet by trying to access the HEAD of specified url
|
|
|
|
def has_internet_access(url="www.zenodo.org") -> bool:
|
|
|
|
import http.client as http_client
|
|
|
|
|
|
|
|
# based on answer and comments from
|
|
|
|
# https://stackoverflow.com/a/29854274/11318472
|
|
|
|
conn = http_client.HTTPConnection(url, timeout=5) # need access to zenodo anyway
|
|
|
|
try:
|
|
|
|
conn.request("HEAD", "/")
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
finally:
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
|
2023-03-08 18:22:00 +00:00
|
|
|
def input_eurostat(w):
|
|
|
|
# 2016 includes BA, 2017 does not
|
|
|
|
report_year = config["energy"]["eurostat_report_year"]
|
2023-08-24 09:11:33 +00:00
|
|
|
return f"data/bundle-sector/eurostat-energy_balances-june_{report_year}_edition"
|
2023-03-08 18:22:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def solved_previous_horizon(wildcards):
|
|
|
|
planning_horizons = config["scenario"]["planning_horizons"]
|
|
|
|
i = planning_horizons.index(int(wildcards.planning_horizons))
|
|
|
|
planning_horizon_p = str(planning_horizons[i - 1])
|
|
|
|
return (
|
|
|
|
RESULTS
|
|
|
|
+ "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_"
|
|
|
|
+ planning_horizon_p
|
|
|
|
+ ".nc"
|
2023-03-08 18:22:29 +00:00
|
|
|
)
|