本文整理汇总了Python中pypower.ppoption.ppoption函数的典型用法代码示例。如果您正苦于以下问题:Python ppoption函数的具体用法?Python ppoption怎么用?Python ppoption使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ppoption函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runopf
def runopf(casedata=None, ppopt=None, fname='', solvedcase=''):
"""Runs an optimal power flow.
@see: L{rundcopf}, L{runuopf}
@author: Ray Zimmerman (PSERC Cornell)
"""
## default arguments
if casedata is None:
casedata = join(dirname(__file__), 'case9')
ppopt = ppoption(ppopt)
##----- run the optimal power flow -----
r = opf(casedata, ppopt)
##----- output results -----
if fname:
fd = None
try:
fd = open(fname, "a")
except IOError as detail:
stderr.write("Error opening %s: %s.\n" % (fname, detail))
finally:
if fd is not None:
printpf(r, fd, ppopt)
fd.close()
else:
printpf(r, stdout, ppopt)
## save solved case
if solvedcase:
savecase(solvedcase, r)
return r
示例2: init
def init():
global ppc
global ppopt
ppc = {"version": '2'}
ppc["baseMVA"] = 100.0
ppc["bus"] = np.array([
[1, 3, 0, 0, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9],
[2, 2, 0, 0, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9],
[3, 2, 0, 0, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9],
[4, 1, 0, 0, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9],
[5, 1, 90, 30, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9],
[6, 1, 0, 0, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9],
[7, 1, 100, 35, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9],
[8, 1, 0, 0, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9],
[9, 1, 125, 50, 0, 0, 1, 1, 0, 345, 1, 1.1, 0.9]
])
ppc["branch"] = np.array([
[1, 4, 0, 0.0576, 0, 250, 250, 250, 0, 0, 1, -360, 360],
[4, 5, 0.017, 0.092, 0.158, 250, 250, 250, 0, 0, 1, -360, 360],
[5, 6, 0.039, 0.17, 0.358, 150, 150, 150, 0, 0, 1, -360, 360],
[3, 6, 0, 0.0586, 0, 300, 300, 300, 0, 0, 1, -360, 360],
[6, 7, 0.0119, 0.1008, 0.209, 150, 150, 150, 0, 0, 1, -360, 360],
[7, 8, 0.0085, 0.072, 0.149, 250, 250, 250, 0, 0, 1, -360, 360],
[8, 2, 0, 0.0625, 0, 250, 250, 250, 0, 0, 1, -360, 360],
[8, 9, 0.032, 0.161, 0.306, 250, 250, 250, 0, 0, 1, -360, 360],
[9, 4, 0.01, 0.085, 0.176, 250, 250, 250, 0, 0, 1, -360, 360]
])
ppc["gen"] = np.array([
[1, 0, 0, 300, -300, 1.0, 100, 1, 250, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[2, 163, 0, 300, -300, 1.0, 100, 1, 300, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[3, 85, 0, 300, -300, 1.0, 100, 1, 270, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
])
# OPF functions not yet implemented in GUI
"""
ppc["areas"] = np.array([
[1, 5]
])
ppc["gencost"] = np.array([
[2, 1500, 0, 3, 0.11, 5, 150],
[2, 2000, 0, 3, 0.085, 1.2, 600],
[2, 3000, 0, 3, 0.1225, 1, 335]
])
"""
ppopt = ppoption()
global filename
filename = ""
# Power flow settings
global pf_settings
pf_settings = {"Qlim": False, "max_iter": 25, "err_tol": 0.00001}
示例3: runuopf
def runuopf(casedata=None, ppopt=None, fname='', solvedcase=''):
"""Runs an optimal power flow with unit-decommitment heuristic.
@see: L{rundcopf}, L{runuopf}
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
## default arguments
if casedata is None:
casedata = join(dirname(__file__), 'case9')
ppopt = ppoption(ppopt)
##----- run the unit de-commitment / optimal power flow -----
r = uopf(casedata, ppopt)
##----- output results -----
if fname:
fd = None
try:
fd = open(fname, "wb")
except Exception as detail:
stderr.write("Error opening %s: %s.\n" % (fname, detail))
finally:
if fd is not None:
printpf(r, fd, ppopt)
fd.close()
printpf(r, ppopt=ppopt)
## save solved case
if solvedcase:
savecase(solvedcase, r)
return r
示例4: draw_network
def draw_network(fignr=754):
from matplotlib.pyplot import figure, show
import networkx as nx
casedata = get_topology()
ppc = casedata
ppopt = ppoption(PF_ALG=2)
ppc = ext2int(ppc)
figure(fignr)
g = nx.Graph()
i = ppc['bus'][:, BUS_I].astype(int)
g.add_nodes_from(i, bgcolor='green')
#nx.draw_networkx_nodes(g,pos=nx.spring_layout(g))
fr = ppc['branch'][:, F_BUS].astype(int)
to = ppc['branch'][:, T_BUS].astype(int)
g.add_edges_from(zip(fr, to), color='magenta')
nx.draw(g, with_labels=True, node_size=1000,node_color='skyblue',width=0.5)
show()
示例5: rundcopf
def rundcopf(casedata=None, ppopt=None, fname="", solvedcase=""):
"""Runs a DC optimal power flow.
@see: L{runopf}, L{runduopf}
@author: Ray Zimmerman (PSERC Cornell)
"""
## default arguments
if casedata is None:
casedata = join(dirname(__file__), "case9")
ppopt = ppoption(ppopt, PF_DC=True)
return runopf(casedata, ppopt, fname, solvedcase)
示例6: rundcpf
def rundcpf(casedata=None, ppopt=None, fname='', solvedcase=''):
"""Runs a DC power flow.
@see: L{runpf}
@author: Ray Zimmerman (PSERC Cornell)
"""
## default arguments
if casedata is None:
casedata = join(dirname(__file__), 'case9')
ppopt = ppoption(ppopt, PF_DC=True)
return runpf(casedata, ppopt, fname, solvedcase)
示例7: runduopf
def runduopf(casedata=None, ppopt=None, fname='', solvedcase=''):
"""Runs a DC optimal power flow with unit-decommitment heuristic.
@see: L{rundcopf}, L{runuopf}
@author: Ray Zimmerman (PSERC Cornell)
"""
## default arguments
if casedata is None:
casedata = join(dirname(__file__), 'case9')
ppopt = ppoption(ppopt, PF_DC=True)
return runuopf(casedata, ppopt, fname, solvedcase)
示例8: t_makeLODF
def t_makeLODF(quiet=False):
"""Tests for C{makeLODF}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
ntests = 31
t_begin(ntests, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_auction_case')
verbose = 0#not quiet
## load case
ppc = loadcase(casefile)
ppopt = ppoption(VERBOSE=verbose, OUT_ALL=0)
r = rundcopf(ppc, ppopt)
baseMVA, bus, gen, branch = r['baseMVA'], r['bus'], r['gen'], r['branch']
_, bus, gen, branch = ext2int1(bus, gen, branch)
## compute injections and flows
F0 = branch[:, PF]
## create some PTDF matrices
H = makePTDF(baseMVA, bus, branch, 0)
## create some PTDF matrices
try:
LODF = makeLODF(branch, H)
except ZeroDivisionError:
pass
## take out non-essential lines one-by-one and see what happens
ppc['bus'] = bus
ppc['gen'] = gen
branch0 = branch
outages = r_[arange(12), arange(13, 15), arange(16, 18),
[19], arange(26, 33), arange(34, 41)]
for k in outages:
ppc['branch'] = branch0.copy()
ppc['branch'][k, BR_STATUS] = 0
r, _ = rundcpf(ppc, ppopt)
baseMVA, bus, gen, branch = \
r['baseMVA'], r['bus'], r['gen'], r['branch']
F = branch[:, PF]
t_is(LODF[:, k], (F - F0) / F0[k], 6, 'LODF[:, %d]' % k)
t_end()
示例9: dcopf
def dcopf(*args, **kw_args):
"""Solves a DC optimal power flow.
This is a simple wrapper function around L{opf} that sets the C{PF_DC}
option to C{True} before calling L{opf}.
See L{opf} for the details of input and output arguments.
@see: L{rundcopf}
@author: Ray Zimmerman (PSERC Cornell)
"""
ppc, ppopt = opf_args2(*args, **kw_args);
ppopt = ppoption(ppopt, PF_DC=1)
return opf(ppc, ppopt)
示例10: calc_power_flow
def calc_power_flow(case):
# we run an opf, but real power output is fixed everywhere except a single quasi-slack bus,
# so it just adjusts the voltage setpoints to minimize losses (and hopefully get more
# reasonable solutions than a raw power flow)
#results = runopf(case)
#results = runpf(case, ppopt=ppoption(ENFORCE_Q_LIMS=1))[0]
results = runpf(case, ppopt=ppoption(OUT_ALL=0))[0]
slack_bus = case["slack_bus"]
slack_gens = case["slack_gens"]
# add in the extra slack generation introduced by the model, so the results
# show the operating state accurately (even if it differs from the proposed state)
results["net_injection"][slack_bus] += (
np.sum(results["gen"][slack_gens, PG] - case["gen"][slack_gens, PG])
)
return results
示例11: solve_pf
def solve_pf(case, hour=None,
results=None,
ppopt=None,
set_generator_status=False,
fname='./runpf.log'):
ppopt = ppoption(ppopt)
fname = os.path.abspath(fname)
baseMVA = case.baseMVA
bus = case.bus.copy(deep=True)
branch = case.branch.copy(deep=True)
gen = case.gen.copy(deep=True)
gencost = case.gen.copy(deep=True)
if hour is not None:
logger.debug("Setting bus load based on case.load")
bus['PD'] = case.load.loc[hour]
bus = bus.fillna(0)
if hour is not None and results is not None:
logger.debug("Setting GEN_STATUS and PG")
if set_generator_status is True:
gen['GEN_STATUS'] = results.unit_commitment.loc[hour].astype(int)
gen['PG'] = results.power_generated.loc[hour]
value = [i + 1 for i in range(0, len(bus.index))]
bus_name = bus.index
bus.index = value
bus.index = bus.index.astype(int)
branch['F_BUS'] = branch['F_BUS'].apply(lambda x: value[bus_name.get_loc(x)]).astype(int)
branch['T_BUS'] = branch['T_BUS'].apply(lambda x: value[bus_name.get_loc(x)]).astype(int)
gen['GEN_BUS'] = gen['GEN_BUS'].apply(lambda x: value[bus_name.get_loc(x)]).astype(int)
bus = np.array(bus.reset_index())
branch = np.array(branch)
gen = np.array(gen)
gencost = np.array(gencost)
casedata = {'baseMVA': baseMVA,
'gencost': gencost,
'gen': gen,
'branch': branch,
'bus': bus}
return runpf(casedata, ppopt=ppopt, fname=fname)
示例12: runopf
def runopf(casedata=None, ppopt=None, fname='', solvedcase=''):
"""Runs an optimal power flow.
@see: L{rundcopf}, L{runuopf}
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
## default arguments
if casedata is None:
casedata = join(dirname(__file__), 'case9')
ppopt = ppoption(ppopt)
##----- run the optimal power flow -----
r = opf(casedata, ppopt)
##----- output results -----
if fname:
fd = None
try:
fd = open(fname, "wb")
except IOError, detail:
stderr.write("Error opening %s: %s.\n" % (fname, detail))
finally:
示例13: ppoption
ppopt = ppoption(ppopt)
##----- run the optimal power flow -----
r = opf(casedata, ppopt)
##----- output results -----
if fname:
fd = None
try:
fd = open(fname, "a")
except IOError as detail:
stderr.write("Error opening %s: %s.\n" % (fname, detail))
finally:
if fd is not None:
printpf(r, fd, ppopt)
fd.close()
else:
printpf(r, stdout, ppopt)
## save solved case
if solvedcase:
savecase(solvedcase, r)
return r
if __name__ == '__main__':
ppopt = ppoption(OPF_ALG=580)
runopf(None, ppopt)
示例14: newtonpf
def newtonpf(Ybus, Sbus, V0, ref, pv, pq, ppopt=None):
"""Solves the power flow using a full Newton's method.
Solves for bus voltages given the full system admittance matrix (for
all buses), the complex bus power injection vector (for all buses),
the initial vector of complex bus voltages, and column vectors with
the lists of bus indices for the swing bus, PV buses, and PQ buses,
respectively. The bus voltage vector contains the set point for
generator (including ref bus) buses, and the reference angle of the
swing bus, as well as an initial guess for remaining magnitudes and
angles. C{ppopt} is a PYPOWER options vector which can be used to
set the termination tolerance, maximum number of iterations, and
output options (see L{ppoption} for details). Uses default options if
this parameter is not given. Returns the final complex voltages, a
flag which indicates whether it converged or not, and the number of
iterations performed.
@see: L{runpf}
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
## default arguments
if ppopt is None:
ppopt = ppoption()
## options
tol = ppopt['PF_TOL']
max_it = ppopt['PF_MAX_IT']
verbose = ppopt['VERBOSE']
## initialize
converged = 0
i = 0
V = V0
Va = angle(V)
Vm = abs(V)
## set up indexing for updating V
pvpq = r_[pv, pq]
npv = len(pv)
npq = len(pq)
j1 = 0; j2 = npv ## j1:j2 - V angle of pv buses
j3 = j2; j4 = j2 + npq ## j3:j4 - V angle of pq buses
j5 = j4; j6 = j4 + npq ## j5:j6 - V mag of pq buses
## evaluate F(x0)
mis = V * conj(Ybus * V) - Sbus
F = r_[ mis[pv].real,
mis[pq].real,
mis[pq].imag ]
## check tolerance
normF = linalg.norm(F, Inf)
if verbose > 1:
sys.stdout.write('\n it max P & Q mismatch (p.u.)')
sys.stdout.write('\n---- ---------------------------')
sys.stdout.write('\n%3d %10.3e' % (i, normF))
if normF < tol:
converged = 1
if verbose > 1:
sys.stdout.write('\nConverged!\n')
## do Newton iterations
while (not converged and i < max_it):
## update iteration counter
i = i + 1
## evaluate Jacobian
dS_dVm, dS_dVa = dSbus_dV(Ybus, V)
J11 = dS_dVa[array([pvpq]).T, pvpq].real
J12 = dS_dVm[array([pvpq]).T, pq].real
J21 = dS_dVa[array([pq]).T, pvpq].imag
J22 = dS_dVm[array([pq]).T, pq].imag
J = vstack([
hstack([J11, J12]),
hstack([J21, J22])
], format="csr")
## compute update step
dx = -1 * spsolve(J, F)
## update voltage
if npv:
Va[pv] = Va[pv] + dx[j1:j2]
if npq:
Va[pq] = Va[pq] + dx[j3:j4]
Vm[pq] = Vm[pq] + dx[j5:j6]
V = Vm * exp(1j * Va)
Vm = abs(V) ## update Vm and Va again in case
Va = angle(V) ## we wrapped around with a negative Vm
## evalute F(x)
mis = V * conj(Ybus * V) - Sbus
F = r_[ mis[pv].real,
mis[pq].real,
mis[pq].imag ]
#.........这里部分代码省略.........
示例15: t_runopf_w_res
def t_runopf_w_res(quiet=False):
"""Tests C{runopf_w_res} and the associated callbacks.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
t_begin(46, quiet)
verbose = 0#not quiet
tdir = dirname(__file__)
casefile = join(tdir, 't_case30_userfcns')
ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8,
PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9)
ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose, OPF_ALG=560)
t = 'runopf_w_res(''t_case30_userfcns'') : '
r = runopf_w_res(casefile, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 7, [t, 'mu.Pmax'])
ppc = loadcase(casefile)
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
t = 'gen 5 no reserves : ';
ppc = loadcase(casefile)
ppc['reserves']['zones'][:, 4] = 0
ppc['reserves']['cost'] = delete(ppc['reserves']['cost'], 4)
ppc['reserves']['qty'] = delete(ppc['reserves']['qty'], 4)
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 20], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 0, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 6, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0], 7, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
t_is(r['reserves']['totalcost'], 187.5, 4, [t, 'totalcost'])
t = 'extra offline gen : ';
ppc = loadcase(casefile)
idx = list(range(3)) + [4] + list(range(3, 6))
ppc['gen'] = ppc['gen'][idx, :]
ppc['gencost'] = ppc['gencost'][idx, :]
ppc['reserves']['zones'] = ppc['reserves']['zones'][:, idx]
ppc['reserves']['cost'] = ppc['reserves']['cost'][idx]
ppc['reserves']['qty'] = ppc['reserves']['qty'][idx]
ppc['gen'][3, GEN_STATUS] = 0
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 19.3906, 0.6094], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 5.5, 2, 5.5, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 0, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0.5, 0], 7, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
t = 'both extra & gen 6 no res : ';
ppc = loadcase(casefile)
idx = list(range(3)) + [4] + list(range(3, 6))
ppc['gen'] = ppc['gen'][idx, :]
ppc['gencost'] = ppc['gencost'][idx, :]
ppc['reserves']['zones'] = ppc['reserves']['zones'][:, idx]
ppc['reserves']['cost'] = ppc['reserves']['cost'][idx]
ppc['reserves']['qty'] = ppc['reserves']['qty'][idx]
ppc['gen'][3, GEN_STATUS] = 0
ppc['reserves']['zones'][:, 5] = 0
ppc['reserves']['cost'] = delete(ppc['reserves']['cost'], 5)
ppc['reserves']['qty'] = delete(ppc['reserves']['qty'], 5)
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 0, 20], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 5.5, 2, 0, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 0, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0, 0], 6, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0, 0], 7, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
t_is(r['reserves']['totalcost'], 187.5, 4, [t, 'totalcost'])
t = 'no qty (Rmax) : '
ppc = loadcase(casefile)
del ppc['reserves']['qty']
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [39.3826, 0.6174, 0, 0, 19.3818, 0.6182], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 5, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 5, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0.1, 0, 0, 0, 0.5, 0], 5, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['totalcost'], 176.3708, 4, [t, 'totalcost'])
t = 'RAMP_10, no qty (Rmax) : ';
ppc = loadcase(casefile)
del ppc['reserves']['qty']
#.........这里部分代码省略.........