Remove generators, stores and links whose installationYear + lifetime < year. Correct commented lines to YearDecomissioning > year

This commit is contained in:
martavp 2020-07-08 16:28:08 +02:00
parent 2b3dc60f11
commit a4c22a29a4
2 changed files with 39 additions and 19 deletions

View File

@ -68,21 +68,27 @@ def prepare_costs():
return costs return costs
def add_brownfield(n,n_p): def add_brownfield(n, n_p, year):
print("adding brownfield") print("adding brownfield")
previous_timestep=snakemake.config['scenario']['planning_horizons'][snakemake.config['scenario']['planning_horizons'].index(year)-1] previous_timestep=snakemake.config['scenario']['planning_horizons'][snakemake.config['scenario']['planning_horizons'].index(year)-1]
previous_timesteps=snakemake.config['scenario']['planning_horizons'][0:snakemake.config['scenario']['planning_horizons'].index(year)] previous_timesteps=snakemake.config['scenario']['planning_horizons'][0:snakemake.config['scenario']['planning_horizons'].index(year)]
# generators installed before baseyear are removed,
#add generators from previous step # they are added again by add_power_capacities_installed_before_baseyear()
# with updated capacities (some of them have been decomissioned)
n_p.mremove("Generator", [index for index in n_p.generators.index.to_list() if '<'+snakemake.config['scenario']['planning_horizons'][0] in index]) n_p.mremove("Generator", [index for index in n_p.generators.index.to_list() if '<'+snakemake.config['scenario']['planning_horizons'][0] in index])
n_p.mremove("Generator", [index for index in n_p.generators.index.to_list() if 'ror' in index]) n_p.mremove("Generator", [index for index in n_p.generators.index.to_list() if 'ror' in index])
# generators whose installationYear + lifetime < year are removed
n_p.mremove("Generator", [index for index in n_p.generators.index.to_list() if (index[-4:] in previous_timesteps) and (int(index[-4:])+snakemake.config['costs']['lifetime'] < int(year))])
# generators whose capacity was optimized in the previous year are renamed
n_p.generators.index=np.where(n_p.generators.index.str[-4:].isin(previous_timesteps)==False, n_p.generators.index=np.where(n_p.generators.index.str[-4:].isin(previous_timesteps)==False,
n_p.generators.index + '-' + previous_timestep, n_p.generators.index + '-' + previous_timestep,
n_p.generators.index) n_p.generators.index)
#add generators from previous step
n.madd("Generator", n.madd("Generator",
n_p.generators.index, n_p.generators.index,
bus=n_p.generators.bus, bus=n_p.generators.bus,
@ -95,6 +101,11 @@ def add_brownfield(n,n_p):
#add stores from previous steps #add stores from previous steps
n_p.mremove("Store", ['co2 atmosphere', 'co2 stored', 'EU gas Store'] ) n_p.mremove("Store", ['co2 atmosphere', 'co2 stored', 'EU gas Store'] )
# stores whose installationYear + lifetime < year are removed
n_p.mremove("Store", [index for index in n_p.stores.index.to_list() if (index[-4:] in previous_timesteps) and (int(index[-4:])+snakemake.config['costs']['lifetime'] < int(year))])
# stores whose capacity was optimized in the previous year are renamed
n_p.stores.index=np.where(n_p.stores.index.str[-4:].isin(previous_timesteps)==False, n_p.stores.index=np.where(n_p.stores.index.str[-4:].isin(previous_timesteps)==False,
n_p.stores.index + '-' + previous_timestep, n_p.stores.index + '-' + previous_timestep,
n_p.stores.index) n_p.stores.index)
@ -111,6 +122,10 @@ def add_brownfield(n,n_p):
n_p.mremove("Link", [index for index in n_p.links.index.to_list() if '<'+snakemake.config['scenario']['planning_horizons'][0] in index]) n_p.mremove("Link", [index for index in n_p.links.index.to_list() if '<'+snakemake.config['scenario']['planning_horizons'][0] in index])
n_p.mremove("Link", [index for index in n_p.links.index.to_list() if 'CHP' in index]) n_p.mremove("Link", [index for index in n_p.links.index.to_list() if 'CHP' in index])
# stores whose installationYear + lifetime < year are removed
n_p.mremove("Link", [index for index in n_p.links.index.to_list() if (index[-4:] in previous_timesteps) and (int(index[-4:])+snakemake.config['costs']['lifetime'] < int(year))])
# links whose installationYear + lifetime < year are removed
n_p.links.index=np.where(n_p.links.index.str[-4:].isin(previous_timesteps)==False, n_p.links.index=np.where(n_p.links.index.str[-4:].isin(previous_timesteps)==False,
n_p.links.index + '-' + previous_timestep, n_p.links.index + '-' + previous_timestep,
n_p.links.index) n_p.links.index)
@ -161,7 +176,7 @@ if __name__ == "__main__":
n_p = pypsa.Network(snakemake.input.network_p, n_p = pypsa.Network(snakemake.input.network_p,
override_component_attrs=override_component_attrs) override_component_attrs=override_component_attrs)
add_brownfield(n,n_p) add_brownfield(n, n_p, year)
Nyears = n.snapshot_weightings.sum()/8760. Nyears = n.snapshot_weightings.sum()/8760.
@ -169,13 +184,15 @@ if __name__ == "__main__":
baseyear = snakemake.config['scenario']["planning_horizons"][0] baseyear = snakemake.config['scenario']["planning_horizons"][0]
add_power_capacities_installed_before_baseyear(n, year, baseyear, costs) # only the capacities with YearDecomissioning < year are added add_power_capacities_installed_before_baseyear(n, year, baseyear, costs) # only the capacities with YearDecomissioning > year are added
if "H" in opts: if "H" in opts:
time_dep_hp_cop = options["time_dep_hp_cop"] time_dep_hp_cop = options["time_dep_hp_cop"]
ashp_cop = xr.open_dataarray(snakemake.input.cop_air_total).T.to_pandas().reindex(index=n.snapshots) ashp_cop = xr.open_dataarray(snakemake.input.cop_air_total).T.to_pandas().reindex(index=n.snapshots)
gshp_cop = xr.open_dataarray(snakemake.input.cop_soil_total).T.to_pandas().reindex(index=n.snapshots) gshp_cop = xr.open_dataarray(snakemake.input.cop_soil_total).T.to_pandas().reindex(index=n.snapshots)
add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop, gshp_cop, time_dep_hp_cop, costs) # only the capacities with YearDecomissioning < year are added default_lifetime = snakemake.config['costs']['lifetime']
add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop, gshp_cop, time_dep_hp_cop, costs,
default_lifetime) # only the capacities with YearDecomissioning > year are added
n.export_to_netcdf(snakemake.output[0]) n.export_to_netcdf(snakemake.output[0])

