예제 #1
0
    def getYfromPyPower(self):

        sysN, sysopt = opf_args.opf_args2(self.sys)
        sysN = pyp.ext2int(sysN)
        #sysopt = pyp.ppoption(sysopt, OPF_ALG=0, VERBOSE=3)
        om = pyp.opf_setup(sysN, sysopt)
        sysN = om.get_ppc()

        baseMVA = sysN['baseMVA']
        branch = sysN['branch']
        bus = sysN['bus']
        Y, Yf, Yt = pyp.makeYbus(baseMVA, bus, branch)

        return Y, Yf, Yt
예제 #2
0
파일: utils.py 프로젝트: vjugor1/lmp
def get_Jac(ppc, ppopt, results):
    ppc = ext2int(ppc)
    baseMVA, bus, gen, branch = \
        ppc["baseMVA"], ppc["bus"], ppc["gen"], ppc["branch"]

    Ybus, Yf, Yt = makeYbus(baseMVA, bus, branch)
    #print(Ybus.shape)
    #print(Yf.shape)
    #print(Yt.shape)

    x = results['x']
    om = opf_setup(ppc, ppopt)

    g, geq, dg, dgeq = opf_consfcn(x, om, Ybus, Yf, Yt, ppopt)

    return dg.T, dgeq.T
예제 #3
0
    def __init__(self, data):
        """Initialize internal structure with loaded case file"""
        self.baseMVA = data['baseMVA']
        self.bus = data['bus']
        self.branch = data['branch']
        self.gen = data['gen']

        self.ref, self.pv, self.pq = bustypes(self.bus, self.gen)
        self.pvpq = np.r_[self.pv, self.pq]
        self.npv = len(self.pv)
        self.npq = len(self.pq)
        self.j1 = 0
        self.j2 = self.npv
        self.j3 = self.j2
        self.j4 = self.j2 + self.npq
        self.j5 = self.j4
        self.j6 = self.j4 + self.npq
        ## j1:j2 - V angle of pv buses
        ## j3:j4 - V angle of pq buses
        ## j5:j6 - V mag of pq buses

        self.Y, _, _ = makeYbus(self.baseMVA, self.bus, self.branch)
        self.S = makeSbus(self.baseMVA, self.bus, self.gen)
        self.V0 = self.get_V0()
예제 #4
0
def GetYbus(ppc):
    Ybus, j1, j2 = makeYbus(ppc['baseMVA'], ppc['bus'], ppc['branch'])

    return Ybus
예제 #5
0
t_f = 96
# time variation
t_ges = 1440  # all time in min
delta_t = 15  # time intervals in min
time = np.arange(delta_t, t_ges + delta_t, delta_t)

casedataWhole = netWhole()
convert_to_python_indices(casedataWhole)
ppc = casedataWhole
ppopt = ppoption(PF_ALG=2)
ppc = ext2int(ppc)
baseMVA, bus, gen, branch = ppc["baseMVA"], ppc["bus"], ppc["gen"], ppc[
    "branch"]
baseMVA = 1000
Ybus, Yf, Yt = makeYbus(baseMVA, bus, branch)  # nodal admittance matrix Ybus
condition = np.hstack((1, np.arange(16, 27, 1)))
Yws = Ybus[np.ix_(condition, condition)]

#Yws = Y
t_f = 96
slack_idx = 0
p0 = 1e-3
iterstop = 50
accuracy = 1e-9
roundY = None

filename1 = '/Users/makara01/Documents/oioi/dataMonthKlant55.dat'
PVdata = np.loadtxt(filename1)

location = 'Normal'  # ['High', 'Normal', 'Low']
from scipy.io import loadmat
from NLO.dynamic_models import AR2Model_single, SimpleModel
from NLO.nodal_load_observer import IteratedExtendedKalman, LinearKalmanFilter
import tools.profilesPV as ProfilePV
from pypower.api import ppoption, runpf, makeYbus
from tools.load import convert_mcase, convert_to_python_indices
from pypower.ext2int import ext2int
from tools.data_tools import process_admittance, separate_Yslack

# from NLO.nodal_load_observer import LinearKalmanFilter

# load data
topology = network.full_network()
S = network.measured_data()

Ybus, Yf, Yt = makeYbus(topology['baseMVA'], topology['bus'],
                        topology['branch'])  # nodal admittance matrix Ybus
baseMVA = topology['baseMVA']
condition = np.hstack((1, np.arange(16, 27, 1)))
Yws = Ybus[np.ix_(condition, condition)]

