Group the generators existing before base year into categories and add them to the network as e.g. solar-2005, solar-2010, solar-2015
This commit is contained in:
parent
17a348d1e6
commit
4523f324cd
@ -46,7 +46,10 @@ biomass:
|
||||
year: 2030
|
||||
scenario: "Med"
|
||||
|
||||
|
||||
existing_capacities:
|
||||
grouping_years: ['1980', '1985', '1990', '1995', '2000','2005','2010','2015', '2019']
|
||||
threshold_capacity: 10
|
||||
|
||||
sector:
|
||||
'central' : True
|
||||
'central_fraction' : 0.6
|
||||
|
@ -20,10 +20,6 @@ import pytz
|
||||
|
||||
from vresutils.costdata import annuity
|
||||
|
||||
from add_existing_baseyear import add_power_capacities_installed_before_baseyear
|
||||
|
||||
from add_existing_baseyear import add_heating_capacities_installed_before_baseyear
|
||||
|
||||
from prepare_sector_network import prepare_costs
|
||||
|
||||
#First tell PyPSA that links can have multiple outputs by
|
||||
@ -39,7 +35,12 @@ override_component_attrs["Link"].loc["efficiency3"] = ["static or series","per u
|
||||
override_component_attrs["Link"].loc["p2"] = ["series","MW",0.,"2nd bus output","Output"]
|
||||
override_component_attrs["Link"].loc["p3"] = ["series","MW",0.,"3rd bus output","Output"]
|
||||
|
||||
|
||||
override_component_attrs["Link"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Link"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Generator"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Generator"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Store"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Store"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
|
||||
def add_brownfield(n, n_p, year):
|
||||
print("adding brownfield")
|
||||
@ -66,19 +67,21 @@ def add_brownfield(n, n_p, year):
|
||||
|
||||
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)]
|
||||
grouping_years=snakemake.config['existing_capacities']['grouping_years']
|
||||
|
||||
# generators installed before baseyear are removed,
|
||||
# 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])
|
||||
|
||||
|
||||
### GENERATORS ###
|
||||
# generators whose build_year + lifetime < year are removed
|
||||
n_p.mremove("Generator", [index for index in n_p.generators.index.to_list()
|
||||
if (n_p.generators.loc[index, 'build_year'] in previous_timesteps)
|
||||
and (n_p.generators.loc[index, 'build_year']+n_p.generators.loc[index, 'lifetime'] < int(year))])
|
||||
if (n_p.generators.loc[index, 'build_year']+n_p.generators.loc[index, '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,
|
||||
# remove generators if their optimized nominal capacity is lower than a threshold
|
||||
n_p.mremove("Generator", [index for index in n_p.generators.index.to_list()
|
||||
if (n_p.generators.loc[index, 'p_nom_opt'] < snakemake.config['existing_capacities']['threshold_capacity'])])
|
||||
|
||||
|
||||
# generators whose capacity was optimized in the previous year are renamed and build year is added
|
||||
n_p.generators.index=np.where(n_p.generators.index.str[-4:].isin(previous_timesteps+grouping_years)==False,
|
||||
n_p.generators.index + '-' + previous_timestep,
|
||||
n_p.generators.index)
|
||||
n_p.generators.loc[[index for index in n_p.generators.index.to_list()
|
||||
@ -97,19 +100,22 @@ def add_brownfield(n, n_p, year):
|
||||
build_year=n_p.generators.build_year,
|
||||
lifetime=n_p.generators.lifetime)
|
||||
|
||||
#add stores from previous steps
|
||||
|
||||
### STORES ###
|
||||
# stores whose installationYear + lifetime < year are removed
|
||||
n_p.mremove("Store", [index for index in n_p.stores.index.to_list()
|
||||
if (n_p.stores.loc[index, 'build_year'] in previous_timesteps)
|
||||
and (n_p.stores.loc[index, 'build_year']+n_p.stores.loc[index, 'lifetime'] < int(year))])
|
||||
if (n_p.stores.loc[index, 'build_year']+n_p.stores.loc[index, '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,
|
||||
# remove stores if their optimized nominal capacity is lower than a threshold
|
||||
n_p.mremove("Store", [index for index in n_p.stores.index.to_list()
|
||||
if (n_p.stores.loc[index, 'e_nom_opt'] < snakemake.config['existing_capacities']['threshold_capacity'])])
|
||||
|
||||
# stores whose capacity was optimized in the previous year are renamed and the build year is added
|
||||
n_p.stores.index=np.where(n_p.stores.index.str[-4:].isin(previous_timesteps+grouping_years)==False,
|
||||
n_p.stores.index + '-' + previous_timestep,
|
||||
n_p.stores.index)
|
||||
n_p.stores.loc[[index for index in n_p.stores.index.to_list()
|
||||
if previous_timestep in index], 'build_year']=int(previous_timestep)
|
||||
#add stores from previous steps
|
||||
n.madd("Store",
|
||||
n_p.stores.index,
|
||||
bus=n_p.stores.bus,
|
||||
@ -120,22 +126,25 @@ def add_brownfield(n, n_p, year):
|
||||
build_year=n_p.stores.build_year,
|
||||
lifetime=n_p.stores.lifetime)
|
||||
|
||||
## add links from previous steps
|
||||
# TODO: add_chp_constraint() in solve_network needs to be adjusted
|
||||
n_p.mremove("Link", [index for index in n_p.links.index.to_list() if '<'+snakemake.config['scenario']['planning_horizons'][0] in index])
|
||||
### LINKS ###
|
||||
# TODO: add_chp_constraint() in solve_network needs to be adjusted
|
||||
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 (n_p.links.loc[index, 'build_year'] in previous_timesteps)
|
||||
and (n_p.links.loc[index, 'build_year']+n_p.links.loc[index, '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.mremove("Link", [index for index in n_p.links.index.to_list()
|
||||
if (n_p.links.loc[index, 'build_year']+n_p.links.loc[index, 'lifetime'] < int(year))])
|
||||
|
||||
# delete links if their optimized nominal capacity is lower than a threshold
|
||||
n_p.mremove("Link", [index for index in n_p.links.index.to_list()
|
||||
if (n_p.links.loc[index, 'p_nom_opt'] < snakemake.config['existing_capacities']['threshold_capacity'])])
|
||||
|
||||
# links whose capacity was optimized in the previous year are renamed and the build year is added
|
||||
n_p.links.index=np.where(n_p.links.index.str[-4:].isin(previous_timesteps+grouping_years)==False,
|
||||
n_p.links.index + '-' + previous_timestep,
|
||||
n_p.links.index)
|
||||
n_p.links.loc[[index for index in n_p.links.index.to_list()
|
||||
if previous_timestep in index], 'build_year']=int(previous_timestep)
|
||||
#add links from previous steps
|
||||
n.madd("Link",
|
||||
n_p.links.index,
|
||||
bus0=n_p.links.bus0,
|
||||
@ -159,9 +168,9 @@ if __name__ == "__main__":
|
||||
wildcards=dict(network='elec', simpl='', clusters='37', lv='1.0',
|
||||
sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1',
|
||||
co2_budget_name='go',
|
||||
planning_horizons='2050'),
|
||||
planning_horizons='2030'),
|
||||
input=dict(network='pypsa-eur-sec/results/test/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_{planning_horizons}.nc',
|
||||
network_p='pypsa-eur-sec/results/test/postnetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_2040.nc',
|
||||
network_p='pypsa-eur-sec/results/test/postnetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_2020.nc',
|
||||
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_soil_total="pypsa-eur-sec/resources/cop_soil_total_{network}_s{simpl}_{clusters}.nc"),
|
||||
@ -195,17 +204,8 @@ if __name__ == "__main__":
|
||||
Nyears)
|
||||
|
||||
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
|
||||
|
||||
|
||||
if "H" in opts:
|
||||
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)
|
||||
gshp_cop = xr.open_dataarray(snakemake.input.cop_soil_total).T.to_pandas().reindex(index=n.snapshots)
|
||||
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])
|
||||
|
||||
|
||||
|
@ -35,18 +35,22 @@ override_component_attrs["Link"].loc["efficiency3"] = ["static or series","per u
|
||||
override_component_attrs["Link"].loc["p2"] = ["series","MW",0.,"2nd bus output","Output"]
|
||||
override_component_attrs["Link"].loc["p3"] = ["series","MW",0.,"3rd bus output","Output"]
|
||||
|
||||
override_component_attrs["Link"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Link"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Generator"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Generator"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Store"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Store"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
|
||||
def add_power_capacities_installed_before_baseyear(n, year, baseyear, costs):
|
||||
def add_power_capacities_installed_before_baseyear(n, grouping_years, costs):
|
||||
"""
|
||||
|
||||
Parameters
|
||||
----------
|
||||
n : network
|
||||
year : capacity that fulfills YearDecomissioning > year is added
|
||||
|
||||
grouping_years : intervals to group existing capacities
|
||||
|
||||
baseyear : capacity name will be e.g. "solar <baseyear"
|
||||
this allows adding the solar capacity that was installed before
|
||||
2020 (baseyear) and is still alive in 2030 (year)
|
||||
costs : to read lifetime to estimate YearDecomissioning
|
||||
|
||||
|
||||
@ -111,79 +115,82 @@ def add_power_capacities_installed_before_baseyear(n, year, baseyear, costs):
|
||||
'YearDecommissioning':int(float(year)+costs.at[tech, 'lifetime'])},
|
||||
ignore_index=True)
|
||||
|
||||
# powerplants already include an estimated decommissining year wich has been
|
||||
# calculated based on pm config, check if we want to make this calculation more
|
||||
# transparent, e.g., by loading lifetime assumptions from costs.csv into pm config
|
||||
# check how pm is dealing with retrofitting
|
||||
# pm.get_config()['fuel_to_lifetime']
|
||||
# index = df_agg.Fueltype.map(lf)+df_agg.YearCommissioned > 2020
|
||||
nodes=set([node[0:2] for node in n.buses.index[n.buses.carrier == "AC"]])
|
||||
|
||||
|
||||
#TODO: Check if we want to change YearCommisioned into YearRetrofited
|
||||
for i,grouping_year in enumerate(grouping_years):
|
||||
if i==0:
|
||||
index = df_agg.YearCommissioned < int(grouping_year)
|
||||
else:
|
||||
index = (int(grouping_years[i-1]) < df_agg.YearCommissioned) & (df_agg.YearCommissioned < int(grouping_year))
|
||||
|
||||
index=df_agg.YearDecommissioning > int(year)
|
||||
df = df_agg[index].pivot_table(index='Country', columns='Fueltype',
|
||||
values='Capacity', aggfunc='sum')
|
||||
|
||||
nodes=set([node[0:2] for node in n.buses.index[n.buses.carrier == "AC"]])
|
||||
|
||||
for carrier in ['coal', 'oil', 'uranium']:
|
||||
n.add("Bus",
|
||||
"EU " + carrier,
|
||||
carrier=carrier)
|
||||
|
||||
for node in nodes:
|
||||
#if a country has more than one node, selects the first one
|
||||
bus_selected=[bus for bus in n.buses.index[n.buses.carrier == "AC"] if bus[0:2]==node][0]
|
||||
for generator,carrier in [("OCGT","gas"),
|
||||
("CCGT", "gas"),
|
||||
("coal", "coal"),
|
||||
("oil","oil"),
|
||||
("nuclear","uranium")]:
|
||||
if node in df.index and not np.isnan(df.loc[node, generator]):
|
||||
n.add("Link",
|
||||
bus_selected + " " + generator +" <" + baseyear,
|
||||
bus0="EU " + carrier,
|
||||
bus1=bus_selected,
|
||||
bus2="co2 atmosphere",
|
||||
marginal_cost=costs.at[generator,'efficiency']*costs.at[generator,'VOM'], #NB: VOM is per MWel
|
||||
capital_cost=costs.at[generator,'efficiency']*costs.at[generator,'fixed'], #NB: fixed cost is per MWel
|
||||
p_nom=df.loc[node, generator],
|
||||
efficiency=costs.at[generator,'efficiency'],
|
||||
efficiency2=costs.at[carrier,'CO2 intensity'])
|
||||
values='Capacity', aggfunc='sum')
|
||||
|
||||
for generator in ['solar', 'onwind', 'offwind']:
|
||||
try:
|
||||
if not np.isnan(df.loc[node, generator]):
|
||||
if generator =='offwind':
|
||||
p_max_pu=n.generators_t.p_max_pu[bus_selected + ' offwind-ac']
|
||||
else:
|
||||
p_max_pu=n.generators_t.p_max_pu[bus_selected + ' ' + generator]
|
||||
|
||||
n.add("Generator",
|
||||
bus_selected + ' ' + generator +" <"+ baseyear,
|
||||
bus=bus_selected,
|
||||
carrier=generator,
|
||||
p_nom=df.loc[node, generator],
|
||||
marginal_cost=costs.at[generator,'VOM'],
|
||||
capital_cost=costs.at[generator,'fixed'],
|
||||
efficiency=costs.at[generator, 'efficiency'],
|
||||
p_max_pu=p_max_pu)
|
||||
except:
|
||||
print("No capacity installed before base year of " + generator + " is alive in node " + node)
|
||||
|
||||
# delete generators if their lifetime is over and p_nom=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])
|
||||
|
||||
def add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop, gshp_cop, time_dep_hp_cop, costs, default_lifetime):
|
||||
for node in nodes:
|
||||
#if a country has more than one node, selects the first one
|
||||
bus_selected=[bus for bus in n.buses.index[n.buses.carrier == "AC"] if bus[0:2]==node][0]
|
||||
for generator,carrier in [("OCGT","gas"),
|
||||
("CCGT", "gas"),
|
||||
("coal", "coal"),
|
||||
("oil","oil"),
|
||||
("nuclear","uranium")]:
|
||||
try:
|
||||
if node in df.index and not np.isnan(df.loc[node, generator]):
|
||||
n.add("Link",
|
||||
bus_selected + " " + generator +"-" + grouping_year,
|
||||
bus0="EU " + carrier,
|
||||
bus1=bus_selected,
|
||||
bus2="co2 atmosphere",
|
||||
marginal_cost=costs.at[generator,'efficiency']*costs.at[generator,'VOM'], #NB: VOM is per MWel
|
||||
capital_cost=costs.at[generator,'efficiency']*costs.at[generator,'fixed'], #NB: fixed cost is per MWel
|
||||
p_nom=df.loc[node, generator],
|
||||
efficiency=costs.at[generator,'efficiency'],
|
||||
efficiency2=costs.at[carrier,'CO2 intensity'],
|
||||
build_year=int(grouping_year),
|
||||
lifetime=costs.at[generator,'lifetime'])
|
||||
except:
|
||||
print("No capacity installed around " + grouping_year + " of " + generator + " in node " + node)
|
||||
|
||||
for generator in ['solar', 'onwind', 'offwind']:
|
||||
try:
|
||||
if not np.isnan(df.loc[node, generator]):
|
||||
if generator =='offwind':
|
||||
p_max_pu=n.generators_t.p_max_pu[bus_selected + ' offwind-ac']
|
||||
else:
|
||||
p_max_pu=n.generators_t.p_max_pu[bus_selected + ' ' + generator]
|
||||
|
||||
n.add("Generator",
|
||||
bus_selected + ' ' + generator +"-"+ grouping_year,
|
||||
bus=bus_selected,
|
||||
carrier=generator,
|
||||
p_nom=df.loc[node, generator],
|
||||
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=int(grouping_year),
|
||||
lifetime=costs.at[generator,'lifetime'])
|
||||
except:
|
||||
print("No capacity installed around " + grouping_year + " of " + generator + " in node " + node)
|
||||
|
||||
# delete generators if their lifetime is over and p_nom=0
|
||||
n.mremove("Generator", [index for index in n.generators.index.to_list() if grouping_year in index and n.generators.p_nom[index] < snakemake.config['existing_capacities']['threshold_capacity']])
|
||||
n.mremove("Link", [index for index in n.links.index.to_list() if grouping_year in index and n.links.p_nom[index] < snakemake.config['existing_capacities']['threshold_capacity']])
|
||||
|
||||
def add_heating_capacities_installed_before_baseyear(n, baseyear, grouping_years, ashp_cop, gshp_cop, time_dep_hp_cop, costs, default_lifetime):
|
||||
|
||||
"""
|
||||
|
||||
Parameters
|
||||
----------
|
||||
n : network
|
||||
year : capacity that fulfills YearDecomissioning > year is added
|
||||
baseyear : capacity name will be e.g. "gas boiler <baseyear"
|
||||
this allows adding the gas boiler capacity that was installed
|
||||
before 2020 (baseyear) and is still alive in 2030 (year)
|
||||
|
||||
baseyear: last year covered in the existing capacities database
|
||||
|
||||
grouping_years : intervals to group existing capacities
|
||||
|
||||
linear decomissioning of heating capacities from 2020 to 2045 is
|
||||
currently assumed
|
||||
@ -266,59 +273,73 @@ def add_heating_capacities_installed_before_baseyear(n, year, baseyear, ashp_cop
|
||||
|
||||
cop = {"air" : ashp_cop, "ground" : gshp_cop}
|
||||
efficiency = cop[heat_pump_type][nodes[name]] if time_dep_hp_cop else costs.at[costs_name,'efficiency']
|
||||
|
||||
n.madd("Link",
|
||||
nodes[name],
|
||||
suffix=" {} {} heat pump <{}".format(name,heat_pump_type, baseyear),
|
||||
bus0=nodes[name],
|
||||
bus1=nodes[name] + " " + name + " heat",
|
||||
carrier="{} {} heat pump".format(name,heat_pump_type),
|
||||
efficiency=efficiency,
|
||||
capital_cost=costs.at[costs_name,'efficiency']*costs.at[costs_name,'fixed'],
|
||||
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
|
||||
# (50% capacities to rural buses, 50% to urban buses)
|
||||
n.madd("Link",
|
||||
nodes[name],
|
||||
suffix= " " + name + " resistive heater <{}".format(baseyear),
|
||||
bus0=nodes[name],
|
||||
bus1=nodes[name] + " " + name + " heat",
|
||||
carrier=name + " resistive heater",
|
||||
efficiency=costs.at[name_type + ' resistive heater','efficiency'],
|
||||
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,(int(baseyear)+default_lifetime-int(year))/default_lifetime))
|
||||
|
||||
n.madd("Link",
|
||||
nodes[name],
|
||||
suffix= " " + name + " gas boiler <{}".format(baseyear),
|
||||
bus0=["EU gas"]*len(nodes[name]),
|
||||
bus1=nodes[name] + " " + name + " heat",
|
||||
bus2="co2 atmosphere",
|
||||
carrier=name + " gas boiler",
|
||||
efficiency=costs.at[name_type + ' gas boiler','efficiency'],
|
||||
efficiency2=costs.at['gas','CO2 intensity'],
|
||||
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,(int(baseyear)+default_lifetime-int(year))/default_lifetime))
|
||||
|
||||
n.madd("Link",
|
||||
nodes[name],
|
||||
suffix=" " + name + " oil boiler <{}".format(baseyear),
|
||||
bus0=["EU oil"]*len(nodes[name]),
|
||||
bus1=nodes[name] + " " + name + " heat",
|
||||
bus2="co2 atmosphere",
|
||||
carrier=name + " oil boiler",
|
||||
efficiency=costs.at['decentral oil boiler','efficiency'],
|
||||
efficiency2=costs.at['oil','CO2 intensity'],
|
||||
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,(int(baseyear)+default_lifetime-int(year))/default_lifetime))
|
||||
for i,grouping_year in enumerate(grouping_years):
|
||||
if int(grouping_year) + default_lifetime <= int(baseyear):
|
||||
ratio=0
|
||||
else:
|
||||
#installation is assumed to be linear for the past 25 years (default lifetime)
|
||||
ratio = (int(grouping_year)-int(grouping_years[i-1]))/default_lifetime
|
||||
print(grouping_year + ' ratio ' + str(ratio))
|
||||
n.madd("Link",
|
||||
nodes[name],
|
||||
suffix=" {} {} heat pump-{}".format(name,heat_pump_type, grouping_year),
|
||||
bus0=nodes[name],
|
||||
bus1=nodes[name] + " " + name + " heat",
|
||||
carrier="{} {} heat pump".format(name,heat_pump_type),
|
||||
efficiency=efficiency,
|
||||
capital_cost=costs.at[costs_name,'efficiency']*costs.at[costs_name,'fixed'],
|
||||
p_nom=p_nom[name]*ratio,
|
||||
build_year=int(grouping_year),
|
||||
lifetime=costs.at[costs_name,'lifetime'])
|
||||
|
||||
# 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])])
|
||||
# add resistive heater, gas boilers and oil boilers
|
||||
# (50% capacities to rural buses, 50% to urban buses)
|
||||
n.madd("Link",
|
||||
nodes[name],
|
||||
suffix= " " + name + " resistive heater-{}".format(grouping_year),
|
||||
bus0=nodes[name],
|
||||
bus1=nodes[name] + " " + name + " heat",
|
||||
carrier=name + " resistive heater",
|
||||
efficiency=costs.at[name_type + ' resistive heater','efficiency'],
|
||||
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]]*ratio,
|
||||
build_year=int(grouping_year),
|
||||
lifetime=costs.at[costs_name,'lifetime'])
|
||||
|
||||
n.madd("Link",
|
||||
nodes[name],
|
||||
suffix= " " + name + " gas boiler-{}".format(grouping_year),
|
||||
bus0=["EU gas"]*len(nodes[name]),
|
||||
bus1=nodes[name] + " " + name + " heat",
|
||||
bus2="co2 atmosphere",
|
||||
carrier=name + " gas boiler",
|
||||
efficiency=costs.at[name_type + ' gas boiler','efficiency'],
|
||||
efficiency2=costs.at['gas','CO2 intensity'],
|
||||
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]]*ratio,
|
||||
build_year=int(grouping_year),
|
||||
lifetime=costs.at[name_type + ' gas boiler','lifetime'])
|
||||
n.madd("Link",
|
||||
nodes[name],
|
||||
suffix=" " + name + " oil boiler-{}".format(grouping_year),
|
||||
bus0=["EU oil"]*len(nodes[name]),
|
||||
bus1=nodes[name] + " " + name + " heat",
|
||||
bus2="co2 atmosphere",
|
||||
carrier=name + " oil boiler",
|
||||
efficiency=costs.at['decentral oil boiler','efficiency'],
|
||||
efficiency2=costs.at['oil','CO2 intensity'],
|
||||
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]]*ratio,
|
||||
build_year=int(grouping_year),
|
||||
lifetime=costs.at[name_type + ' gas boiler','lifetime'])
|
||||
|
||||
# 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 grouping_year in index and np.isnan(n.links.p_nom[index])])
|
||||
|
||||
# delete links if their lifetime is over and p_nom=0
|
||||
n.mremove("Link", [index for index in n.links.index.to_list() if '<'+baseyear in index and n.links.p_nom[index]==0])
|
||||
# delete links if their lifetime is over and p_nom=0
|
||||
n.mremove("Link", [index for index in n.links.index.to_list() if grouping_year in index and n.links.p_nom[index]<snakemake.config['existing_capacities']['threshold_capacity']])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Detect running outside of snakemake and mock snakemake for testing
|
||||
if 'snakemake' not in globals():
|
||||
@ -332,7 +353,7 @@ if __name__ == "__main__":
|
||||
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_soil_total="pypsa-eur-sec/resources/cop_soil_total_{network}_s{simpl}_{clusters}.nc"),
|
||||
output=['pypsa-eur-sec/results/test/prenetworks_bf/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc'],
|
||||
output=['pypsa-eur-sec/results/test/prenetworks_brownfield/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc'],
|
||||
)
|
||||
import yaml
|
||||
with open('config.yaml') as f:
|
||||
@ -348,22 +369,22 @@ if __name__ == "__main__":
|
||||
|
||||
n = pypsa.Network(snakemake.input.network,
|
||||
override_component_attrs=override_component_attrs)
|
||||
|
||||
|
||||
Nyears = n.snapshot_weightings.sum()/8760.
|
||||
costs = prepare_costs(snakemake.input.costs,
|
||||
snakemake.config['costs']['USD2013_to_EUR2013'],
|
||||
snakemake.config['costs']['discountrate'],
|
||||
Nyears)
|
||||
|
||||
|
||||
add_power_capacities_installed_before_baseyear(n, baseyear, baseyear, costs)
|
||||
grouping_years=snakemake.config['existing_capacities']['grouping_years']
|
||||
add_power_capacities_installed_before_baseyear(n, grouping_years, costs)
|
||||
|
||||
if "H" in opts:
|
||||
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)
|
||||
gshp_cop = xr.open_dataarray(snakemake.input.cop_soil_total).T.to_pandas().reindex(index=n.snapshots)
|
||||
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)
|
||||
add_heating_capacities_installed_before_baseyear(n, baseyear, grouping_years, ashp_cop, gshp_cop, time_dep_hp_cop, costs, default_lifetime)
|
||||
|
||||
n.export_to_netcdf(snakemake.output[0])
|
||||
|
||||
|
@ -35,8 +35,32 @@ override_component_attrs["Link"].loc["efficiency3"] = ["static or series","per u
|
||||
override_component_attrs["Link"].loc["p2"] = ["series","MW",0.,"2nd bus output","Output"]
|
||||
override_component_attrs["Link"].loc["p3"] = ["series","MW",0.,"3rd bus output","Output"]
|
||||
|
||||
override_component_attrs["Link"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Link"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Generator"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Generator"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Store"].loc["build_year"] = ["integer","year",np.nan,"build year","Input (optional)"]
|
||||
override_component_attrs["Store"].loc["lifetime"] = ["float","years",np.nan,"build year","Input (optional)"]
|
||||
|
||||
def add_lifetime_wind_solar(n):
|
||||
"""
|
||||
Add lifetime for solar and wind generators
|
||||
"""
|
||||
for carrier in ['solar', 'onwind', 'offwind-dc', 'offwind-ac']:
|
||||
carrier_name='offwind' if carrier in ['offwind-dc', 'offwind-ac'] else carrier
|
||||
n.generators.loc[[index for index in n.generators.index.to_list()
|
||||
if carrier in index], 'lifetime']=costs.at[carrier_name,'lifetime']
|
||||
|
||||
def add_coal_oil_uranium_buses(n):
|
||||
"""
|
||||
Add buses to connect coal, nuclear and oil plants
|
||||
"""
|
||||
|
||||
for carrier in ['coal', 'oil', 'uranium']:
|
||||
n.add("Bus",
|
||||
"EU " + carrier,
|
||||
carrier=carrier)
|
||||
|
||||
def remove_elec_base_techs(n):
|
||||
"""remove conventional generators (e.g. OCGT) and storage units (e.g. batteries and H2)
|
||||
from base electricity-only network, since they're added here differently using links
|
||||
@ -1615,20 +1639,11 @@ if __name__ == "__main__":
|
||||
|
||||
n.loads["carrier"] = "electricity"
|
||||
|
||||
# Add lifetime and build_year attributes to generators, links and stores
|
||||
n.generators["lifetime"]=np.nan
|
||||
n.generators["build_year"]=np.nan
|
||||
n.links["lifetime"]=np.nan
|
||||
n.links["build_year"]=np.nan
|
||||
n.stores["lifetime"]=np.nan
|
||||
|
||||
if snakemake.config["foresight"]=='myopic':
|
||||
add_lifetime_wind_solar(n)
|
||||
add_coal_oil_uranium_buses(n)
|
||||
|
||||
# Add lifetime for solar and wind generators
|
||||
for carrier in ['solar', 'onwind', 'offwind-dc', 'offwind-ac']:
|
||||
carrier_name='offwind' if carrier in ['offwind-dc', 'offwind-ac'] else carrier
|
||||
n.generators.loc[[index for index in n.generators.index.to_list()
|
||||
if carrier in index], 'lifetime']=costs.at[carrier_name,'lifetime']
|
||||
|
||||
|
||||
add_co2_tracking(n)
|
||||
|
||||
add_generation(n)
|
||||
@ -1715,5 +1730,4 @@ if __name__ == "__main__":
|
||||
if snakemake.config["sector"]['electricity_grid_connection']:
|
||||
add_electricity_grid_connection(n)
|
||||
|
||||
n.stores["build_year"]=np.nan
|
||||
n.export_to_netcdf(snakemake.output[0])
|
||||
|
Loading…
Reference in New Issue
Block a user