示例#1
0
    def test_force_masked(self):
        a = np.arange(0, 24, dtype=np.int32)
        a.shape = 4, 6
        source_image = FastNdarrayDownsamplingImage(a,
                                                    tile_size=(2, 2),
                                                    num_levels=1,
                                                    z_index=0)
        target_image = TransformArrayImage(source_image,
                                           force_masked=True,
                                           no_data_value=14)

        self.assertEqual(target_image.size, (6, 4))
        self.assertEqual(target_image.num_tiles, (3, 2))
        self.assertEqual(target_image.num_tiles, (3, 2))

        self.assertEqual(
            target_image.get_tile(0, 0).tolist(), [[0, 1], [6, 7]])
        self.assertEqual(
            target_image.get_tile(1, 0).tolist(), [[2, 3], [8, 9]])
        self.assertEqual(
            target_image.get_tile(2, 0).tolist(), [[4, 5], [10, 11]])

        self.assertEqual(
            target_image.get_tile(0, 1).tolist(), [[12, 13], [18, 19]])
        self.assertEqual(
            target_image.get_tile(1, 1).tolist(), [[None, 15], [20, 21]])
        self.assertEqual(
            target_image.get_tile(2, 1).tolist(), [[16, 17], [22, 23]])

        a = np.arange(0, 24, dtype=np.float64)
        a.shape = 4, 6
        a[1, 2] = np.nan
        a[2, 5] = np.inf
        source_image = FastNdarrayDownsamplingImage(a,
                                                    tile_size=(2, 2),
                                                    num_levels=1,
                                                    z_index=0)
        target_image = TransformArrayImage(source_image, force_masked=True)

        self.assertEqual(target_image.size, (6, 4))
        self.assertEqual(target_image.num_tiles, (3, 2))

        self.assertEqual(
            target_image.get_tile(0, 0).tolist(), [[0, 1], [6, 7]])
        self.assertEqual(
            target_image.get_tile(1, 0).tolist(), [[2, 3], [None, 9]])
        self.assertEqual(
            target_image.get_tile(2, 0).tolist(), [[4, 5], [10, 11]])

        self.assertEqual(
            target_image.get_tile(0, 1).tolist(), [[12, 13], [18, 19]])
        self.assertEqual(
            target_image.get_tile(1, 1).tolist(), [[14, 15], [20, 21]])
        self.assertEqual(
            target_image.get_tile(2, 1).tolist(), [[16, None], [22, 23]])
示例#2
0
    def test_flip_y(self):
        a = np.arange(0, 24, dtype=np.int32)
        a.shape = 4, 6
        source_image = FastNdarrayDownsamplingImage(a,
                                                    tile_size=(2, 2),
                                                    num_levels=1,
                                                    z_index=0)
        target_image = TransformArrayImage(source_image, flip_y=True)

        self.assertEqual(target_image.size, (6, 4))
        self.assertEqual(target_image.num_tiles, (3, 2))
        self.assertEqual(target_image.num_tiles, (3, 2))

        self.assertEqual(
            target_image.get_tile(0, 0).tolist(), [[18, 19], [12, 13]])
        self.assertEqual(
            target_image.get_tile(1, 0).tolist(), [[20, 21], [14, 15]])
        self.assertEqual(
            target_image.get_tile(2, 0).tolist(), [[22, 23], [16, 17]])

        self.assertEqual(
            target_image.get_tile(0, 1).tolist(), [[6, 7], [0, 1]])
        self.assertEqual(
            target_image.get_tile(1, 1).tolist(), [[8, 9], [2, 3]])
        self.assertEqual(
            target_image.get_tile(2, 1).tolist(), [[10, 11], [4, 5]])
示例#3
0
 def test_pad_tile(self):
     a = np.arange(0, 6, dtype=np.float32)
     a.shape = 2, 3
     b = FastNdarrayDownsamplingImage.pad_tile(a, (3, 2))
     np.testing.assert_equal(b, np.array([[0., 1., 2.],
                                          [3., 4., 5.]]))
     b = FastNdarrayDownsamplingImage.pad_tile(a, (4, 2))
     np.testing.assert_equal(b, np.array([[0., 1., 2., np.nan],
                                          [3., 4., 5., np.nan]]))
     b = FastNdarrayDownsamplingImage.pad_tile(a, (3, 3))
     np.testing.assert_equal(b, np.array([[0., 1., 2.],
                                          [3., 4., 5.],
                                          [np.nan, np.nan, np.nan]]))
     b = FastNdarrayDownsamplingImage.pad_tile(a, (4, 3))
     np.testing.assert_equal(b, np.array([[0., 1., 2., np.nan],
                                          [3., 4., 5., np.nan],
                                          [np.nan, np.nan, np.nan, np.nan]]))