nNodes = S.shape[0] / 2
nT = S.shape[1]
t = np.arange(15, 15 * (nT + 1), 15)
#################################################### PV data
filename1 = 'dataMonthKlant55.dat'
PVdata = np.loadtxt(filename1)
location = 'Normal'  # ['High', 'Normal', 'Low']
Season = 'Summer'  # ['Winter', 'Spring', 'Summer', 'Autumn']
Ampl, mu, sig = ProfilePV.ProfilePower(
    location, Season
)  # paramater identification according your choise of location and season
from scipy.io import loadmat
from NLO.dynamic_models import AR2Model_single, SimpleModel
from NLO.nodal_load_observer import IteratedExtendedKalman, LinearKalmanFilter
import tools.profilesPV as ProfilePV
from pypower.api import ppoption, runpf, makeYbus 
from tools.load import convert_mcase, convert_to_python_indices
from pypower.ext2int import ext2int
from tools.data_tools import process_admittance, separate_Yslack

# from NLO.nodal_load_observer import LinearKalmanFilter

# load data
topology = network.full_network()
S = network.measured_data()

Ybus, Yf, Yt = makeYbus(topology['baseMVA'], topology['bus'], topology['branch']) # nodal admittance matrix Ybus
baseMVA= topology['baseMVA']
condition = np.hstack((1,np.arange(16,27,1))) 
Yws = Ybus[np.ix_(condition, condition)]

nNodes = S.shape[0]/2
nT = S.shape[1]
t = np.arange(15,15*(nT+1),15)
#################################################### PV data
filename1 = 'dataMonthKlant55.dat'
PVdata = np.loadtxt(filename1)
location = 'Normal' # ['High', 'Normal', 'Low']
Season = 'Summer' # ['Winter', 'Spring', 'Summer', 'Autumn']
Ampl, mu, sig = ProfilePV.ProfilePower(location, Season)  # paramater identification according your choise of location and season
FittedPV = ProfilePV.gaussian(np.linspace(0, nT-1, nT), Ampl, baseMVA, mu, sig, location) # creating PV pseudo-data according your choise of location and season
LoadP = PVdata[:,19] # in kVA 
                  131.7, 129.3, 128.2, 127.4, 125.6, 124.2]]) # sample load profile
sf = sampleL[0,:nt]/np.mean(sampleL[0,:nt])
sf = np.matlib.repmat(sf,busnum,1)
loads = np.matlib.repmat(ppc["bus"][:, [2]],1,nt)
loads = loads*sf

#     loads(8,:)=loads(8,:)+5*ones(1,nt);%add 5mw of load at bus 8 to create congestion
#     load ('newnetCavg.mat');
#     mg=net; % microgrid contribution, +:export, -:import
#     mbus=8; % bus for microgrid
#     wbus=25; 
#     wl=0; % wind penetration scaling factor

# Create B Matrix
#    make Y/B bus matrix and A matrix in Pline=A*Pinj
Ybus, Yf, Yt = makeYbus(100,ppc["bus"],ppc["branch"])
B = (1j*Ybus).real.todense()
NB = -B
Bred = B[0:busnum-1,0:busnum-1] # Reduced B Matrix
#    
frm = ppc["branch"][:,0]
to = ppc["branch"][:,1]
M = np.zeros((linenum,busnum)) # from/to matrix
lineC = np.zeros((linenum,1))

for i in xrange(linenum):
    M[i,int(frm[i]-1)] = 1
    M[i,int(to[i]-1)]= -1
    lineC[i]=1*ppc["branch"][i,6]
    
