add monthly prices to network

This commit is contained in:
lisazeyen 2023-05-16 16:15:51 +02:00
parent dfdd116206
commit 024da02f8a
2 changed files with 23 additions and 7 deletions

View File

@ -239,7 +239,7 @@ rule build_monthly_prices:
fuel_price_raw="/home/lisa/Documents/pypsa-eur/data/validation/energy-price-trends-xlsx-5619002.xlsx"
output:
co2_price="data/validation/CO2_price_2019.csv",
fuel_price="data/validation/onthly_fuel_price.csv"
fuel_price="data/validation/monthly_fuel_price.csv"
log:
LOGS + "build_monthly_prices.log",
threads: 1
@ -285,7 +285,8 @@ rule add_electricity:
powerplants=RESOURCES + "powerplants.csv",
hydro_capacities=ancient("data/bundle/hydro_capacities.csv"),
geth_hydro_capacities="data/geth2015_hydro_capacities.csv",
monthly_fuel_price="data/monthly_fuel_price.csv",
co2_price="data/validation/CO2_price_2019.csv",
fuel_price="data/validation/monthly_fuel_price.csv",
load=RESOURCES + "load.csv",
nuts3_shapes=RESOURCES + "nuts3_shapes.geojson",
output:

View File

@ -154,7 +154,6 @@ def load_costs(tech_costs, config, elec_config, Nyears=1.0):
* costs["investment"]
* Nyears
)
costs.at["OCGT", "fuel"] = costs.at["gas", "fuel"]
costs.at["CCGT", "fuel"] = costs.at["gas", "fuel"]
@ -353,6 +352,7 @@ def attach_wind_and_solar(
def attach_conventional_generators(
n,
costs,
fuel_price,
ppl,
conventional_carriers,
extendable_carriers,
@ -368,8 +368,16 @@ def attach_conventional_generators(
.rename(index=lambda s: "C" + str(s))
)
ppl["efficiency"] = ppl.efficiency.fillna(ppl.efficiency_r)
ppl["marginal_cost"] = (
ppl.carrier.map(costs.VOM) + ppl.carrier.map(costs.fuel) / ppl.efficiency
fuel_price = (fuel_price.assign(OCGT=m_fuel_price['gas'],
CCGT=m_fuel_price['gas'])
.drop("gas", axis=1))
fuel_price = fuel_price.reindex(ppl.carrier, axis=1)
fuel_price.fillna(costs.fuel, inplace=True)
fuel_price.columns = ppl.index
marginal_cost = (
(fuel_price.div(ppl.efficiency)).add(ppl.carrier.map(costs.VOM))
)
logger.info(
@ -387,7 +395,7 @@ def attach_conventional_generators(
p_nom=ppl.p_nom.where(ppl.carrier.isin(conventional_carriers), 0),
p_nom_extendable=ppl.carrier.isin(extendable_carriers["Generator"]),
efficiency=ppl.efficiency,
marginal_cost=ppl.marginal_cost,
marginal_cost=marginal_cost,
capital_cost=ppl.capital_cost,
build_year=ppl.datein.fillna(0).astype(int),
lifetime=(ppl.dateout - ppl.datein).fillna(np.inf),
@ -700,7 +708,7 @@ def add_nice_carrier_names(n, config):
logger.warning(f"tech_colors for carriers {missing_i} not defined in config.")
n.carriers["color"] = colors
#%%
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
@ -753,9 +761,16 @@ if __name__ == "__main__":
conventional_inputs = {
k: v for k, v in snakemake.input.items() if k.startswith("conventional_")
}
m_fuel_price = pd.read_csv(snakemake.input.fuel_price,
index_col=[0], header=[0])
m_fuel_price.index = pd.date_range(start='2019-01-01', end='2019-12-01',
freq='MS')
fuel_price = m_fuel_price.reindex(n.snapshots).fillna(method="ffill")
attach_conventional_generators(
n,
costs,
fuel_price,
ppl,
conventional_carriers,
extendable_carriers,