Exemple #1
0
    def test_sort_generators(self):
        """ Test ordering of generators according to bus index.
        """
        case = PickleReader().read(PWL_FILE)

        self.assertEqual(case.buses.index(case.generators[2].bus), 21)
        self.assertEqual(case.buses.index(case.generators[5].bus), 12)

        case.sort_generators()

        self.assertEqual(case.buses.index(case.generators[2].bus), 12)
        self.assertEqual(case.buses.index(case.generators[5].bus), 26)
Exemple #2
0
    def test_sort_generators(self):
        """ Test ordering of generators according to bus index.
        """
        case = PickleReader().read(PWL_FILE)

        self.assertEqual(case.buses.index(case.generators[2].bus), 21)
        self.assertEqual(case.buses.index(case.generators[5].bus), 12)

        case.sort_generators()

        self.assertEqual(case.buses.index(case.generators[2].bus), 12)
        self.assertEqual(case.buses.index(case.generators[5].bus), 26)
Exemple #3
0
    def setUp(self):
        """ The test runner will execute this method prior to each test.
        """
        case = self.case = PickleReader().read(DATA_FILE)

        self.measurements = [
            Measurement(case.branches[0], PF, 0.12),
            Measurement(case.branches[1], PF, 0.10),
            Measurement(case.branches[2], PT, -0.04),
            Measurement(case.buses[0], PG, 0.58),
            Measurement(case.buses[1], PG, 0.30),
            Measurement(case.buses[2], PG, 0.14),
            Measurement(case.buses[1], VM, 1.04),
            Measurement(case.buses[2], VM, 0.98),
        ]

        self.sigma = array([0.02, 0.02, 0,0, 0.015, 0, 0.01, 0])
Exemple #4
0
 def setUp(self):
     """ The test runner will execute this method prior to each test.
     """
     path = join(DATA_DIR, self.case_name, self.case_name + ".pkl")
     self.case = PickleReader().read(path)
