def run_pypower(case): """ Executes a PYPOWER power flow for *case* and writes its results back to *case*. If *case* is a string, :func:`transform` will be called first to create a bus/branch model from the CIM file. """ basestring = (str,bytes) from pypower.api import ppoption, runpf from cim2busbranch import ext_pypower if isinstance(case, basestring): case = transform(case) ppc = ext_pypower.create(case) ppo = ppoption(OUT_ALL=0, VERBOSE=0) res = runpf(ppc, ppo) if not res[1]: raise RuntimeError('PYPOWER power flow failed.') ext_pypower.write_results_to_case(res[0], case)
def test_create(case, ppc): res = ext_pypower.create(case) assert res['version'] == ppc['version'] assert res['baseMVA'] == ppc['baseMVA'] assert (res['bus'] == ppc['bus']).all() assert (res['gen'] == ppc['gen']).all() assert (res['branch'] == ppc['branch']).all()
def main(): import sys case = sys.argv[1] if len(sys.argv) == 2 else 'a' cases = { 'a': test_case_a, 'b': test_case_b, } case = cases[case]() ppc = ext_pypower.create(case) ppo = ppoption(OUT_ALL=0, VERBOSE=0) res = runpf(ppc, ppo) ext_pypower.write_results_to_case(res[0], case) print(case)