Enable use of lower generators clustering than network clustering
This commit is contained in:
parent
0f3d74ff8f
commit
103ad49671
@ -152,9 +152,20 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas
|
||||
df_agg.drop(df_agg.index[df_agg.Technology.isin(technology_to_drop)], inplace=True)
|
||||
df_agg.Fueltype = df_agg.Fueltype.map(rename_fuel)
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
# assign clustered bus
|
||||
busmap_s = pd.read_csv(snakemake.input.busmap_s, index_col=0, squeeze=True)
|
||||
busmap = pd.read_csv(snakemake.input.busmap, index_col=0, squeeze=True)
|
||||
=======
|
||||
#assign clustered bus
|
||||
busmap_s = pd.read_csv(snakemake.input.busmap_s, index_col=0).squeeze()
|
||||
busmap = pd.read_csv(snakemake.input.busmap, index_col=0).squeeze()
|
||||
|
||||
inv_busmap={}
|
||||
for k,v in busmap.iteritems():
|
||||
inv_busmap[v]=inv_busmap.get(v,[]) + [k]
|
||||
|
||||
>>>>>>> Stashed changes
|
||||
clustermaps = busmap_s.map(busmap)
|
||||
clustermaps.index = clustermaps.index.astype(int)
|
||||
|
||||
@ -192,6 +203,7 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas
|
||||
capacity = capacity[capacity > snakemake.config['existing_capacities']['threshold_capacity']]
|
||||
|
||||
if generator in ['solar', 'onwind', 'offwind']:
|
||||
<<<<<<< Updated upstream
|
||||
|
||||
rename = {"offwind": "offwind-ac"}
|
||||
p_max_pu=n.generators_t.p_max_pu[capacity.index + ' ' + rename.get(generator, generator) + '-' + str(baseyear)]
|
||||
@ -210,6 +222,43 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas
|
||||
lifetime=costs.at[generator, 'lifetime']
|
||||
)
|
||||
|
||||
=======
|
||||
suffix='-ac' if generator=='offwind' else ''
|
||||
if 'm' in snakemake.wildcards.clusters:
|
||||
for ind in capacity.index:
|
||||
# existing capacities are split evenly among regions in every country
|
||||
inv_ind = [i for i in inv_busmap[ind]]
|
||||
# for offshore the spliting only inludes coastal regions
|
||||
inv_ind=[i for i in inv_ind if (i + ' ' + generator + suffix + '-' + str(baseyear)) in n.generators.index]
|
||||
p_max_pu = n.generators_t.p_max_pu[[i + ' ' + generator + suffix + '-' + str(baseyear) for i in inv_ind ]]
|
||||
p_max_pu.columns=[i + ' ' + generator + suffix + '-' + str(grouping_year) for i in inv_ind ]
|
||||
|
||||
n.madd("Generator",
|
||||
[i + ' ' + generator + suffix + '-' + str(grouping_year) for i in inv_ind ],
|
||||
bus=ind,
|
||||
carrier=generator,
|
||||
p_nom=capacity[ind]/len(inv_ind), #split among regions in a country
|
||||
marginal_cost=costs.at[generator,'VOM'],
|
||||
capital_cost=costs.at[generator,'fixed'],
|
||||
efficiency=costs.at[generator, 'efficiency'],
|
||||
p_max_pu=p_max_pu,
|
||||
build_year=grouping_year,
|
||||
lifetime=costs.at[generator,'lifetime'])
|
||||
else:
|
||||
p_max_pu=n.generators_t.p_max_pu[capacity.index + ' ' + generator + suffix + '-' + str(baseyear)]
|
||||
n.madd("Generator",
|
||||
capacity.index,
|
||||
suffix = ' ' + generator +"-"+ str(grouping_year),
|
||||
bus=capacity.index,
|
||||
carrier=generator,
|
||||
p_nom=capacity,
|
||||
marginal_cost=costs.at[generator,'VOM'],
|
||||
capital_cost=costs.at[generator,'fixed'],
|
||||
efficiency=costs.at[generator, 'efficiency'],
|
||||
p_max_pu=p_max_pu.rename(columns=n.generators.bus),
|
||||
build_year=grouping_year,
|
||||
lifetime=costs.at[generator,'lifetime'])
|
||||
>>>>>>> Stashed changes
|
||||
else:
|
||||
|
||||
n.madd("Link",
|
||||
@ -404,6 +453,7 @@ def add_heating_capacities_installed_before_baseyear(n, baseyear, grouping_years
|
||||
|
||||
if __name__ == "__main__":
|
||||
if 'snakemake' not in globals():
|
||||
<<<<<<< Updated upstream
|
||||
from helper import mock_snakemake
|
||||
snakemake = mock_snakemake(
|
||||
'add_existing_baseyear',
|
||||
@ -412,6 +462,22 @@ if __name__ == "__main__":
|
||||
lv=1.0,
|
||||
sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1',
|
||||
planning_horizons=2020,
|
||||
=======
|
||||
from vresutils.snakemake import MockSnakemake
|
||||
snakemake = MockSnakemake(
|
||||
wildcards=dict(network='elec', simpl='148', clusters='37m', lv='1.0',
|
||||
sector_opts='168H-T-H-B-I-solar+p3-dist1-cb36.7ex0',
|
||||
planning_horizons='2020'),
|
||||
input=dict(network='pypsa-eur-sec/results/version-36.7ex0-168H/prenetworks/elec_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc',
|
||||
powerplants='pypsa-eur/resources/powerplants.csv',
|
||||
busmap_s='pypsa-eur/resources/busmap_elec_s{simpl}.csv',
|
||||
busmap='pypsa-eur/resources/busmap_elec_s{simpl}_{clusters}.csv',
|
||||
costs='technology-data/outputs/costs_{planning_horizons}.csv',
|
||||
cop_air_total="pypsa-eur-sec/resources/cop_air_total_elec_s{simpl}_{clusters}.nc",
|
||||
cop_soil_total="pypsa-eur-sec/resources/cop_soil_total_elec_s{simpl}_{clusters}.nc",
|
||||
clustered_pop_layout="pypsa-eur-sec/resources/pop_layout_elec_s{simpl}_{clusters}.csv",),
|
||||
output=['pypsa-eur-sec/results/version-36.7ex0-168H/prenetworks_brownfield/elec_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc'],
|
||||
>>>>>>> Stashed changes
|
||||
)
|
||||
|
||||
logging.basicConfig(level=snakemake.config['logging_level'])
|
||||
|
@ -136,6 +136,7 @@ def add_chp_constraints(n):
|
||||
|
||||
rhs = n.links.loc[electric_fix, "p_nom"].values
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
define_constraints(n, lhs, "<=", rhs, 'chplink', 'top_iso_fuel_line_fix')
|
||||
|
||||
if not electric.empty:
|
||||
@ -148,6 +149,28 @@ def add_chp_constraints(n):
|
||||
link_p[electric].values))
|
||||
|
||||
define_constraints(n, lhs, "<=", 0, 'chplink', 'backpressure')
|
||||
=======
|
||||
def add_land_use_constraint(n):
|
||||
if 'm' in snakemake.wildcards.clusters:
|
||||
# if generators clustering is lower than network clustering, land_use
|
||||
# accounting is at generators clusters
|
||||
for carrier in ['solar', 'onwind', 'offwind-ac', 'offwind-dc']:
|
||||
existing_capacities = n.generators.loc[n.generators.carrier==carrier,"p_nom"]
|
||||
ind=list(set([i.split(sep=" ")[0] + ' ' + i.split(sep=" ")[1] for i in existing_capacities.index]))
|
||||
previous_years= [str(y) for y in
|
||||
snakemake.config["scenario"]["planning_horizons"]
|
||||
+ snakemake.config["existing_capacities"]["grouping_years"]
|
||||
if y < int(snakemake.wildcards.planning_horizons)]
|
||||
for p_year in previous_years:
|
||||
ind2 = [i for i in ind if i + " " + carrier + "-" + p_year in existing_capacities.index]
|
||||
n.generators.loc[[i + " " + carrier + "-" + snakemake.wildcards.planning_horizons for i in ind2], "p_nom_max"] -= existing_capacities.loc[[i + " " + carrier + "-" + p_year for i in ind2]].rename(lambda x: x[:-4]+snakemake.wildcards.planning_horizons)
|
||||
else:
|
||||
#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_capacities = n.generators.loc[n.generators.carrier==carrier,"p_nom"].groupby(n.generators.bus.map(n.buses.location)).sum()
|
||||
existing_capacities.index += " " + carrier + "-" + snakemake.wildcards.planning_horizons
|
||||
n.generators.loc[existing_capacities.index,"p_nom_max"] -= existing_capacities
|
||||
>>>>>>> Stashed changes
|
||||
|
||||
|
||||
def extra_functionality(n, snapshots):
|
||||
@ -181,6 +204,7 @@ def solve_network(n, config, opts='', **kwargs):
|
||||
|
||||
if __name__ == "__main__":
|
||||
if 'snakemake' not in globals():
|
||||
<<<<<<< Updated upstream
|
||||
from helper import mock_snakemake
|
||||
snakemake = mock_snakemake(
|
||||
'solve_network',
|
||||
@ -189,6 +213,17 @@ if __name__ == "__main__":
|
||||
lv=1.0,
|
||||
sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1',
|
||||
planning_horizons=2050,
|
||||
=======
|
||||
from vresutils.snakemake import MockSnakemake, Dict
|
||||
snakemake = MockSnakemake(
|
||||
wildcards=dict(network='elec', simpl='148', clusters='37m', lv='1.0',
|
||||
sector_opts='168H-T-H-B-I-solar+p3-dist1-cb36.7ex0',
|
||||
co2_budget_name='', planning_horizons='2020'),
|
||||
input=dict(network="pypsa-eur-sec/results/version-36.7ex0-168H/prenetworks_brownfield/elec_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc"),
|
||||
output=["results/networks/s{simpl}_{clusters}_lv{lv}_{sector_opts}_{co2_budget_name}_{planning_horizons}-test.nc"],
|
||||
log=dict(gurobi="logs/elec_s{simpl}_{clusters}_lv{lv}_{sector_opts}_{co2_budget_name}_{planning_horizons}_gurobi-test.log",
|
||||
python="logs/elec_s{simpl}_{clusters}_lv{lv}_{sector_opts}_{co2_budget_name}_{planning_horizons}_python-test.log")
|
||||
>>>>>>> Stashed changes
|
||||
)
|
||||
|
||||
logging.basicConfig(filename=snakemake.log.python,
|
||||
|
Loading…
Reference in New Issue
Block a user