View File

@ -67,7 +67,7 @@ def add_power_capacities_installed_before_baseyear(n, year, baseyear, costs):
Parameters Parameters
---------- ----------
n : network n : network
year : capacity that fulfills YearDecomissioning < year is added year : capacity that fulfills YearDecomissioning > year is added
baseyear : capacity name will be e.g. "solar <baseyear" baseyear : capacity name will be e.g. "solar <baseyear"
this allows adding the solar capacity that was installed before this allows adding the solar capacity that was installed before
@ -198,14 +198,14 @@ def add_power_capacities_installed_before_baseyear(n, year, baseyear, costs):
n.mremove("Generator", [index for index in n.generators.index.to_list() if '<'+baseyear in index and n.generators.p_nom[index]==0]) n.mremove("Generator", [index for index in n.generators.index.to_list() if '<'+baseyear in index and n.generators.p_nom[index]==0])
n.mremove("Link", [index for index in n.links.index.to_list() if '<'+baseyear in index and n.links.p_nom[index]==0]) n.mremove("Link", [index for index in n.links.index.to_list() if '<'+baseyear in index and n.links.p_nom[index]==0])
def add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop, gshp_cop, time_dep_hp_cop, costs): def add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop, gshp_cop, time_dep_hp_cop, costs, default_lifetime):
""" """
Parameters Parameters
---------- ----------
n : network n : network
year : capacity that fulfills YearDecomissioning < year is added year : capacity that fulfills YearDecomissioning > year is added
baseyear : capacity name will be e.g. "gas boiler <baseyear" baseyear : capacity name will be e.g. "gas boiler <baseyear"
this allows adding the gas boiler capacity that was installed this allows adding the gas boiler capacity that was installed
before 2020 (baseyear) and is still alive in 2030 (year) before 2020 (baseyear) and is still alive in 2030 (year)
@ -300,7 +300,7 @@ def add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop
carrier="{} {} heat pump".format(name,heat_pump_type), carrier="{} {} heat pump".format(name,heat_pump_type),
efficiency=efficiency, efficiency=efficiency,
capital_cost=costs.at[costs_name,'efficiency']*costs.at[costs_name,'fixed'], capital_cost=costs.at[costs_name,'efficiency']*costs.at[costs_name,'fixed'],
p_nom=p_nom[name]*max(0,(2045-int(year))/25)) #decomissioning happens lineary from now to 25 years lter p_nom=p_nom[name]*max(0,(int(baseyear)+default_lifetime-int(year))/default_lifetime)) #decomissioning happens lineary from now to 25 years lter
# add resistive heater, gas boilers and oil boilers # add resistive heater, gas boilers and oil boilers
# (50% capacities to rural buses, 50% to urban buses) # (50% capacities to rural buses, 50% to urban buses)
@ -312,7 +312,7 @@ def add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop
carrier=name + " resistive heater", carrier=name + " resistive heater",
efficiency=costs.at[name_type + ' resistive heater','efficiency'], efficiency=costs.at[name_type + ' resistive heater','efficiency'],
capital_cost=costs.at[name_type + ' resistive heater','efficiency']*costs.at[name_type + ' resistive heater','fixed'], capital_cost=costs.at[name_type + ' resistive heater','efficiency']*costs.at[name_type + ' resistive heater','fixed'],
p_nom=0.5*df['{} resistive heater'.format(heat_type)][nodes[name]]*max(0,(2045-int(year))/25)) p_nom=0.5*df['{} resistive heater'.format(heat_type)][nodes[name]]*max(0,(int(baseyear)+default_lifetime-int(year))/default_lifetime))
n.madd("Link", n.madd("Link",
nodes[name], nodes[name],
@ -324,7 +324,7 @@ def add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop
efficiency=costs.at[name_type + ' gas boiler','efficiency'], efficiency=costs.at[name_type + ' gas boiler','efficiency'],
efficiency2=costs.at['gas','CO2 intensity'], efficiency2=costs.at['gas','CO2 intensity'],
capital_cost=costs.at[name_type + ' gas boiler','efficiency']*costs.at[name_type + ' gas boiler','fixed'], capital_cost=costs.at[name_type + ' gas boiler','efficiency']*costs.at[name_type + ' gas boiler','fixed'],
p_nom=0.5*df['{} gas boiler'.format(heat_type)][nodes[name]]*max(0,(2045-int(year))/25)) p_nom=0.5*df['{} gas boiler'.format(heat_type)][nodes[name]]*max(0,(int(baseyear)+default_lifetime-int(year))/default_lifetime))
n.madd("Link", n.madd("Link",
nodes[name], nodes[name],
@ -336,7 +336,7 @@ def add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop
efficiency=costs.at['decentral oil boiler','efficiency'], efficiency=costs.at['decentral oil boiler','efficiency'],
efficiency2=costs.at['oil','CO2 intensity'], efficiency2=costs.at['oil','CO2 intensity'],
capital_cost=costs.at['decentral oil boiler','efficiency']*costs.at['decentral oil boiler','fixed'], capital_cost=costs.at['decentral oil boiler','efficiency']*costs.at['decentral oil boiler','fixed'],
p_nom=0.5*df['{} oil boiler'.format(heat_type)][nodes[name]]*max(0,(2045-int(year))/25)) p_nom=0.5*df['{} oil boiler'.format(heat_type)][nodes[name]]*max(0,(int(baseyear)+default_lifetime-int(year))/default_lifetime))
# delete links with p_nom=nan corresponding to extra nodes in country # delete links with p_nom=nan corresponding to extra nodes in country
n.mremove("Link", [index for index in n.links.index.to_list() if baseyear in index and np.isnan(n.links.p_nom[index])]) n.mremove("Link", [index for index in n.links.index.to_list() if baseyear in index and np.isnan(n.links.p_nom[index])])
@ -351,8 +351,9 @@ if __name__ == "__main__":
snakemake = MockSnakemake( snakemake = MockSnakemake(
wildcards=dict(network='elec', simpl='', clusters='37', lv='1.0', wildcards=dict(network='elec', simpl='', clusters='37', lv='1.0',
sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1', sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1',
co2_budget_name='go',
planning_horizons='2020'), planning_horizons='2020'),
input=dict(network='pypsa-eur-sec/results/test/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc', input=dict(network='pypsa-eur-sec/results/test/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_{planning_horizons}.nc',
costs='pypsa-eur-sec/data/costs/costs_{planning_horizons}.csv', costs='pypsa-eur-sec/data/costs/costs_{planning_horizons}.csv',
cop_air_total="pypsa-eur-sec/resources/cop_air_total_{network}_s{simpl}_{clusters}.nc", cop_air_total="pypsa-eur-sec/resources/cop_air_total_{network}_s{simpl}_{clusters}.nc",
cop_soil_total="pypsa-eur-sec/resources/cop_soil_total_{network}_s{simpl}_{clusters}.nc"), cop_soil_total="pypsa-eur-sec/resources/cop_soil_total_{network}_s{simpl}_{clusters}.nc"),
@ -376,13 +377,15 @@ if __name__ == "__main__":
Nyears = n.snapshot_weightings.sum()/8760. Nyears = n.snapshot_weightings.sum()/8760.
costs = prepare_costs() costs = prepare_costs()
add_power_capacities_installed_before_baseyear(n, baseyear, baseyear, costs) add_power_capacities_installed_before_baseyear(n, baseyear, baseyear, costs)
if "H" in opts: if "H" in opts:
time_dep_hp_cop = options["time_dep_hp_cop"] time_dep_hp_cop = options["time_dep_hp_cop"]
ashp_cop = xr.open_dataarray(snakemake.input.cop_air_total).T.to_pandas().reindex(index=n.snapshots) ashp_cop = xr.open_dataarray(snakemake.input.cop_air_total).T.to_pandas().reindex(index=n.snapshots)
gshp_cop = xr.open_dataarray(snakemake.input.cop_soil_total).T.to_pandas().reindex(index=n.snapshots) gshp_cop = xr.open_dataarray(snakemake.input.cop_soil_total).T.to_pandas().reindex(index=n.snapshots)
add_heating_capacities_installed_before_baseyear(n, baseyear, baseyear, ashp_cop, gshp_cop, time_dep_hp_cop, costs) default_lifetime = snakemake.config['costs']['lifetime']
add_heating_capacities_installed_before_baseyear(n, baseyear, baseyear, ashp_cop, gshp_cop, time_dep_hp_cop, costs, default_lifetime)
n.export_to_netcdf(snakemake.output[0]) n.export_to_netcdf(snakemake.output[0])