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(
'add_brownfield',
simpl='',
clusters="45",
clusters="37",
opts="",
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,
)

View File

@ -253,10 +253,9 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas
)
else:
bus0 = n.buses[(n.buses.carrier==carrier[generator])].index
if any(n.buses.loc[bus0,"location"]!="EU"):
bus0 = n.buses[n.buses.location.isin(capacity.index) &
(n.buses.carrier==carrier[generator])].index
bus0 = vars(spatial)[carrier[generator]].nodes
if "EU" not in vars(spatial)[carrier[generator]].locations:
bus0 = bus0.intersection(capacity.index + " gas")
n.madd("Link",
capacity.index,
@ -410,10 +409,7 @@ def add_heating_capacities_installed_before_baseyear(n, baseyear, grouping_years
lifetime=costs.at[costs_name, 'lifetime']
)
bus0 = n.buses[(n.buses.carrier=="gas")].index
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
bus0 = vars(spatial)["gas"].nodes
n.madd("Link",
nodes[name],
@ -452,17 +448,17 @@ def add_heating_capacities_installed_before_baseyear(n, baseyear, grouping_years
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])
#%%
if __name__ == "__main__":
if 'snakemake' not in globals():
from helper import mock_snakemake
snakemake = mock_snakemake(
'add_existing_baseyear',
simpl='',
clusters="45",
clusters="37",
lv=1.0,
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,
)
@ -476,7 +472,7 @@ if __name__ == "__main__":
overrides = override_component_attrs(snakemake.input.overrides)
n = pypsa.Network(snakemake.input.network, override_component_attrs=overrides)
# 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)
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.locations = ["EU"]
return spatial
from types import SimpleNamespace
spatial = SimpleNamespace()
@ -371,7 +373,8 @@ def add_carrier_buses(n, carrier, nodes=None):
"""
if nodes is None:
nodes = ["EU " + carrier]
nodes = vars(spatial)[carrier].nodes
location = vars(spatial)[carrier].locations
# skip if carrier already exists
if carrier in n.carriers.index:
@ -384,7 +387,7 @@ def add_carrier_buses(n, carrier, nodes=None):
n.madd("Bus",
nodes,
location=nodes.str.replace(" " + carrier, ""),
location=location,
carrier=carrier
)
@ -825,10 +828,8 @@ def add_generation(n, costs):
for generator, carrier in conventionals.items():
if carrier == 'gas':
carrier_nodes = spatial.gas.nodes
else:
carrier_nodes = ["EU " + carrier]
carrier_nodes = vars(spatial)[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_cyclic=True,
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)
@ -1434,10 +1436,10 @@ def add_land_transport(n, costs):
if ice_share > 0:
if "EU oil" not in n.buses.index:
n.add("Bus",
"EU oil",
location="EU",
if "oil" not in n.buses.carrier.unique():
n.madd("Bus",
vars(spatial)["oil"].nodes,
location=vars(spatial)["oil"].locations,
carrier="oil"
)
@ -1446,7 +1448,7 @@ def add_land_transport(n, costs):
n.madd("Load",
nodes,
suffix=" land transport oil",
bus="EU oil",
bus=vars(spatial)["oil"].nodes,
carrier="land transport oil",
p_set=ice_share / ice_efficiency * transport[nodes]
)
@ -2113,7 +2115,7 @@ def add_industry(n, costs):
n.madd("Load",
nodes,
suffix=" shipping oil",
bus="EU oil",
bus=vars(spatial)["oil"].nodes,
carrier="shipping oil",
p_set=p_set
)
@ -2127,30 +2129,29 @@ def add_industry(n, costs):
p_set=-co2
)
if "EU oil" not in n.buses.index:
n.add("Bus",
"EU oil",
location="EU",
if "oil" not in n.buses.carrier.unique():
n.madd("Bus",
vars(spatial)["oil"].nodes,
location=vars(spatial)["oil"].locations,
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
n.add("Store",
"EU oil Store",
bus="EU oil",
n.madd("Store",
[oil_bus + " Store" for oil_bus in vars(spatial)["oil"].nodes],
bus=vars(spatial)["oil"].nodes,
e_nom_extendable=True,
e_cyclic=True,
carrier="oil",
)
if "EU oil" not in n.generators.index:
if "oil" not in n.generators.carrier.unique():
n.add("Generator",
"EU oil",
bus="EU oil",
n.madd("Generator",
vars(spatial)["oil"].nodes,
bus=vars(spatial)["oil"].nodes,
p_nom_extendable=True,
carrier="oil",
marginal_cost=costs.at["oil", 'fuel']
@ -2165,7 +2166,7 @@ def add_industry(n, costs):
n.madd("Link",
nodes_heat[name] + f" {name} oil boiler",
p_nom_extendable=True,
bus0="EU oil",
bus0=vars(spatial)["oil"].nodes,
bus1=nodes_heat[name] + f" {name} heat",
bus2="co2 atmosphere",
carrier=f"{name} oil boiler",
@ -2178,7 +2179,7 @@ def add_industry(n, costs):
n.madd("Link",
nodes + " Fischer-Tropsch",
bus0=nodes + " H2",
bus1="EU oil",
bus1=vars(spatial)["oil"].nodes,
bus2=spatial.co2.nodes,
carrier="Fischer-Tropsch",
efficiency=costs.at["Fischer-Tropsch", 'efficiency'],
@ -2188,9 +2189,9 @@ def add_industry(n, costs):
lifetime=costs.at['Fischer-Tropsch', 'lifetime']
)
n.add("Load",
"naphtha for industry",
bus="EU oil",
n.madd("Load",
["naphtha for industry"],
bus=vars(spatial)["oil"].nodes,
carrier="naphtha for industry",
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"]
p_set = nodal_energy_totals.loc[nodes, all_aviation].sum(axis=1).sum() * 1e6 / 8760
n.add("Load",
"kerosene for aviation",
bus="EU oil",
n.madd("Load",
["kerosene for aviation"],
bus=vars(spatial)["oil"].nodes,
carrier="kerosene for aviation",
p_set=p_set
)
@ -2353,7 +2354,7 @@ def add_agriculture(n, costs):
n.add("Load",
"agriculture machinery oil",
bus="EU oil",
bus=vars(spatial)["oil"].nodes,
carrier="agriculture machinery oil",
p_set=ice_share * machinery_nodal_energy.sum() * 1e6 / 8760
)
@ -2457,7 +2458,7 @@ if __name__ == "__main__":
patch_electricity_network(n)
define_spatial(pop_layout.index, options)
spatial = define_spatial(pop_layout.index, options)
if snakemake.config["foresight"] == 'myopic':