m = M[:,0:busnum-1]    
예제 #9
0
    def _get_param(self):

        # delect the disturbances not defined in the set_disturb, and renumber the new disturbance set.
        for d_type in {1, 2, 3, 4}:
            i_d_all = list()
            for i_d in range(len(self.casedata['disturbance'][d_type])):
                if (d_type, self.casedata['disturbance'][d_type][i_d, 0]
                    ) in self.set_disturb:
                    i_d_all.append(i_d)
            self.casedata['disturbance'][d_type] = self.casedata[
                'disturbance'][d_type][i_d_all, :]
            for i_d in range(len(self.casedata['disturbance'][d_type])):
                self.casedata['disturbance'][d_type][i_d, 0] = i_d + 1
            if len(self.casedata['disturbance'][d_type]) == 0:
                del self.casedata['disturbance'][d_type]

        # parameters
        if len(self.casedata['bus']) >= 200 or len(self.casedata['bus']) == 59:
            opt = ppoption(PF_TOL=1e-12, PF_MAX_IT=20)
        else:
            opt = ppoption(PF_TOL=1e-13, PF_MAX_IT=20)
        s_pf = runpf(self.casedata, opt)

        pcc_y = ext2int(self.casedata)
        Ybus = makeYbus(pcc_y["baseMVA"], pcc_y["bus"],
                        pcc_y["branch"])[0].toarray()
        n_bus = len(Ybus)
        B_0 = np.imag(Ybus)
        for i in range(len(B_0)):
            B_0[i, i] = 0
        pg_0 = np.zeros(n_bus)
        pg_0[(s_pf[0]['gen'][:, 0] - 1).astype(int)] = s_pf[0]['gen'][:, 1]
        i_gen = self.casedata['gen'][:, 0].astype(int).tolist()
        i_non_0 = (np.where(self.casedata['bus'][:, 2] == 0)[0] + 1).tolist()
        i_non = list(set(i_non_0).difference(set(i_gen)))
        i_load_0 = list(
            set(self.casedata['bus'][:, 0].astype(int).tolist()).difference(
                set(i_gen)))
        i_load = list(set(i_load_0).difference(set(i_non)))

        self.Ybus = Ybus
        self.n_bus = n_bus
        self.B_0 = B_0
        self.v_0 = s_pf[0]['bus'][:, 7]
        self.theta_0 = np.radians(s_pf[0]['bus'][:, 8])
        self.pl_0 = s_pf[0]['bus'][:, 2] / 100.0
        self.pg_0 = pg_0 / 100.0
        self.w_0 = np.zeros(self.n_bus)

        self.i_gen = i_gen
        self.i_non = i_non
        self.i_load = i_load
        self.i_gl = i_gen + i_load
        self.i_all = self.casedata['bus'][:, 0].astype(int).tolist()

        self.theta_gl_0 = self.theta_0[(np.array(self.i_gl) - 1).tolist()]

        # initial values and bounds of optimization variables
        self.m_0, self.m_l, self.m_u = dict(), dict(), dict()
        self.d_0, self.d_l, self.d_u = dict(), dict(), dict()
        self.M = self.casedata['bus'][:, 13].tolist()
        self.D = self.casedata['bus'][:, 14].tolist()

        for i in self.i_gen:
            i_gc = np.where(self.casedata['gencontrol'][:, 0] == i)[0]
            i_bus = np.where(self.casedata['bus'][:, 0] == i)[0][0]
            self.m_0[i] = self.M[i_bus]
            self.m_l[i] = self.casedata['gencontrol'][i_gc, 2][0]
            self.m_u[i] = self.casedata['gencontrol'][i_gc, 3][0]
            self.d_0[i] = self.D[i_bus]
            self.d_l[i] = self.casedata['gencontrol'][i_gc, 4][0]
            self.d_u[i] = self.casedata['gencontrol'][i_gc, 5][0]

        # set of index for each kind of branch, used for computing the objective function
        self.ind_branch = list(
        )  # index set [(ind_bus_from, ind_bus_to)] of all branch
        for i_b in self.casedata['branch'][:, [0, 1]]:
            self.ind_branch.append((int(i_b[0]), int(i_b[1])))

        set_k_i = list()  # list of (k,i) of all disturbances and time elements
        for k0 in self.casedata['disturbance'].keys():
            if k0 != 9:
                for k1 in self.casedata['disturbance'][k0][:, 0]:
                    for i in range(
                            1,
                            self.casedata['param_disc']['time_ele'][k0] + 1):
                        set_k_i.append(((int(k0), int(k1)), i))
        self.set_k_i = set_k_i
예제 #10
0
    pilotBus = [lIdx[i] for i in pIdx]

    return pilotBus






if __name__ == '__main__':
    print('-----------Start-----------')
    ppc, success = runpf(case9())
    ppc = ext2int(ppc)
    baseMVA = ppc['baseMVA']
    bus = ppc['bus']
    branch = ppc['branch']

    Ybus, Yf, Yt = makeYbus(baseMVA, bus, branch)

    vm = bus[:, VM]
    va = 2 * np.pi * bus[:, VA]
    V = vm * np.exp(1j * va)

    gIdx = [0, 1, 2]
    lIdx = [3, 4, 5, 6, 7, 8]

    nPilot = 2
    pilotBus = findPilot(Ybus, V, gIdx, lIdx, nPilot)
    print(pilotBus)
예제 #11
0
    np.linspace(0, t_f - 1, t_f), Ampl, baseMVA, mu, sig, location
)  # creating PV pseudo-data according your choise of location and season
LoadP = -PVdata[:, 19]  # in kVA
loadsP15to25[6, :] = -PVdata[:, 14] / 1000 + loadsP15to25[
    6, :]  # in kVA ***************
casedata = net()
bus_var = np.arange(2, 13, 1)  # buses that are varied

casedataWhole = netWhole()
convert_to_python_indices(casedataWhole)
ppc = casedataWhole
ppopt = ppoption(PF_ALG=2)
ppc = ext2int(ppc)
baseMVA, bus, gen, branch = ppc["baseMVA"], ppc["bus"], ppc["gen"], ppc[
    "branch"]  #original grid which has 77 buses
Ybus, Yf, Yt = makeYbus(baseMVA, bus, branch)  #build bus admittance matrix
condition = np.hstack((1, np.arange(16, 27, 1)))
Yws = Ybus[np.ix_(condition, condition)]

v_mag = np.zeros((13, t_f))
v_ang = np.zeros((13, t_f))
loadP_all = np.zeros((13, t_f))
loadQ_all = np.zeros((13, t_f))
genP_all = np.zeros((2, t_f))
genQ_all = np.zeros((2, t_f))
P_into_00 = np.zeros((1, t_f))
Q_into_00 = np.zeros((1, t_f))

for n in range(len(time)):
    casedata['bus'][
        bus_var,