From 95853bb59d492cba345d9faeda902949c4c2a48a Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Sat, 17 Feb 2024 18:27:59 +0100 Subject: [PATCH] _helpers: allow specifying dedicated shared_resources folder --- doc/configtables/run.csv | 2 +- scripts/_helpers.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/configtables/run.csv b/doc/configtables/run.csv index e2a81e0b..f619d8bf 100644 --- a/doc/configtables/run.csv +++ b/doc/configtables/run.csv @@ -4,5 +4,5 @@ scenarios,,, -- enable,bool,"{true, false}","Switch to select whether workflow should generate scenarios based on ``file``." -- file,str,,"Path to the scenario yaml file. The scenario file contains config overrides for each scenario. In order to be taken account, ``run: scenarios`` has to be set to ``true`` and ``run: name`` has to be a subset of top level keys given in the scenario file. In order to automatically create a `scenario.yaml` file based on a combination of settings, alter and use the ``config/create_scenarios.py`` script in the ``config`` directory." disable_progrssbar,bool,"{true, false}","Switch to select whether progressbar should be disabled." -shared_resources,bool/str/list,,"Switch to select whether resources should be shared across runs. If a string or list is passed, it is assumed to be wildcard(s) which indicates up to which set of wildcards the resource folder should be shared. If set to 'base', only resources before creating the elec.nc file are shared." +shared_resources,bool/str,,"Switch to select whether resources should be shared across runs. If a string is passed, this is used as a subdirectory name for shared resources. If set to 'base', only resources before creating the elec.nc file are shared." shared_cutouts,bool,"{true, false}","Switch to select whether cutouts should be shared across runs." diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 98e5aaae..b2b1b341 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -42,6 +42,7 @@ def get_run_path(fn, dir, rdir, shared_resources): shared_resources : str or bool Specifies which resources should be shared. - If string is "base", special handling for shared "base" resources (see notes). + - If random string other than "base", this folder is used instead of the `rdir` keyword. - If boolean, directly specifies if the resource is shared. Returns @@ -59,11 +60,14 @@ def get_run_path(fn, dir, rdir, shared_resources): pattern = r"\{([^{}]+)\}" existing_wildcards = set(re.findall(pattern, fn)) irrelevant_wildcards = {"technology", "year", "scope"} - no_relevant_wildcards = not (existing_wildcards - irrelevant_wildcards) + no_relevant_wildcards = not existing_wildcards - irrelevant_wildcards no_elec_rule = not fn.startswith("networks/elec") and not fn.startswith( "add_electricity" ) is_shared = no_relevant_wildcards and no_elec_rule + elif isinstance(shared_resources, str): + rdir = shared_resources + "/" + is_shared = True elif isinstance(shared_resources, bool): is_shared = shared_resources else: