From a3a7e19b07a51ca2c0a9a8f8de4f9573a6194647 Mon Sep 17 00:00:00 2001 From: virio-andreyana Date: Thu, 28 Sep 2023 21:11:22 +0200 Subject: [PATCH] add finishing touches --- doc/configtables/snapshots.csv | 2 +- doc/configtables/solving.csv | 2 +- scripts/_helpers.py | 12 ++++++++++++ scripts/prepare_network.py | 18 ++---------------- scripts/solve_network.py | 4 ++-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/doc/configtables/snapshots.csv b/doc/configtables/snapshots.csv index 769e6cb0..4a3e1212 100644 --- a/doc/configtables/snapshots.csv +++ b/doc/configtables/snapshots.csv @@ -3,4 +3,4 @@ start,--,str or datetime-like; e.g. YYYY-MM-DD,Left bound of date range end,--,str or datetime-like; e.g. YYYY-MM-DD,Right bound of date range inclusive,--,"One of {'neither', 'both', ‘left’, ‘right’}","Make the time interval closed to the ``left``, ``right``, or both sides ``both`` or neither side ``None``." resolution ,--,"{false,``nH``; i.e. ``2H``-``6H``}",Resample the time-resolution by averaging over every ``n`` snapshots -segmentation,--,"{false,``nSEG``; e.g. ``4380SEG``}","Apply time series segmentation with `tsam `_ package to ``n`` adjacent snapshots of varying lengths based on capacity factors of varying renewables, hydro inflow and load." +segmentation,--,"{false,``n``; e.g. ``4380``}","Apply time series segmentation with `tsam `_ package to ``n`` adjacent snapshots of varying lengths based on capacity factors of varying renewables, hydro inflow and load." diff --git a/doc/configtables/solving.csv b/doc/configtables/solving.csv index 344bf73f..940deba9 100644 --- a/doc/configtables/solving.csv +++ b/doc/configtables/solving.csv @@ -14,7 +14,7 @@ options,,, -- horizon,--,int,Number of snapshots to consider in each iteration. Defaults to 100. constraints ,,, -- CCL,bool,"{'true','false'}",Add minimum and maximum levels of generator nominal capacity per carrier for individual countries. These can be specified in the file linked at ``electricity: agg_p_nom_limits`` in the configuration. File defaults to ``data/agg_p_nom_minmax.csv``. --- EQ,bool/string,"{'false',`EQn(c| )``; i.e. ``EQ0.5``-``EQ0.7c``}",Require each country or node to on average produce a minimal share of its total consumption itself. Example: ``EQ0.5c`` demands each country to produce on average at least 50% of its consumption; ``EQ0.5`` demands each node to produce on average at least 50% of its consumption. +-- EQ,bool/string,"{'false',`n(c| )``; i.e. ``0.5``-``0.7c``}",Require each country or node to on average produce a minimal share of its total consumption itself. Example: ``EQ0.5c`` demands each country to produce on average at least 50% of its consumption; ``EQ0.5`` demands each node to produce on average at least 50% of its consumption. -- BAU,bool,"{'true','false'}",Add a per-``carrier`` minimal overall capacity; i.e. at least ``40GW`` of ``OCGT`` in Europe; configured in ``electricity: BAU_mincapacities`` -- SAFE,bool,"{'true','false'}",Add a capacity reserve margin of a certain fraction above the peak demand to which renewable generators and storage do *not* contribute. Ignores network. solver,,, diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 01349e08..559997ad 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -36,6 +36,18 @@ def get_opt(opts, expr, flags=None): return match.group(0) return None +def find_opt(opts, expr): + """ + Return if available the float after the expression. + """ + for o in opts: + if expr in o: + m = re.findall("[0-9]*\.?[0-9]+$", o) + if len(m) > 0: + return True, float(m[0]) + else: + return True, None + return False, None # Define a context manager to temporarily mute print statements @contextlib.contextmanager diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index 2a15cb0c..c91097ba 100755 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -63,7 +63,7 @@ import re import numpy as np import pandas as pd import pypsa -from _helpers import configure_logging, get_opt +from _helpers import configure_logging, get_opt, find_opt from add_electricity import load_costs, update_transmission_costs from pypsa.descriptors import expand_series @@ -72,20 +72,6 @@ idx = pd.IndexSlice logger = logging.getLogger(__name__) -def find_opt(opts, expr): - """ - Return if available the float after the expression. - """ - for o in opts: - if expr in o: - m = re.findall("[0-9]*\.?[0-9]+$", o) - if len(m) > 0: - return True, float(m[0]) - else: - return True, None - return False, None - - def add_co2limit(n, co2limit, Nyears=1.0): n.add( "GlobalConstraint", @@ -320,7 +306,7 @@ if __name__ == "__main__": # segments with package tsam time_seg_config = snakemake.params.snapshots.get("segmentation", False) - time_seg_wildcard = get_opt(opts, r"^\d+seg$") + time_seg_wildcard = get_opt(opts, r"^\d+seg$")[:-3] time_seg = time_seg_wildcard or time_seg_config if time_seg: solver_name = snakemake.config["solving"]["solver"]["name"] diff --git a/scripts/solve_network.py b/scripts/solve_network.py index ca542bba..2335c86d 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -598,8 +598,8 @@ def extra_functionality(n, snapshots): if reserve.get("activate"): add_operational_reserve_margin(n, snapshots, config) - EQ_config = constraints.get("EQ", False) - EQ_wildcard = get_opt(opts, r"^EQ+[0-9]*\.?[0-9]+(c|)") + EQ_config = constraints.get("EQ",False) + EQ_wildcard = get_opt(opts, r"^EQ+[0-9]*\.?[0-9]+(c|)")[2:] EQ_o = EQ_wildcard or EQ_config if EQ_o: add_EQ_constraints(n, EQ_o)