Пример #1
0
    def test_PermMapMatched(self):
        """Test a PermMap whose inverse is the inverse of its forward
        """
        permmap = ast.PermMap([2, 3, 1], [3, 1, 2])
        self.assertEqual(permmap.className, "PermMap")
        self.assertEqual(permmap.nIn, 3)
        self.assertEqual(permmap.nOut, 3)

        self.checkBasicSimplify(permmap)
        self.checkCopy(permmap)

        indata = np.array([
            [1.1, -43.5],
            [2.2, 1309.31],
            [3.3, 0.005],
        ])
        outdata = permmap.applyForward(indata)
        pred_outdata = np.array([
            [3.3, 0.005],
            [1.1, -43.5],
            [2.2, 1309.31],
        ])
        assert_allclose(outdata, pred_outdata)

        self.checkRoundTrip(permmap, indata)
        self.checkMappingPersistence(permmap, indata)
Пример #2
0
    def test_FrameDictPermutationUnequal(self):
        """Test permuting FrameDict axes with nIn != nOut

        Permuting the axes of the current frame of a frame set
        *in situ* (by calling `permAxes` on the frame set itself)
        should update the connected mappings.

        Make nIn != nOut in order to test DM-9899
        FrameDict.permAxes would fail if nIn != nOut
        """
        # Initial mapping: 3 inputs, 2 outputs: 1-1, 2-2, 3=z
        # Test using arbitrary values for x,y,z
        x = 75.1
        y = -53.2
        z = 0.123
        frame1 = ast.Frame(3)
        permMap = ast.PermMap([1, 2, -1], [1, 2], [z])
        frame2 = ast.Frame(2)
        frameDict = ast.FrameDict(frame1, permMap, frame2)
        self.assertAlmostEqual(frameDict.applyForward([x, y, z]), [x, y])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [x, y, z])

        # permuting the axes of the current frame also permutes the mapping
        frameDict.permAxes([2, 1])
        self.assertAlmostEqual(frameDict.applyForward([x, y, z]), [y, x])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [y, x, z])

        # permuting again puts things back
        frameDict.permAxes([2, 1])
        self.assertAlmostEqual(frameDict.applyForward([x, y, z]), [x, y])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [x, y, z])
Пример #3
0
    def test_PermMapWithConstants(self):
        """Test a PermMap with constant values
        """
        permmap = astshim.PermMap([-2, 1, 3], [2, 1, -1], [75.3, -126.5])
        self.assertEqual(permmap.className, "PermMap")
        self.assertEqual(permmap.nIn, 3)
        self.assertEqual(permmap.nOut, 3)

        indata = np.array([1.1, 2.2, 3.3])
        outdata = permmap.applyForward(indata)
        assert_allclose(outdata, [2.2, 1.1, 75.3])

        outdata2 = permmap.applyInverse(indata)
        assert_allclose(outdata2, [-126.5, 1.1, 3.3])
Пример #4
0
    def test_PermMapUnmatched(self):
        """Test PermMap with different number of inputs and outputs
        """
        permmap = ast.PermMap([2, 1, 3], [3, 1])
        self.assertEqual(permmap.className, "PermMap")
        self.assertEqual(permmap.nIn, 3)
        self.assertEqual(permmap.nOut, 2)

        indata = np.array([1.1, 2.2, -3.3])
        outdata = permmap.applyForward(indata)
        assert_allclose(outdata, [-3.3, 1.1])

        indata2 = np.array([1.1, 2.2])
        outdata2 = permmap.applyInverse(indata2)
        assert_allclose(outdata2, [2.2, 1.1, np.nan], equal_nan=True)

        self.checkMappingPersistence(permmap, indata)