示例#4
0
 def test_pad_tile(self):
     a = np.arange(0, 6, dtype=np.float32)
     a.shape = 2, 3
     b = FastNdarrayDownsamplingImage.pad_tile(a, (3, 2))
     np.testing.assert_equal(b, np.array([[0., 1., 2.], [3., 4., 5.]]))
     b = FastNdarrayDownsamplingImage.pad_tile(a, (4, 2))
     np.testing.assert_equal(
         b, np.array([[0., 1., 2., np.nan], [3., 4., 5., np.nan]]))
     b = FastNdarrayDownsamplingImage.pad_tile(a, (3, 3))
     np.testing.assert_equal(
         b, np.array([[0., 1., 2.], [3., 4., 5.], [np.nan, np.nan,
                                                   np.nan]]))
     b = FastNdarrayDownsamplingImage.pad_tile(a, (4, 3))
     np.testing.assert_equal(
         b,
         np.array([[0., 1., 2., np.nan], [3., 4., 5., np.nan],
                   [np.nan, np.nan, np.nan, np.nan]]))
示例#5
0
    def test_force_2d(self):
        a = np.arange(0, 48, dtype=np.int32)
        a.shape = 2, 4, 6
        source_image = FastNdarrayDownsamplingImage(a, (2, 2), 0)
        target_image = TransformArrayImage(source_image, force_2d=True)

        self.assertEqual(target_image.size, (6, 4))
        self.assertEqual(target_image.tile_size, (2, 2))
        self.assertEqual(target_image.num_tiles, (3, 2))
示例#6
0
    def test_level_2(self):
        a = np.arange(0, 16 * 24, dtype=np.int32)
        a.shape = 16, 24
        source_image = FastNdarrayDownsamplingImage(a, (2, 2), 2)
        target_image = TransformArrayImage(source_image)

        self.assertEqual(target_image.size, (6, 4))
        self.assertEqual(target_image.tile_size, (2, 2))
        self.assertEqual(target_image.num_tiles, (3, 2))

        self.assertEqual(
            target_image.get_tile(0, 0).tolist(), [[0, 4], [96, 100]])
        self.assertEqual(
            target_image.get_tile(1, 0).tolist(), [[8, 12], [104, 108]])
        self.assertEqual(
            target_image.get_tile(2, 0).tolist(), [[16, 20], [112, 116]])

        self.assertEqual(
            target_image.get_tile(0, 1).tolist(), [[192, 196], [288, 292]])
        self.assertEqual(
            target_image.get_tile(1, 1).tolist(), [[200, 204], [296, 300]])
        self.assertEqual(
            target_image.get_tile(2, 1).tolist(), [[208, 212], [304, 308]])
示例#7
0
    def test_default(self):
        a = np.arange(0, 24, dtype=np.int32)
        a.shape = 4, 6
        source_image = FastNdarrayDownsamplingImage(a, (2, 2), 0)
        target_image = TransformArrayImage(source_image)

        self.assertEqual(target_image.size, (6, 4))
        self.assertEqual(target_image.tile_size, (2, 2))
        self.assertEqual(target_image.num_tiles, (3, 2))

        self.assertEqual(
            target_image.get_tile(0, 0).tolist(), [[0, 1], [6, 7]])
        self.assertEqual(
            target_image.get_tile(1, 0).tolist(), [[2, 3], [8, 9]])
        self.assertEqual(
            target_image.get_tile(2, 0).tolist(), [[4, 5], [10, 11]])

        self.assertEqual(
            target_image.get_tile(0, 1).tolist(), [[12, 13], [18, 19]])
        self.assertEqual(
            target_image.get_tile(1, 1).tolist(), [[14, 15], [20, 21]])
        self.assertEqual(
            target_image.get_tile(2, 1).tolist(), [[16, 17], [22, 23]])