def test_type_parsers(self): for case in test_cases.CASES: if case.split('.')[-1] == 'mat': self.assertRaises(pf.ParserError,pf.ParserJSON().parse,case) self.assertRaises(pf.ParserError,pf.PyParserMAT().parse,case) if pf.has_raw_parser(): self.assertRaises(pf.ParserError,pf.ParserRAW().parse,case) net = pf.ParserMAT().parse(case) self.assertGreater(net.num_buses,0) if case.split('.')[-1] == 'm': self.assertRaises(pf.ParserError,pf.ParserJSON().parse,case) self.assertRaises(pf.ParserError,pf.ParserMAT().parse,case) if pf.has_raw_parser(): self.assertRaises(pf.ParserError,pf.ParserRAW().parse,case) net = pf.PyParserMAT().parse(case) self.assertGreater(net.num_buses,0)
def test_pyparsermat_write(self): tested = False for case in test_cases.CASES: if os.path.splitext(case)[-1] != '.m': continue parser = pf.PyParserMAT() parser.set('output_level', 0) net1 = parser.parse(case, num_periods=2) try: p = pf.PyParserMAT() p.write(net1, 'foo.m') parser = pf.PyParserMAT() net2 = parser.parse('foo.m', num_periods=2) finally: if os.path.isfile('foo.m'): os.remove('foo.m') pf.tests.utils.compare_networks(self, net1, net2) tested = True
def test_gridopt(self): try: case = os.path.join('.', 'tests', 'resources', 'cases', 'ieee300.mat') net = pfnet.Parser(case).parse(case) method = gopt.power_flow.ACPF() method.set_parameters({'quiet': True, 'solver': 'nr'}) method.solve(net) method.update_network(net) gopt.scripts.gridopt.main([case, 'ACPF', '--parameters', 'solver=nr', '--write', 'foo.json', '--quiet']) p = pfnet.ParserJSON() net_json = p.parse('foo.json') pfnet.tests.utils.compare_networks(self, net, net_json) gopt.scripts.gridopt.main([case, 'ACPF', '--parameters', 'solver=nr', '--write', 'foo.m', '--quiet']) p = pfnet.PyParserMAT() net_m = p.parse('foo.m') pfnet.tests.utils.compare_networks(self, net, net_m)
self.assertEqual(branch12.ratingC, 2500. / 100.) self.assertEqual(branch13.bus_k, bus8) self.assertEqual(branch13.bus_m, bus10) self.assertLess(abs(branch13.b + 1. / 0.07), 1e-10) self.assertEqual(branch13.ratingA, 4000. / 100.) self.assertEqual(branch13.ratingB, 4000. / 100.) self.assertEqual(branch13.ratingC, 4000. / 100.) def test_ieee14_gen_cost(self): case = os.path.join('data', 'ieee14.m') if not os.path.isfile(case): raise unittest.SkipTest('file not available') net = pf.PyParserMAT().parse(case) self.assertEqual(net.base_power, 100.) self.assertEqual(net.num_buses, 14) self.assertEqual(net.num_generators, 5) gen0 = net.get_generator(net.num_generators - 1) gen1 = net.get_generator(net.num_generators - 2) self.assertEqual(gen0.P, 232.4 / 100.) self.assertEqual(gen0.cost_coeff_Q2, (4.3029259900e-02) * (net.base_power**2.)) self.assertEqual(gen0.cost_coeff_Q1, 20. * net.base_power) self.assertEqual(gen1.P, 40. / 100.) self.assertEqual(gen1.cost_coeff_Q2, 0.25 * (net.base_power**2.))
#***************************************************# # This file is part of PFNET. # # # # Copyright (c) 2015, Tomas Tinoco De Rubira. # # # # PFNET is released under the BSD 2-clause license. # #***************************************************# import sys sys.path.append('.') # Getting Started - Example import pfnet import numpy as np net = pfnet.PyParserMAT().parse(sys.argv[1]) print(np.average([bus.degree for bus in net.buses]))
#***************************************************# # This file is part of PFNET. # # # # Copyright (c) 2015, Tomas Tinoco De Rubira. # # # # PFNET is released under the BSD 2-clause license. # #***************************************************# import os import sys sys.path.append('.') # Parsers - Overview import pfnet parser = pfnet.Parser(sys.argv[1]) network = parser.parse(sys.argv[1]) parser_json = pfnet.ParserJSON() parser_json.write(network, 'new_network.json') network = parser_json.parse('new_network.json') os.remove('new_network.json') parser_mat = pfnet.PyParserMAT() parser_mat.write(network, 'new_network.m') network = parser_mat.parse('new_network.m') os.remove('new_network.m')
def __init__(self): self.parser_raw = pf.PyParserRAW() self.parser_raw.set('keep_all_out_of_service', True) self.parser_mat = pf.PyParserMAT()