This Jupyter Notebook is also available to download at: http://www.pypsa.org/examples/ac-dc-lopf.ipynb.
This example has a 3-node AC network coupled via AC-DC converters to a 3-node DC network. There is also a single point-to-point DC using the Link component.
The data files for this example are in the examples folder of the github repository: https://github.com/PyPSA/PyPSA.
In [ ]:
#make the code as Python 3 compatible as possible
from __future__ import print_function, division, absolute_import
import pypsa
import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
%matplotlib inline
In [ ]:
#You may have to adjust this path to where
#you downloaded the github repository
#https://github.com/PyPSA/PyPSA
csv_folder_name = "../ac-dc-meshed/ac-dc-data/"
network = pypsa.Network(csv_folder_name)
In [ ]:
#get current type (AC or DC) of the lines from the buses
lines_current_type = pd.merge(network.lines,network.buses,how="left",left_on="bus0",right_index=True,suffixes=("","bus"))["carrier"]
lines_current_type
In [ ]:
fig,ax = plt.subplots(1,1,subplot_kw={"projection":ccrs.PlateCarree()})
fig.set_size_inches(10,8)
network.plot(ax=ax,line_colors=lines_current_type.map(lambda ct: "r" if ct=="DC" else "b"))
ax.set_title('Mixed AC (blue) - DC (red) network - DC (cyan) P2P')
In [ ]:
fig.tight_layout()
#fig.savefig("meshed-ac-dc.png")
In [ ]:
network.links.loc["Norwich Converter",'p_nom_extendable']=False
In [ ]:
#perform linear OPF
#compute optimal caps
network.lopf(network.snapshots)
In [ ]:
network.sub_networks["n_branches"] = [len(sn.branches()) for sn in network.sub_networks.obj]
network.sub_networks["n_buses"] = [len(sn.buses()) for sn in network.sub_networks.obj]
network.sub_networks
In [ ]:
#Plot active power of AC-DC converters and HVDC link
network.links_t.p0.plot(figsize = (9,7))
In [ ]:
network.lines_t.p0.plot(figsize = (9,7))
In [ ]:
network.buses_t.p.plot(figsize = (9,7))
In [ ]:
network.lines_t.mu_upper
In [ ]:
network.lines_t.mu_lower
In [ ]:
network.links_t.mu_upper
In [ ]:
network.links_t.mu_lower