use define spatial for all conventionals, add lifetime for H2 storage

This commit is contained in:
lisazeyen 2022-03-18 13:46:40 +01:00
parent 4f288834b2
commit 71a8bc6c96
3 changed files with 47 additions and 50 deletions

View File

@ -88,10 +88,10 @@ if __name__ == "__main__":
snakemake = mock_snakemake( snakemake = mock_snakemake(
'add_brownfield', 'add_brownfield',
simpl='', simpl='',
clusters="45", clusters="37",
opts="", opts="",
lv=1.0, lv=1.0,
sector_opts='168H-T-H-B-I-A-solar+p3-dist1', sector_opts='168H-T-H-B-I-solar+p3-dist1',
planning_horizons=2030, planning_horizons=2030,
) )

View File

@ -253,10 +253,9 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas
) )
else: else:
bus0 = n.buses[(n.buses.carrier==carrier[generator])].index bus0 = vars(spatial)[carrier[generator]].nodes
if any(n.buses.loc[bus0,"location"]!="EU"): if "EU" not in vars(spatial)[carrier[generator]].locations:
bus0 = n.buses[n.buses.location.isin(capacity.index) & bus0 = bus0.intersection(capacity.index + " gas")
(n.buses.carrier==carrier[generator])].index
n.madd("Link", n.madd("Link",
capacity.index, capacity.index,
@ -410,10 +409,7 @@ def add_heating_capacities_installed_before_baseyear(n, baseyear, grouping_years
lifetime=costs.at[costs_name, 'lifetime'] lifetime=costs.at[costs_name, 'lifetime']
) )
bus0 = n.buses[(n.buses.carrier=="gas")].index bus0 = vars(spatial)["gas"].nodes
if any(n.buses.loc[bus0,"location"]!="EU"):
bus0 = n.buses[n.buses.location.isin(nodal_df[f'{heat_type} gas boiler'][nodes[name]].index) &
(n.buses.carrier=="gas")].index
n.madd("Link", n.madd("Link",
nodes[name], nodes[name],
@ -452,17 +448,17 @@ def add_heating_capacities_installed_before_baseyear(n, baseyear, grouping_years
threshold = snakemake.config['existing_capacities']['threshold_capacity'] threshold = snakemake.config['existing_capacities']['threshold_capacity']
n.mremove("Link", [index for index in n.links.index.to_list() if str(grouping_year) in index and n.links.p_nom[index] < threshold]) n.mremove("Link", [index for index in n.links.index.to_list() if str(grouping_year) in index and n.links.p_nom[index] < threshold])
#%%
if __name__ == "__main__": if __name__ == "__main__":
if 'snakemake' not in globals(): if 'snakemake' not in globals():
from helper import mock_snakemake from helper import mock_snakemake
snakemake = mock_snakemake( snakemake = mock_snakemake(
'add_existing_baseyear', 'add_existing_baseyear',
simpl='', simpl='',
clusters="45", clusters="37",
lv=1.0, lv=1.0,
opts='', opts='',
sector_opts='168H-T-H-B-I-A-solar+p3-dist1', sector_opts='Co2L0-168H-T-H-B-I-solar+p3-dist1',
planning_horizons=2020, planning_horizons=2020,
) )
@ -476,7 +472,7 @@ if __name__ == "__main__":
overrides = override_component_attrs(snakemake.input.overrides) overrides = override_component_attrs(snakemake.input.overrides)
n = pypsa.Network(snakemake.input.network, override_component_attrs=overrides) n = pypsa.Network(snakemake.input.network, override_component_attrs=overrides)
# define spatial resolution of carriers # define spatial resolution of carriers
define_spatial(n.buses[n.buses.carrier=="AC"].index, options) spatial = define_spatial(n.buses[n.buses.carrier=="AC"].index, options)
add_build_year_to_new_assets(n, baseyear) add_build_year_to_new_assets(n, baseyear)
Nyears = n.snapshot_weightings.generators.sum() / 8760. Nyears = n.snapshot_weightings.generators.sum() / 8760.

View File

@ -114,6 +114,8 @@ def define_spatial(nodes, options):
spatial.lignite.nodes = ["EU lignite"] spatial.lignite.nodes = ["EU lignite"]
spatial.lignite.locations = ["EU"] spatial.lignite.locations = ["EU"]
return spatial
from types import SimpleNamespace from types import SimpleNamespace
spatial = SimpleNamespace() spatial = SimpleNamespace()
@ -371,7 +373,8 @@ def add_carrier_buses(n, carrier, nodes=None):
""" """
if nodes is None: if nodes is None:
nodes = ["EU " + carrier] nodes = vars(spatial)[carrier].nodes
location = vars(spatial)[carrier].locations
# skip if carrier already exists # skip if carrier already exists
if carrier in n.carriers.index: if carrier in n.carriers.index:
@ -384,7 +387,7 @@ def add_carrier_buses(n, carrier, nodes=None):
n.madd("Bus", n.madd("Bus",
nodes, nodes,
location=nodes.str.replace(" " + carrier, ""), location=location,
carrier=carrier carrier=carrier
) )
@ -825,10 +828,8 @@ def add_generation(n, costs):
for generator, carrier in conventionals.items(): for generator, carrier in conventionals.items():
if carrier == 'gas':
carrier_nodes = spatial.gas.nodes carrier_nodes = vars(spatial)[carrier].nodes
else:
carrier_nodes = ["EU " + carrier]
add_carrier_buses(n, carrier, carrier_nodes) add_carrier_buses(n, carrier, carrier_nodes)
@ -1088,7 +1089,8 @@ def add_storage_and_grids(n, costs):
e_nom_max=h2_caverns.values, e_nom_max=h2_caverns.values,
e_cyclic=True, e_cyclic=True,
carrier="H2 Store", carrier="H2 Store",
capital_cost=h2_capital_cost capital_cost=h2_capital_cost,
lifetime=costs.at["hydrogen storage underground", "lifetime"]
) )
# hydrogen stored overground (where not already underground) # hydrogen stored overground (where not already underground)
@ -1434,10 +1436,10 @@ def add_land_transport(n, costs):
if ice_share > 0: if ice_share > 0:
if "EU oil" not in n.buses.index: if "oil" not in n.buses.carrier.unique():
n.add("Bus", n.madd("Bus",
"EU oil", vars(spatial)["oil"].nodes,
location="EU", location=vars(spatial)["oil"].locations,
carrier="oil" carrier="oil"
) )
@ -1446,7 +1448,7 @@ def add_land_transport(n, costs):
n.madd("Load", n.madd("Load",
nodes, nodes,
suffix=" land transport oil", suffix=" land transport oil",
bus="EU oil", bus=vars(spatial)["oil"].nodes,
carrier="land transport oil", carrier="land transport oil",
p_set=ice_share / ice_efficiency * transport[nodes] p_set=ice_share / ice_efficiency * transport[nodes]
) )
@ -2113,7 +2115,7 @@ def add_industry(n, costs):
n.madd("Load", n.madd("Load",
nodes, nodes,
suffix=" shipping oil", suffix=" shipping oil",
bus="EU oil", bus=vars(spatial)["oil"].nodes,
carrier="shipping oil", carrier="shipping oil",
p_set=p_set p_set=p_set
) )
@ -2127,30 +2129,29 @@ def add_industry(n, costs):
p_set=-co2 p_set=-co2
) )
if "EU oil" not in n.buses.index: if "oil" not in n.buses.carrier.unique():
n.madd("Bus",
n.add("Bus", vars(spatial)["oil"].nodes,
"EU oil", location=vars(spatial)["oil"].locations,
location="EU",
carrier="oil" carrier="oil"
) )
if "EU oil Store" not in n.stores.index: if "oil" not in n.stores.carrier.unique():
#could correct to e.g. 0.001 EUR/kWh * annuity and O&M #could correct to e.g. 0.001 EUR/kWh * annuity and O&M
n.add("Store", n.madd("Store",
"EU oil Store", [oil_bus + " Store" for oil_bus in vars(spatial)["oil"].nodes],
bus="EU oil", bus=vars(spatial)["oil"].nodes,
e_nom_extendable=True, e_nom_extendable=True,
e_cyclic=True, e_cyclic=True,
carrier="oil", carrier="oil",
) )
if "EU oil" not in n.generators.index: if "oil" not in n.generators.carrier.unique():
n.add("Generator", n.madd("Generator",
"EU oil", vars(spatial)["oil"].nodes,
bus="EU oil", bus=vars(spatial)["oil"].nodes,
p_nom_extendable=True, p_nom_extendable=True,
carrier="oil", carrier="oil",
marginal_cost=costs.at["oil", 'fuel'] marginal_cost=costs.at["oil", 'fuel']
@ -2165,7 +2166,7 @@ def add_industry(n, costs):
n.madd("Link", n.madd("Link",
nodes_heat[name] + f" {name} oil boiler", nodes_heat[name] + f" {name} oil boiler",
p_nom_extendable=True, p_nom_extendable=True,
bus0="EU oil", bus0=vars(spatial)["oil"].nodes,
bus1=nodes_heat[name] + f" {name} heat", bus1=nodes_heat[name] + f" {name} heat",
bus2="co2 atmosphere", bus2="co2 atmosphere",
carrier=f"{name} oil boiler", carrier=f"{name} oil boiler",
@ -2178,7 +2179,7 @@ def add_industry(n, costs):
n.madd("Link", n.madd("Link",
nodes + " Fischer-Tropsch", nodes + " Fischer-Tropsch",
bus0=nodes + " H2", bus0=nodes + " H2",
bus1="EU oil", bus1=vars(spatial)["oil"].nodes,
bus2=spatial.co2.nodes, bus2=spatial.co2.nodes,
carrier="Fischer-Tropsch", carrier="Fischer-Tropsch",
efficiency=costs.at["Fischer-Tropsch", 'efficiency'], efficiency=costs.at["Fischer-Tropsch", 'efficiency'],
@ -2188,9 +2189,9 @@ def add_industry(n, costs):
lifetime=costs.at['Fischer-Tropsch', 'lifetime'] lifetime=costs.at['Fischer-Tropsch', 'lifetime']
) )
n.add("Load", n.madd("Load",
"naphtha for industry", ["naphtha for industry"],
bus="EU oil", bus=vars(spatial)["oil"].nodes,
carrier="naphtha for industry", carrier="naphtha for industry",
p_set=industrial_demand.loc[nodes, "naphtha"].sum() / 8760 p_set=industrial_demand.loc[nodes, "naphtha"].sum() / 8760
) )
@ -2198,9 +2199,9 @@ def add_industry(n, costs):
all_aviation = ["total international aviation", "total domestic aviation"] all_aviation = ["total international aviation", "total domestic aviation"]
p_set = nodal_energy_totals.loc[nodes, all_aviation].sum(axis=1).sum() * 1e6 / 8760 p_set = nodal_energy_totals.loc[nodes, all_aviation].sum(axis=1).sum() * 1e6 / 8760
n.add("Load", n.madd("Load",
"kerosene for aviation", ["kerosene for aviation"],
bus="EU oil", bus=vars(spatial)["oil"].nodes,
carrier="kerosene for aviation", carrier="kerosene for aviation",
p_set=p_set p_set=p_set
) )
@ -2353,7 +2354,7 @@ def add_agriculture(n, costs):
n.add("Load", n.add("Load",
"agriculture machinery oil", "agriculture machinery oil",
bus="EU oil", bus=vars(spatial)["oil"].nodes,
carrier="agriculture machinery oil", carrier="agriculture machinery oil",
p_set=ice_share * machinery_nodal_energy.sum() * 1e6 / 8760 p_set=ice_share * machinery_nodal_energy.sum() * 1e6 / 8760
) )
@ -2457,7 +2458,7 @@ if __name__ == "__main__":
patch_electricity_network(n) patch_electricity_network(n)
define_spatial(pop_layout.index, options) spatial = define_spatial(pop_layout.index, options)
if snakemake.config["foresight"] == 'myopic': if snakemake.config["foresight"] == 'myopic':