From ad6322bcb3c2eff0530c67b89f6150b06c9211bc Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 4 Aug 2023 12:58:31 +0200 Subject: [PATCH] address review commments --- .gitignore | 4 ++-- Snakefile | 1 + config/config.default.yaml | 1 + config/config.validation.yaml | 2 +- doc/configtables/opts.csv | 1 + rules/solve_electricity.smk | 3 ++- rules/solve_myopic.smk | 1 + rules/solve_overnight.smk | 1 + scripts/prepare_network.py | 25 ++++++++++++++----------- 9 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 178087c9..0adf0ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ gurobi.log /networks /benchmarks /logs -# /notebooks +/notebooks /data /cutouts @@ -68,7 +68,7 @@ doc/_build *.geojson -# *.ipynb +*.ipynb data/costs_* diff --git a/Snakefile b/Snakefile index 0e783beb..f8a1e476 100644 --- a/Snakefile +++ b/Snakefile @@ -19,6 +19,7 @@ if not exists("config/config.yaml"): configfile: "config/config.yaml" +configfile: "config/config.validation.yaml" COSTS = f"data/costs_{config['costs']['year']}.csv" diff --git a/config/config.default.yaml b/config/config.default.yaml index 28eb0f0b..b162b75d 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -669,6 +669,7 @@ solving: glpk-default: {} # Used in CI mem: 30000 #memory in MB; 20 GB enough for 50+B+I+H2; 100 GB for 181+B+I+H2 + walltime: "12:00:00" # docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#plotting plotting: diff --git a/config/config.validation.yaml b/config/config.validation.yaml index 525d741a..5bcd5c31 100644 --- a/config/config.validation.yaml +++ b/config/config.validation.yaml @@ -62,7 +62,7 @@ renewable: flatten_dispatch: 0.01 conventional: - unit_commitment: true + unit_commitment: false dynamic_fuel_price: true nuclear: p_max_pu: "data/nuclear_p_max_pu.csv" diff --git a/doc/configtables/opts.csv b/doc/configtables/opts.csv index b468be6e..8c8a706f 100644 --- a/doc/configtables/opts.csv +++ b/doc/configtables/opts.csv @@ -3,6 +3,7 @@ Trigger, Description, Definition, Status ``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.", ``prepare_network``: apply_time_segmentation(), In active use ``Co2L``, Add an overall absolute carbon-dioxide emissions limit configured in ``electricity: co2limit``. If a float is appended an overall emission limit relative to the emission level given in ``electricity: co2base`` is added (e.g. ``Co2L0.05`` limits emissisions to 5% of what is given in ``electricity: co2base``), ``prepare_network``: `add_co2limit() `_ and its `caller `__, In active use ``Ep``, Add cost for a carbon-dioxide price configured in ``costs: emission_prices: co2`` to ``marginal_cost`` of generators (other emission types listed in ``network.carriers`` possible as well), ``prepare_network``: `add_emission_prices() `_ and its `caller `__, In active use +``Ept``, Add monthly cost for a carbon-dioxide price based on historical values built by the rule ``build_monthly_prices``, In active use ``CCL``, 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``., ``solve_network``, In active use ``EQ``, "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.", ``solve_network``, In active use ``ATK``, "Require each node to be autarkic. Example: ``ATK`` removes all lines and links. ``ATKc`` removes all cross-border lines and links.", ``prepare_network``, In active use diff --git a/rules/solve_electricity.smk b/rules/solve_electricity.smk index 7da42a11..c396ebd5 100644 --- a/rules/solve_electricity.smk +++ b/rules/solve_electricity.smk @@ -27,7 +27,7 @@ rule solve_network: threads: 4 resources: mem_mb=memory, - walltime="24:00:00", + walltime=config["solving"].get("walltime", "12:00:00"), shadow: "minimal" conda: @@ -58,6 +58,7 @@ rule solve_operations_network: threads: 4 resources: mem_mb=(lambda w: 10000 + 372 * int(w.clusters)), + walltime=config["solving"].get("walltime", "12:00:00"), shadow: "minimal" conda: diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index 6e84e5f4..8a93d24a 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -106,6 +106,7 @@ rule solve_sector_network_myopic: threads: 4 resources: mem_mb=config["solving"]["mem"], + walltime=config["solving"].get("walltime", "12:00:00"), benchmark: ( BENCHMARKS diff --git a/rules/solve_overnight.smk b/rules/solve_overnight.smk index a01c1195..c7700760 100644 --- a/rules/solve_overnight.smk +++ b/rules/solve_overnight.smk @@ -28,6 +28,7 @@ rule solve_sector_network: threads: config["solving"]["solver"].get("threads", 4) resources: mem_mb=config["solving"]["mem"], + walltime=config["solving"].get("walltime", "12:00:00"), benchmark: ( RESULTS diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index 8021e999..a5a00a3c 100755 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -115,14 +115,17 @@ def add_dynamic_emission_prices(n): co2_price = ( co2_price.reindex(n.snapshots).fillna(method="ffill").fillna(method="bfill") ) - # TODO: enable this without having dynamic marginal costs defined beforehand + emissions = ( n.generators.carrier.map(n.carriers.co2_emissions) / n.generators.efficiency ) co2_cost = expand_series(emissions, n.snapshots).T.mul(co2_price.iloc[:, 0], axis=0) - n.generators_t.marginal_cost += co2_cost.reindex( - columns=n.generators_t.marginal_cost.columns - ) + + static = n.generators.marginal_cost + dynamic = n.get_switchable_as_dense("Generator", "marginal_cost") + + marginal_cost = dynamic + co2_cost.reindex(columns=dynamic.columns, fill_value=0) + n.generators_t.marginal_cost = marginal_cost.loc[:, marginal_cost.ne(static).any()] def set_line_s_max_pu(n, s_max_pu=0.7): @@ -277,7 +280,7 @@ if __name__ == "__main__": from _helpers import mock_snakemake snakemake = mock_snakemake( - "prepare_network", simpl="", clusters="37c", ll="v1.0", opts="24H-Ept" + "prepare_network", simpl="", clusters="37", ll="v1.0", opts="Ept" ) configure_logging(snakemake) @@ -351,7 +354,12 @@ if __name__ == "__main__": c.df.loc[sel, attr] *= factor for o in opts: - if "Ep" in o: + if "Ept" in o: + logger.info( + "Setting time dependent emission prices according spot market price" + ) + add_dynamic_emission_prices(n) + elif "Ep" in o: m = re.findall("[0-9]*\.?[0-9]+$", o) if len(m) > 0: logger.info("Setting emission prices according to wildcard value.") @@ -360,11 +368,6 @@ if __name__ == "__main__": logger.info("Setting emission prices according to config value.") add_emission_prices(n, snakemake.params.costs["emission_prices"]) break - if "Ept" in o: - logger.info( - "Setting time dependent emission prices according spot market price" - ) - add_dynamic_emission_prices(n) ll_type, factor = snakemake.wildcards.ll[0], snakemake.wildcards.ll[1:] set_transmission_limit(n, ll_type, factor, costs, Nyears)