prepare_sector_network: Fix costs bug and carrier bug

In prepare_costs, you need the min_count=1 in the sum so that it
generates NaNs for missing data (rather than 0) so that NaNs can be
subsituted by .fillna in the next line. Otherwise many values
(discount rates and efficiencies for solar, wind) are set to zero.

Also added carriers, storage and generators for coal, nuclear and
oil. (This needs to be organized better soon so that the carriers are
defined in config.yaml.)
This commit is contained in:
Tom Brown 2020-07-29 15:50:40 +02:00
parent 4523f324cd
commit 7abe928337

View File

@ -36,11 +36,11 @@ override_component_attrs["Link"].loc["p2"] = ["series","MW",0.,"2nd bus 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["Link"].loc["lifetime"] = ["float","years",np.nan,"lifetime","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["Generator"].loc["lifetime"] = ["float","years",np.nan,"lifetime","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)"]
override_component_attrs["Store"].loc["lifetime"] = ["float","years",np.nan,"lifetime","Input (optional)"]
def add_lifetime_wind_solar(n):
"""
@ -57,10 +57,32 @@ def add_coal_oil_uranium_buses(n):
"""
for carrier in ['coal', 'oil', 'uranium']:
n.add("Carrier",
carrier)
n.add("Bus",
"EU " + carrier,
carrier=carrier)
#use madd to get carrier inserted
n.madd("Store",
["EU " + carrier + " Store"],
bus=["EU " + carrier],
e_nom_extendable=True,
e_cyclic=True,
carrier=carrier,
capital_cost=0.) #could correct to e.g. 0.2 EUR/kWh * annuity and O&M
n.add("Generator",
"EU " + carrier,
bus="EU " + carrier,
p_nom_extendable=True,
carrier=carrier,
capital_cost=0.,
marginal_cost=costs.at[carrier,'fuel'])
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
@ -459,9 +481,8 @@ def prepare_costs(cost_file, USD_to_EUR, discount_rate, Nyears):
costs.loc[costs.unit.str.contains("/kW"),"value"]*=1e3
costs.loc[costs.unit.str.contains("USD"),"value"]*=USD_to_EUR
#cost_year = snakemake.config['costs']['year']
#costs = costs.loc[idx[:,cost_year,:],"value"].unstack(level=2).groupby(level="technology").sum(min_count=1)
costs = costs.loc[:, "value"].unstack(level=1).groupby("technology").sum()
#min_count=1 is important to generate NaNs which are then filled by fillna
costs = costs.loc[:, "value"].unstack(level=1).groupby("technology").sum(min_count=1)
costs = costs.fillna({"CO2 intensity" : 0,
"FOM" : 0,
"VOM" : 0,