From 332936bcec2fb01eb1cba4a5ae7e3a7f665307e7 Mon Sep 17 00:00:00 2001 From: lisazeyen Date: Wed, 22 Feb 2023 17:44:05 +0100 Subject: [PATCH] adjust p_nom_max if existing larger --- scripts/add_existing_baseyear.py | 13 +++++++++---- scripts/solve_network.py | 21 +++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index 74b26211..44e3bcc3 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -338,7 +338,12 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas efficiency2=costs.at[key, 'efficiency-heat'], lifetime=lifetime_assets.loc[new_capacity.index] ) - + # check if existing capacities are larger than technical potential + existing_large = n.generators[n.generators["p_nom_min"] > n.generators["p_nom_max"]].index + if len(existing_large): + logger.warning(f"Existing capacities larger than technical potential for {existing_large},\ + adjust technical potential to existing capacities") + n.generators.loc[existing_large, "p_nom_max"] = n.generators.loc[existing_large, "p_nom_min"] def add_heating_capacities_installed_before_baseyear(n, baseyear, grouping_years, ashp_cop, gshp_cop, time_dep_hp_cop, costs, default_lifetime): """ @@ -520,11 +525,11 @@ if __name__ == "__main__": snakemake = mock_snakemake( 'add_existing_baseyear', simpl='', - clusters="37", + clusters="45", lv=1.0, opts='', - sector_opts='800sn-T-H-B-I-A-solar+p3-dist1-co2min-1p7', - planning_horizons=2030, + sector_opts='8760H-T-H-B-I-A-solar+p3-dist1', + planning_horizons=2020, ) logging.basicConfig(level=snakemake.config['logging_level']) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 7e42838e..ddac9196 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -23,10 +23,19 @@ def _add_land_use_constraint(n): #warning: this will miss existing offwind which is not classed AC-DC and has carrier 'offwind' for carrier in ['solar', 'onwind', 'offwind-ac', 'offwind-dc']: - existing = n.generators.loc[n.generators.carrier==carrier,"p_nom"].groupby(n.generators.bus.map(n.buses.location)).sum() + ext_i = (n.generators.carrier==carrier) & ~n.generators.p_nom_extendable + existing = n.generators.loc[ext_i,"p_nom"].groupby(n.generators.bus.map(n.buses.location)).sum() existing.index += " " + carrier + "-" + snakemake.wildcards.planning_horizons n.generators.loc[existing.index,"p_nom_max"] -= existing + # check if existing capacities are larger than technical potential + existing_large = n.generators[n.generators["p_nom_min"] > n.generators["p_nom_max"]].index + if len(existing_large): + logger.warning(f"Existing capacities larger than technical potential for {existing_large},\ + adjust technical potential to existing capacities") + n.generators.loc[existing_large, "p_nom_max"] = n.generators.loc[existing_large, "p_nom_min"] + + n.generators.p_nom_max.clip(lower=0, inplace=True) @@ -241,18 +250,18 @@ def solve_network(n, config, opts="", **kwargs): return n - +#%% if __name__ == "__main__": if 'snakemake' not in globals(): from helper import mock_snakemake snakemake = mock_snakemake( - 'solve_network', + 'solve_network_myopic', simpl='', opts="", - clusters="5", + clusters="45", lv=1.0, - sector_opts='Co2L0-3H-T-H-B-I-A-solar+p3-dist1', - planning_horizons="2050", + sector_opts='8760H-T-H-B-I-A-solar+p3-dist1', + planning_horizons="2020", ) logging.basicConfig(filename=snakemake.log.python,