Exemplo n.º 1
0
    def test_create_control_grid(self):
        with self.assertRaisesRegex(TypeError, ''):
            create_control_grid(None, None)
        with self.assertRaisesRegex(TypeError, ''):
            create_control_grid((1, 1), 2.)

        g = create_control_grid((1., 1.), (1., 1.))
        expected = np.array([
            [[-1., -1., -1.], [0., 0., 0.], [1., 1., 1.]],
            [[-1., 0., 1.], [-1., 0., 1.], [-1., 0., 1.]],
            [[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]],
        ])
        np.testing.assert_allclose(g, expected)

        g = create_control_grid((1., 1.), (2., 2.))
        expected = np.array([
            [[-2., -2., -2.], [0., 0., 0.], [2., 2., 2.]],
            [[-2., 0., 2.], [-2., 0., 2.], [-2., 0., 2.]],
            [[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]],
        ])
        np.testing.assert_allclose(g, expected)

        g = create_control_grid((2., 2.), (1., 1.))
        expected = np.array([
            [[-1.5, -1.5, -1.5, -1.5], [-0.5, -0.5, -0.5, -0.5],
             [0.5, 0.5, 0.5, 0.5], [1.5, 1.5, 1.5, 1.5]],
            [[-1.5, -0.5, 0.5, 1.5], [-1.5, -0.5, 0.5, 1.5],
             [-1.5, -0.5, 0.5, 1.5], [-1.5, -0.5, 0.5, 1.5]],
            [[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.],
             [1., 1., 1., 1.]],
        ])
        np.testing.assert_allclose(g, expected)

        g = create_control_grid((2., 2.), (2., 2.))
        expected = np.array([
            [[-3., -3., -3., -3.], [-1., -1., -1., -1.], [1., 1., 1., 1.],
             [3., 3., 3., 3.]],
            [[-3., -1., 1., 3.], [-3., -1., 1., 3.], [-3., -1., 1., 3.],
             [-3., -1., 1., 3.]],
            [[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.],
             [1., 1., 1., 1.]],
        ])
        np.testing.assert_allclose(g, expected)

        g = create_control_grid((1., 1., 1.), (2., 2., 2.), homogeneous=False)
        expected = np.array([[[[-2., -2., -2.], [-2., -2., -2.],
                               [-2., -2., -2.]],
                              [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]],
                              [[2., 2., 2.], [2., 2., 2.], [2., 2., 2.]]],
                             [[[-2., -2., -2.], [0., 0., 0.], [2., 2., 2.]],
                              [[-2., -2., -2.], [0., 0., 0.], [2., 2., 2.]],
                              [[-2., -2., -2.], [0., 0., 0.], [2., 2., 2.]]],
                             [[[-2., 0., 2.], [-2., 0., 2.], [-2., 0., 2.]],
                              [[-2., 0., 2.], [-2., 0., 2.], [-2., 0., 2.]],
                              [[-2., 0., 2.], [-2., 0., 2.], [-2., 0., 2.]]]])
        np.testing.assert_allclose(g, expected)
Exemplo n.º 2
0
    def test_create_control_grid(self):
        with self.assertRaisesRegex(TypeError, ""):
            create_control_grid(None, None)
        with self.assertRaisesRegex(TypeError, ""):
            create_control_grid((1, 1), 2.0)

        test_assert(
            create_control_grid,
            ((1.0, 1.0), (1.0, 1.0)),
            np.array(
                [
                    [[-1.0, -1.0, -1.0], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]],
                    [[-1.0, 0.0, 1.0], [-1.0, 0.0, 1.0], [-1.0, 0.0, 1.0]],
                    [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]],
                ]
            ),
        )

        test_assert(
            create_control_grid,
            ((1.0, 1.0), (2.0, 2.0)),
            np.array(
                [
                    [[-2.0, -2.0, -2.0], [0.0, 0.0, 0.0], [2.0, 2.0, 2.0]],
                    [[-2.0, 0.0, 2.0], [-2.0, 0.0, 2.0], [-2.0, 0.0, 2.0]],
                    [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]],
                ]
            ),
        )

        test_assert(
            create_control_grid,
            ((2.0, 2.0), (1.0, 1.0)),
            np.array(
                [
                    [[-1.5, -1.5, -1.5, -1.5], [-0.5, -0.5, -0.5, -0.5], [0.5, 0.5, 0.5, 0.5], [1.5, 1.5, 1.5, 1.5]],
                    [[-1.5, -0.5, 0.5, 1.5], [-1.5, -0.5, 0.5, 1.5], [-1.5, -0.5, 0.5, 1.5], [-1.5, -0.5, 0.5, 1.5]],
                    [[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]],
                ]
            ),
        )

        test_assert(
            create_control_grid,
            ((2.0, 2.0), (2.0, 2.0)),
            np.array(
                [
                    [[-3.0, -3.0, -3.0, -3.0], [-1.0, -1.0, -1.0, -1.0], [1.0, 1.0, 1.0, 1.0], [3.0, 3.0, 3.0, 3.0]],
                    [[-3.0, -1.0, 1.0, 3.0], [-3.0, -1.0, 1.0, 3.0], [-3.0, -1.0, 1.0, 3.0], [-3.0, -1.0, 1.0, 3.0]],
                    [[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]],
                ]
            ),
        )

        test_assert(
            create_control_grid,
            ((1.0, 1.0, 1.0), (2.0, 2.0, 2.0), False),
            np.array(
                [
                    [
                        [[-2.0, -2.0, -2.0], [-2.0, -2.0, -2.0], [-2.0, -2.0, -2.0]],
                        [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                        [[2.0, 2.0, 2.0], [2.0, 2.0, 2.0], [2.0, 2.0, 2.0]],
                    ],
                    [
                        [[-2.0, -2.0, -2.0], [0.0, 0.0, 0.0], [2.0, 2.0, 2.0]],
                        [[-2.0, -2.0, -2.0], [0.0, 0.0, 0.0], [2.0, 2.0, 2.0]],
                        [[-2.0, -2.0, -2.0], [0.0, 0.0, 0.0], [2.0, 2.0, 2.0]],
                    ],
                    [
                        [[-2.0, 0.0, 2.0], [-2.0, 0.0, 2.0], [-2.0, 0.0, 2.0]],
                        [[-2.0, 0.0, 2.0], [-2.0, 0.0, 2.0], [-2.0, 0.0, 2.0]],
                        [[-2.0, 0.0, 2.0], [-2.0, 0.0, 2.0], [-2.0, 0.0, 2.0]],
                    ],
                ]
            ),
        )