Esempio n. 1
0
    def test_timebase_conversions(self, tsys):
        '''Check to make sure timebases transfer properly'''
        tf1 = TransferFunction([1, 1], [1, 2, 3], None)  # unspecified
        tf2 = TransferFunction([1, 1], [1, 2, 3], 0)     # cont time
        tf3 = TransferFunction([1, 1], [1, 2, 3], True)  # dtime, unspec
        tf4 = TransferFunction([1, 1], [1, 2, 3], .1)    # dtime, dt=.1

        # Make sure unspecified timebase is converted correctly
        assert timebase(tf1*tf1) == timebase(tf1)
        assert timebase(tf1*tf2) == timebase(tf2)
        assert timebase(tf1*tf3) == timebase(tf3)
        assert timebase(tf1*tf4) == timebase(tf4)
        assert timebase(tf3*tf4) == timebase(tf4)
        assert timebase(tf2*tf1) == timebase(tf2)
        assert timebase(tf3*tf1) == timebase(tf3)
        assert timebase(tf4*tf1) == timebase(tf4)
        assert timebase(tf1+tf1) == timebase(tf1)
        assert timebase(tf1+tf2) == timebase(tf2)
        assert timebase(tf1+tf3) == timebase(tf3)
        assert timebase(tf1+tf4) == timebase(tf4)
        assert timebase(feedback(tf1, tf1)) == timebase(tf1)
        assert timebase(feedback(tf1, tf2)) == timebase(tf2)
        assert timebase(feedback(tf1, tf3)) == timebase(tf3)
        assert timebase(feedback(tf1, tf4)) == timebase(tf4)

        # Make sure discrete time without sampling is converted correctly
        assert timebase(tf3*tf3) == timebase(tf3)
        assert timebase(tf3*tf4) == timebase(tf4)
        assert timebase(tf3+tf3) == timebase(tf3)
        assert timebase(tf3+tf4) == timebase(tf4)
        assert timebase(feedback(tf3, tf3)) == timebase(tf3)
        assert timebase(feedback(tf3, tf4)) == timebase(tf4)

        # Make sure all other combinations are errors
        with pytest.raises(ValueError, match="incompatible timebases"):
            tf2 * tf3
        with pytest.raises(ValueError, match="incompatible timebases"):
            tf3 * tf2
        with pytest.raises(ValueError, match="incompatible timebases"):
            tf2 * tf4
        with pytest.raises(ValueError, match="incompatible timebases"):
            tf4 * tf2
        with pytest.raises(ValueError, match="incompatible timebases"):
            tf2 + tf3
        with pytest.raises(ValueError, match="incompatible timebases"):
            tf3 + tf2
        with pytest.raises(ValueError, match="incompatible timebases"):
            tf2 + tf4
        with pytest.raises(ValueError, match="incompatible timebases"):
            tf4 + tf2
        with pytest.raises(ValueError, match="incompatible timebases"):
            feedback(tf2, tf3)
        with pytest.raises(ValueError, match="incompatible timebases"):
            feedback(tf3, tf2)
        with pytest.raises(ValueError, match="incompatible timebases"):
            feedback(tf2, tf4)
        with pytest.raises(ValueError, match="incompatible timebases"):
            feedback(tf4, tf2)
