enter image description hereI want to optimize one hydro reservoir over multiple time snaphshots using PyPSA and Python.
On Pypsa support page, I used the Two chained reservoir example as a starting point, even if i want only one reservoir in my case.
text
import pypsa
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
country = "South Africa"
network = pypsa.Network()
network.set_snapshots(pd.date_range("2016-01-01 00:00", "2016-01-01 03:00", freq="h"))
network.add("Bus", country, carrier="AC") # "Electrical" Bus is the country bidding zone
# Hydro system definition
network.add("Carrier", "reservoir")
network.add("Carrier", "rain")
# network.add("Bus", "0", carrier="AC") # Replaced by our country South Africa electrical Bus
network.add("Bus", "0 reservoir", carrier="reservoir")
# network.add("Bus", "1 reservoir", carrier="reservoir")
network.add(
"Generator",
"rain",
bus="0 reservoir",
carrier="rain",
p_nom=500,
p_max_pu=[0.1, 0.2, 0.6, 0.4],
)
network.add(
"Link",
"0 turbine",
bus0="0 reservoir",
bus1=country,
# bus2="1 reservoir",
efficiency=0.85,
# efficiency2=0.8,
capital_cost=0,
p_nom_extendable=True,
)
network.add(
"Store", "0 reservoir", bus="0 reservoir", e_cyclic=True, e_nom_extendable=True
)
# marginal costs in EUR/MWh
marginal_costs = {"Wind": 0, "Coal": 80, "Gas": 130, "Oil": 180}
# power plant capacities (nominal powers in MW) in each country (not necessarily realistic)
power_plant_p_nom = {
"South Africa": {"Wind": 400, "Coal": 1000, "Gas": 1000, "Oil": 300}
}
[enter image description here](https://i.sstatic.net/jyV3kPIF.png)
# p_max_pu is variable for wind
for tech in power_plant_p_nom[country]:
network.add(
"Generator",
"{} {}".format(country, tech),
bus=country,
p_nom=power_plant_p_nom[country][tech],
marginal_cost=marginal_costs[tech],
p_max_pu=([0.2, 0.8, 0.5, 0.7] if tech == "Wind" else 1),
)
# country electrical loads in MW (not necessarily realistic)
loads = {"South Africa": 1500}
# load which varies over the snapshots
network.add(
"Load",
"{} load".format(country),
bus=country,
p_set=loads[country] + np.array([-700, 700, -1000, 1000])
)
network.optimize(network.snapshots)
# network.optimize()
print("Objective:", network.objective)
network.generators_t.p.plot.area(figsize=(9, 4))
plt.tight_layout()
network.links_t.p0.plot(figsize=(9, 4), lw=3)
plt.tight_layout()
# print the load active power (P) consumption
print(network.loads_t.p)
# print the generator active power (P) dispatch
print(network.generators_t.p)
# print the clearing price (corresponding to gas)
print("SMP :",network.buses_t.marginal_price)
network.buses_t.marginal_price.plot(figsize=(9, 4))
plt.show()
First, I did not find the way to specify in my code essential reservoir properties such as :
– Reservoir capacity in MWh
– Turbine Power output in MW
– Waters Inflows in MWh
Despite these missing properties, i generated a first example code below : as per the captures attached i see the turbine running but i do not see the generated Power output properly. I think something is missing regarding how hydro transfers into power generation. Rain is accounted as power generation in the chart as well which does not make sense. As you can see the turbine runs on rain numbers without respect to the turbine capacity that sould be in place.