add_electricity: Fix for choices of countries
without any offshore or hydro
fixes #22.
This commit is contained in:
parent
31aefae93c
commit
f0a0a2531e
@ -178,6 +178,8 @@ def attach_wind_and_solar(n, costs):
|
|||||||
|
|
||||||
n.add("Carrier", name=tech)
|
n.add("Carrier", name=tech)
|
||||||
with xr.open_dataset(getattr(snakemake.input, 'profile_' + tech)) as ds:
|
with xr.open_dataset(getattr(snakemake.input, 'profile_' + tech)) as ds:
|
||||||
|
if ds.indexes['bus'].empty: continue
|
||||||
|
|
||||||
suptech = tech.split('-', 2)[0]
|
suptech = tech.split('-', 2)[0]
|
||||||
if suptech == 'offwind':
|
if suptech == 'offwind':
|
||||||
underwater_fraction = ds['underwater_fraction'].to_pandas()
|
underwater_fraction = ds['underwater_fraction'].to_pandas()
|
||||||
@ -249,14 +251,17 @@ def attach_hydro(n, costs, ppl):
|
|||||||
has_pump=ppl.technology.str.contains('Pumped Storage')
|
has_pump=ppl.technology.str.contains('Pumped Storage')
|
||||||
)
|
)
|
||||||
|
|
||||||
country = ppl['bus'].map(n.buses.country)
|
country = ppl['bus'].map(n.buses.country).rename("country")
|
||||||
# distribute by p_nom in each country
|
|
||||||
|
if ppl.has_inflow.any():
|
||||||
dist_key = ppl.loc[ppl.has_inflow, 'p_nom'].groupby(country).transform(normed)
|
dist_key = ppl.loc[ppl.has_inflow, 'p_nom'].groupby(country).transform(normed)
|
||||||
|
|
||||||
with xr.open_dataarray(snakemake.input.profile_hydro) as inflow:
|
with xr.open_dataarray(snakemake.input.profile_hydro) as inflow:
|
||||||
inflow_countries = pd.Index(country.loc[ppl.has_inflow].values)
|
inflow_countries = pd.Index(country.loc[ppl.has_inflow].values)
|
||||||
assert len(inflow_countries.unique().difference(inflow.indexes['countries'])) == 0, \
|
assert len(inflow_countries.unique().difference(inflow.indexes['countries'])) == 0, (
|
||||||
"'{}' is missing inflow time-series for at least one country: {}".format(snakemake.input.profile_hydro, ", ".join(inflow_countries.unique().difference(inflow.indexes['countries'])))
|
"'{}' is missing inflow time-series for at least one country: {}"
|
||||||
|
.format(snakemake.input.profile_hydro, ", ".join(inflow_countries.unique().difference(inflow.indexes['countries'])))
|
||||||
|
)
|
||||||
|
|
||||||
inflow_t = (
|
inflow_t = (
|
||||||
inflow.sel(countries=inflow_countries)
|
inflow.sel(countries=inflow_countries)
|
||||||
@ -269,6 +274,7 @@ def attach_hydro(n, costs, ppl):
|
|||||||
|
|
||||||
if 'ror' in carriers:
|
if 'ror' in carriers:
|
||||||
ror = ppl.loc[ppl.has_inflow & ~ ppl.has_store]
|
ror = ppl.loc[ppl.has_inflow & ~ ppl.has_store]
|
||||||
|
if not ror.empty:
|
||||||
n.madd("Generator", ror.index,
|
n.madd("Generator", ror.index,
|
||||||
carrier='ror',
|
carrier='ror',
|
||||||
bus=ror['bus'],
|
bus=ror['bus'],
|
||||||
@ -282,6 +288,7 @@ def attach_hydro(n, costs, ppl):
|
|||||||
|
|
||||||
if 'PHS' in carriers:
|
if 'PHS' in carriers:
|
||||||
phs = ppl.loc[ppl.has_store & ppl.has_pump]
|
phs = ppl.loc[ppl.has_store & ppl.has_pump]
|
||||||
|
if not phs.empty:
|
||||||
n.madd('StorageUnit', phs.index,
|
n.madd('StorageUnit', phs.index,
|
||||||
carrier='PHS',
|
carrier='PHS',
|
||||||
bus=phs['bus'],
|
bus=phs['bus'],
|
||||||
@ -294,8 +301,8 @@ def attach_hydro(n, costs, ppl):
|
|||||||
inflow=inflow_t.loc[:, phs.index[phs.has_inflow]])
|
inflow=inflow_t.loc[:, phs.index[phs.has_inflow]])
|
||||||
|
|
||||||
if 'hydro' in carriers:
|
if 'hydro' in carriers:
|
||||||
hydro = ppl.loc[ppl.has_store & ~ ppl.has_pump & ppl.has_inflow].join(country.rename('country'))
|
hydro = ppl.loc[ppl.has_store & ~ ppl.has_pump & ppl.has_inflow].join(country)
|
||||||
|
if not hydro.empty:
|
||||||
hydro_max_hours = c.get('hydro_max_hours')
|
hydro_max_hours = c.get('hydro_max_hours')
|
||||||
if hydro_max_hours == 'energy_capacity_totals_by_country':
|
if hydro_max_hours == 'energy_capacity_totals_by_country':
|
||||||
hydro_e_country = pd.read_csv(snakemake.input.hydro_capacities, index_col=0)["E_store[TWh]"].clip(lower=0.2)*1e6
|
hydro_e_country = pd.read_csv(snakemake.input.hydro_capacities, index_col=0)["E_store[TWh]"].clip(lower=0.2)*1e6
|
||||||
|
Loading…
Reference in New Issue
Block a user