Esempio n. 2
0
    def test_timebase_conversions(self):
        '''Check to make sure timebases transfer properly'''
        tf1 = TransferFunction([1, 1], [1, 2, 3])  # unspecified
        tf2 = TransferFunction([1, 1], [1, 2, 3], 0)  # cont time
        tf3 = TransferFunction([1, 1], [1, 2, 3], True)  # dtime, unspec
        tf4 = TransferFunction([1, 1], [1, 2, 3], 1)  # dtime, dt=1

        # Make sure unspecified timebase is converted correctly
        self.assertEqual(timebase(tf1 * tf1), timebase(tf1))
        self.assertEqual(timebase(tf1 * tf2), timebase(tf2))
        self.assertEqual(timebase(tf1 * tf3), timebase(tf3))
        self.assertEqual(timebase(tf1 * tf4), timebase(tf4))
        self.assertEqual(timebase(tf2 * tf1), timebase(tf2))
        self.assertEqual(timebase(tf3 * tf1), timebase(tf3))
        self.assertEqual(timebase(tf4 * tf1), timebase(tf4))
        self.assertEqual(timebase(tf1 + tf1), timebase(tf1))
        self.assertEqual(timebase(tf1 + tf2), timebase(tf2))
        self.assertEqual(timebase(tf1 + tf3), timebase(tf3))
        self.assertEqual(timebase(tf1 + tf4), timebase(tf4))
        self.assertEqual(timebase(feedback(tf1, tf1)), timebase(tf1))
        self.assertEqual(timebase(feedback(tf1, tf2)), timebase(tf2))
        self.assertEqual(timebase(feedback(tf1, tf3)), timebase(tf3))
        self.assertEqual(timebase(feedback(tf1, tf4)), timebase(tf4))

        # Make sure discrete time without sampling is converted correctly
        self.assertEqual(timebase(tf3 * tf3), timebase(tf3))
        self.assertEqual(timebase(tf3 * tf4), timebase(tf4))
        self.assertEqual(timebase(tf3 + tf3), timebase(tf3))
        self.assertEqual(timebase(tf3 + tf3), timebase(tf4))
        self.assertEqual(timebase(feedback(tf3, tf3)), timebase(tf3))
        self.assertEqual(timebase(feedback(tf3, tf4)), timebase(tf4))

        # Make sure all other combinations are errors
        try:
            tf2 * tf3  # Error; incompatible timebases
            raise ValueError("incompatible operation allowed")
        except ValueError:
            pass
        try:
            tf2 * tf4  # Error; incompatible timebases
            raise ValueError("incompatible operation allowed")
        except ValueError:
            pass
        try:
            tf2 + tf3  # Error; incompatible timebases
            raise ValueError("incompatible operation allowed")
        except ValueError:
            pass
        try:
            tf2 + tf4  # Error; incompatible timebases
            raise ValueError("incompatible operation allowed")
        except ValueError:
            pass
        try:
            feedback(tf2, tf3)  # Error; incompatible timebases
            raise ValueError("incompatible operation allowed")
        except ValueError:
            pass
        try:
            feedback(tf2, tf4)  # Error; incompatible timebases
            raise ValueError("incompatible operation allowed")
        except ValueError:
            pass
Esempio n. 3
0
 def test_timebase(self, tsys):
     assert timebase(1) is None
     with pytest.raises(ValueError):
         timebase([1, 2])
     assert timebase(tsys.siso_ss1, strict=False) is None
     assert timebase(tsys.siso_ss1, strict=True) is None
     assert timebase(tsys.siso_ss1c) == 0
     assert timebase(tsys.siso_ss1d) == 0.1
     assert timebase(tsys.siso_ss2d) == 0.2
     assert timebase(tsys.siso_ss3d)
     assert timebase(tsys.siso_ss3d, strict=False) == 1
     assert timebase(tsys.siso_tf1, strict=False) is None
     assert timebase(tsys.siso_tf1, strict=True) is None
     assert timebase(tsys.siso_tf1c) == 0
     assert timebase(tsys.siso_tf1d) == 0.1
     assert timebase(tsys.siso_tf2d) == 0.2
     assert timebase(tsys.siso_tf3d)
     assert timebase(tsys.siso_tf3d, strict=False) == 1
Esempio n. 4
0
 def test_timebase(self):
     self.assertEqual(timebase(1), None)
     self.assertRaises(ValueError, timebase, [1, 2])
     self.assertEqual(timebase(self.siso_ss1, strict=False), None)
     self.assertEqual(timebase(self.siso_ss1, strict=True), None)
     self.assertEqual(timebase(self.siso_ss1c), 0)
     self.assertEqual(timebase(self.siso_ss1d), 0.1)
     self.assertEqual(timebase(self.siso_ss2d), 0.2)
     self.assertEqual(timebase(self.siso_ss3d), True)
     self.assertEqual(timebase(self.siso_ss3d, strict=False), 1)
     self.assertEqual(timebase(self.siso_tf1, strict=False), None)
     self.assertEqual(timebase(self.siso_tf1, strict=True), None)
     self.assertEqual(timebase(self.siso_tf1c), 0)
     self.assertEqual(timebase(self.siso_tf1d), 0.1)
     self.assertEqual(timebase(self.siso_tf2d), 0.2)
     self.assertEqual(timebase(self.siso_tf3d), True)
     self.assertEqual(timebase(self.siso_tf3d, strict=False), 1)