Exemple #5
0
class CaseMatrixTest(unittest.TestCase):
    """ Defines a test case for the Pylon case.
    """
    def __init__(self, methodName='runTest'):
        super(CaseMatrixTest, self).__init__(methodName)

        #: Name of the folder in which the MatrixMarket data exists.
        self.case_name = "case6ww"

        self.case = None

    def setUp(self):
        """ The test runner will execute this method prior to each test.
        """
        path = join(DATA_DIR, self.case_name, self.case_name + ".pkl")
        self.case = PickleReader().read(path)

    def testSbus(self):
        """ Test the vector of bus power injections.
        """
        Sbus = self.case.Sbus
        mpSbus = mmread(join(DATA_DIR, self.case_name, "Sbus.mtx")).flatten()

        #        self.assertTrue(alltrue(Sbus == mpSbus))
        # FIXME: Improve accuracy.
        self.assertTrue(abs(max(Sbus - mpSbus)) < 1e-06, msg=self.case_name)

    def testYbus(self):
        """ Test bus and branch admittance matrices.
        """
        self.case.index_buses()
        Ybus, Yf, Yt = self.case.Y

        mpYbus = mmread(join(DATA_DIR, self.case_name, "Ybus.mtx")).tocsr()
        mpYf = mmread(join(DATA_DIR, self.case_name, "Yf.mtx")).tocsr()
        mpYt = mmread(join(DATA_DIR, self.case_name, "Yt.mtx")).tocsr()

        self.assertTrue(mfeq2(Ybus, mpYbus, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(Yf, mpYf, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(Yt, mpYt, diff=1e-12), self.case_name)

    def testB(self):
        """ Test FDPF B matrices.
        """
        self.case.index_buses()
        xbBp, xbBpp = self.case.makeB(method=XB)

        mpxbBp = mmread(join(DATA_DIR, self.case_name, "Bp_XB.mtx")).tocsr()
        mpxbBpp = mmread(join(DATA_DIR, self.case_name, "Bpp_XB.mtx")).tocsr()

        self.assertTrue(mfeq2(xbBp, mpxbBp, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(xbBpp, mpxbBpp, diff=1e-12), self.case_name)

        bxBp, bxBpp = self.case.makeB(method=BX)

        mpbxBp = mmread(join(DATA_DIR, self.case_name, "Bp_BX.mtx")).tocsr()
        mpbxBpp = mmread(join(DATA_DIR, self.case_name, "Bpp_BX.mtx")).tocsr()

        self.assertTrue(mfeq2(bxBp, mpbxBp, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(bxBpp, mpbxBpp, diff=1e-12), self.case_name)

    def testBdc(self):
        """ Test DCPF B matrices and phase shift injection vectors.
        """
        self.case.index_buses()
        B, Bf, Pbusinj, Pfinj = self.case.Bdc

        mpB = mmread(join(DATA_DIR, self.case_name, "B.mtx")).tocsr()
        self.assertTrue(mfeq2(B, mpB, diff=1e-12), self.case_name)

        mpBf = mmread(join(DATA_DIR, self.case_name, "Bf.mtx")).tocsr()
        self.assertTrue(mfeq2(Bf, mpBf, diff=1e-12), self.case_name)

        mpPbusinj = mmread(join(DATA_DIR, self.case_name,
                                "Pbusinj.mtx")).flatten()
        self.assertTrue(abs(max(Pbusinj - mpPbusinj)) < 1e-14, self.case_name)

        mpPfinj = mmread(join(DATA_DIR, self.case_name, "Pfinj.mtx")).flatten()
        self.assertTrue(abs(max(Pfinj - mpPfinj)) < 1e-14, self.case_name)

    def test_dSbus_dV(self):
        """ Test partial derivative of power injection w.r.t. voltage.
        """
        mpYbus = mmread(join(DATA_DIR, self.case_name, "Ybus.mtx")).tocsr()
        mpV0 = mmread(join(DATA_DIR, self.case_name, "V0.mtx")).flatten()

        dSbus_dVm, dSbus_dVa = self.case.dSbus_dV(mpYbus, mpV0)

        mp_dSbus_dVm = mmread(join(DATA_DIR, self.case_name, "dSbus_dVm0.mtx"))
        mp_dSbus_dVa = mmread(join(DATA_DIR, self.case_name, "dSbus_dVa0.mtx"))

        self.assertTrue(mfeq2(dSbus_dVm, mp_dSbus_dVm.tocsr(), 1e-12),
                        self.case_name)
        self.assertTrue(mfeq2(dSbus_dVa, mp_dSbus_dVa.tocsr(), 1e-12),
                        self.case_name)
Exemple #6
0
 def setUp(self):
     """ The test runner will execute this method prior to each test.
     """
     self.case = PickleReader().read(PWL_FILE)
Exemple #7
0
class CaseTest(unittest.TestCase):
    """ Defines a test case for the Pylon case.
    """
    def setUp(self):
        """ The test runner will execute this method prior to each test.
        """
        self.case = PickleReader().read(DATA_FILE)

    def test_reset(self):
        """ Test zeroing of result attributes.
        """
        case = self.case

        case.buses[5].p_lmbda = 1.1
        case.generators[2].mu_pmax = 1.1
        case.branches[10].p_from = 1.1

        case.reset()

        self.assertEqual(case.buses[5].p_lmbda, 0.0)
        self.assertEqual(case.generators[2].mu_pmax, 0.0)
        self.assertEqual(case.branches[10].p_from, 0.0)

    def test_sort_generators(self):
        """ Test ordering of generators according to bus index.
        """
        case = PickleReader().read(PWL_FILE)

        self.assertEqual(case.buses.index(case.generators[2].bus), 21)
        self.assertEqual(case.buses.index(case.generators[5].bus), 12)

        case.sort_generators()

        self.assertEqual(case.buses.index(case.generators[2].bus), 12)
        self.assertEqual(case.buses.index(case.generators[5].bus), 26)

    #--------------------------------------------------------------------------
    #  Serialisation tests.
    #--------------------------------------------------------------------------

    def test_load_matpower(self):
        """ Test loading a MATPOWER data file.
        """
        case = Case.load(MP_DATA_FILE, "matpower")

        self.assertEqual(len(case.generators), 3)
        self.assertTrue(isinstance(case, Case))

    def test_infer_matpower_format(self):
        """ Test inference of MATPOWER format from file extension.
        """
        case = Case.load(MP_DATA_FILE)  # Format not specified.

        self.assertEqual(len(case.generators), 3)
        self.assertTrue(isinstance(case, Case))

    def test_save_matpower(self):
        """ Test saving a case in MATPOWER format.
        """
        tmp_fd, tmp_name = tempfile.mkstemp(".m")
        os.close(tmp_fd)
        os.remove(tmp_name)
        #        os.unlink(tmp_name)

        self.assertFalse(exists(tmp_name))

        self.case.save(tmp_name)

        self.assertTrue(exists(tmp_name))
        self.assertTrue(getsize(tmp_name) > 0)
Exemple #8
0
 def setUp(self):
     """ The test runner will execute this method prior to each test.
     """
     path = join(DATA_DIR, self.case_name, self.case_name + ".pkl")
     self.case = PickleReader().read(path)
Exemple #9
0
class CaseMatrixTest(unittest.TestCase):
    """ Defines a test case for the Pylon case.
    """

    def __init__(self, methodName='runTest'):
        super(CaseMatrixTest, self).__init__(methodName)

        #: Name of the folder in which the MatrixMarket data exists.
        self.case_name = "case6ww"

        self.case = None


    def setUp(self):
        """ The test runner will execute this method prior to each test.
        """
        path = join(DATA_DIR, self.case_name, self.case_name + ".pkl")
        self.case = PickleReader().read(path)


    def testSbus(self):
        """ Test the vector of bus power injections.
        """
        Sbus = self.case.Sbus
        mpSbus = mmread(join(DATA_DIR, self.case_name, "Sbus.mtx")).flatten()

#        self.assertTrue(alltrue(Sbus == mpSbus))
        # FIXME: Improve accuracy.
        self.assertTrue(abs(max(Sbus - mpSbus)) < 1e-06, msg=self.case_name)


    def testYbus(self):
        """ Test bus and branch admittance matrices.
        """
        self.case.index_buses()
        Ybus, Yf, Yt = self.case.Y

        mpYbus = mmread(join(DATA_DIR, self.case_name, "Ybus.mtx")).tocsr()
        mpYf = mmread(join(DATA_DIR, self.case_name, "Yf.mtx")).tocsr()
        mpYt = mmread(join(DATA_DIR, self.case_name, "Yt.mtx")).tocsr()

        self.assertTrue(mfeq2(Ybus, mpYbus, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(Yf, mpYf, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(Yt, mpYt, diff=1e-12), self.case_name)


    def testB(self):
        """ Test FDPF B matrices.
        """
        self.case.index_buses()
        xbBp, xbBpp = self.case.makeB(method=XB)

        mpxbBp = mmread(join(DATA_DIR, self.case_name, "Bp_XB.mtx")).tocsr()
        mpxbBpp = mmread(join(DATA_DIR, self.case_name, "Bpp_XB.mtx")).tocsr()

        self.assertTrue(mfeq2(xbBp, mpxbBp, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(xbBpp, mpxbBpp, diff=1e-12), self.case_name)

        bxBp, bxBpp = self.case.makeB(method=BX)

        mpbxBp = mmread(join(DATA_DIR, self.case_name, "Bp_BX.mtx")).tocsr()
        mpbxBpp = mmread(join(DATA_DIR, self.case_name, "Bpp_BX.mtx")).tocsr()

        self.assertTrue(mfeq2(bxBp, mpbxBp, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(bxBpp, mpbxBpp, diff=1e-12), self.case_name)


    def testBdc(self):
        """ Test DCPF B matrices and phase shift injection vectors.
        """
        self.case.index_buses()
        B, Bf, Pbusinj, Pfinj = self.case.Bdc

        mpB = mmread(join(DATA_DIR, self.case_name, "B.mtx")).tocsr()
        self.assertTrue(mfeq2(B, mpB, diff=1e-12), self.case_name)

        mpBf = mmread(join(DATA_DIR, self.case_name, "Bf.mtx")).tocsr()
        self.assertTrue(mfeq2(Bf, mpBf, diff=1e-12), self.case_name)

        mpPbusinj = mmread(join(DATA_DIR, self.case_name,
                                "Pbusinj.mtx")).flatten()
        self.assertTrue(abs(max(Pbusinj - mpPbusinj)) < 1e-14, self.case_name)

        mpPfinj = mmread(join(DATA_DIR, self.case_name, "Pfinj.mtx")).flatten()
        self.assertTrue(abs(max(Pfinj - mpPfinj)) < 1e-14, self.case_name)


    def test_dSbus_dV(self):
        """ Test partial derivative of power injection w.r.t. voltage.
        """
        mpYbus = mmread(join(DATA_DIR, self.case_name, "Ybus.mtx")).tocsr()
        mpV0 = mmread(join(DATA_DIR, self.case_name, "V0.mtx")).flatten()

        dSbus_dVm, dSbus_dVa = self.case.dSbus_dV(mpYbus, mpV0)

        mp_dSbus_dVm = mmread(join(DATA_DIR, self.case_name, "dSbus_dVm0.mtx"))
        mp_dSbus_dVa = mmread(join(DATA_DIR, self.case_name, "dSbus_dVa0.mtx"))

        self.assertTrue(mfeq2(dSbus_dVm, mp_dSbus_dVm.tocsr(), 1e-12),
                        self.case_name)
        self.assertTrue(mfeq2(dSbus_dVa, mp_dSbus_dVa.tocsr(), 1e-12),
                        self.case_name)
Exemple #10
0
 def setUp(self):
     """ The test runner will execute this method prior to each test.
     """
     self.case = PickleReader().read(DATA_FILE)
Exemple #11
0
class CaseTest(unittest.TestCase):
    """ Defines a test case for the Pylon case.
    """

    def setUp(self):
        """ The test runner will execute this method prior to each test.
        """
        self.case = PickleReader().read(DATA_FILE)


    def test_reset(self):
        """ Test zeroing of result attributes.
        """
        case = self.case

        case.buses[5].p_lmbda = 1.1
        case.generators[2].mu_pmax = 1.1
        case.branches[10].p_from = 1.1

        case.reset()

        self.assertEqual(case.buses[5].p_lmbda, 0.0)
        self.assertEqual(case.generators[2].mu_pmax, 0.0)
        self.assertEqual(case.branches[10].p_from, 0.0)


    def test_sort_generators(self):
        """ Test ordering of generators according to bus index.
        """
        case = PickleReader().read(PWL_FILE)

        self.assertEqual(case.buses.index(case.generators[2].bus), 21)
        self.assertEqual(case.buses.index(case.generators[5].bus), 12)

        case.sort_generators()

        self.assertEqual(case.buses.index(case.generators[2].bus), 12)
        self.assertEqual(case.buses.index(case.generators[5].bus), 26)

    #--------------------------------------------------------------------------
    #  Serialisation tests.
    #--------------------------------------------------------------------------

    def test_load_matpower(self):
        """ Test loading a MATPOWER data file.
        """
        case = Case.load(MP_DATA_FILE, "matpower")

        self.assertEqual(len(case.generators), 3)
        self.assertTrue(isinstance(case, Case))


    def test_infer_matpower_format(self):
        """ Test inference of MATPOWER format from file extension.
        """
        case = Case.load(MP_DATA_FILE) # Format not specified.

        self.assertEqual(len(case.generators), 3)
        self.assertTrue(isinstance(case, Case))


    def test_save_matpower(self):
        """ Test saving a case in MATPOWER format.
        """
        tmp_fd, tmp_name = tempfile.mkstemp(".m")
        os.close(tmp_fd)
        os.remove(tmp_name)
#        os.unlink(tmp_name)

        self.assertFalse(exists(tmp_name))

        self.case.save(tmp_name)

        self.assertTrue(exists(tmp_name))
        self.assertTrue(getsize(tmp_name) > 0)