Exemple #1
0
 def test_default(self):
     a = np.linspace(0, 255, 24, dtype=np.int32).reshape((4, 6))
     b = np.linspace(255, 0, 24, dtype=np.int32).reshape((4, 6))
     c = np.linspace(50, 200, 24, dtype=np.int32).reshape((4, 6))
     source_images = [
         SourceArrayImage(a, (2, 2)),
         SourceArrayImage(b, (2, 2)),
         SourceArrayImage(c, (2, 2)),
     ]
     cm_rgb_image = DirectRgbaImage(source_images, format='PNG')
     self.assertEqual(cm_rgb_image.size, (6, 4))
     self.assertEqual(cm_rgb_image.tile_size, (2, 2))
     self.assertEqual(cm_rgb_image.num_tiles, (3, 2))
     tile = cm_rgb_image.get_tile(0, 0)
     self.assertIsInstance(tile, PIL.Image.Image)
Exemple #2
0
def new_rgb_image(ml_dataset: MultiLevelDataset, image_id: str,
                  var_names: Tuple[str, ...],
                  norm_ranges: Tuple[Number, Number], z: int, labels,
                  labels_are_indices, tile_cache, trace_perf, exception_type):
    tile_grid = ml_dataset.tile_grid
    images = []
    for i in range(3):
        var_name = var_names[i]
        array, _, _ = \
            _get_var_2d_array_and_mask_info(
                ml_dataset, var_name, z, labels,
                labels_are_indices,
                exception_type
            )

        image = SourceArrayImage(array,
                                 image_id=f'ai-{image_id}',
                                 tile_size=tile_grid.tile_size,
                                 flip_y=tile_grid.is_j_axis_up,
                                 trace_perf=trace_perf)
        image = NormalizeArrayImage(image,
                                    image_id=f'tai-{image_id}',
                                    norm_range=norm_ranges[i],
                                    trace_perf=trace_perf)
        images.append(image)

    return DirectRgbaImage((images[0], images[1], images[2]),
                           image_id=f'drgba-{image_id}',
                           encode=True,
                           format='PNG',
                           tile_cache=tile_cache,
                           trace_perf=trace_perf)
Exemple #3
0
    def test_force_2d(self):
        a = np.arange(0, 48, dtype=np.int32).reshape((2, 4, 6))
        source_image = SourceArrayImage(a[0], (2, 2))
        target_image = NormalizeArrayImage(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))
Exemple #4
0
 def test_default(self):
     a = np.linspace(0, 255, 24, dtype=np.int32).reshape((4, 6))
     source_image = SourceArrayImage(a, (2, 2))
     cm_rgb_image = ColorMappedRgbaImage(source_image, format='PNG')
     self.assertEqual(cm_rgb_image.size, (6, 4))
     self.assertEqual(cm_rgb_image.tile_size, (2, 2))
     self.assertEqual(cm_rgb_image.num_tiles, (3, 2))
     tile = cm_rgb_image.get_tile(0, 0)
     self.assertIsInstance(tile, PIL.Image.Image)
Exemple #5
0
    def test_flip_y_tiled_evenly(self):
        a = np.arange(0, 24, dtype=np.int32).reshape((4, 6))
        source_array_image = SourceArrayImage(a, (2, 2), flip_y=True)

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

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

        self.assertEqual(
            source_array_image.get_tile(0, 1).tolist(), [[6, 7], [0, 1]])
        self.assertEqual(
            source_array_image.get_tile(1, 1).tolist(), [[8, 9], [2, 3]])
        self.assertEqual(
            source_array_image.get_tile(2, 1).tolist(), [[10, 11], [4, 5]])
Exemple #6
0
    def test_default(self):
        a = np.arange(0, 24, dtype=np.int32).reshape((4, 6))
        source_image = SourceArrayImage(a, (2, 2))
        target_image = NormalizeArrayImage(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]])
Exemple #7
0
def new_color_mapped_image(ml_dataset: MultiLevelDataset, image_id: str,
                           var_name: str, cmap_name: str,
                           cmap_range: Tuple[float,
                                             float], z: int, labels: Dict[str,
                                                                          Any],
                           labels_are_indices: bool, tile_cache, trace_perf,
                           exception_type: Type[Exception]):
    array, valid_range, var = \
        _get_var_2d_array_and_mask_info(
            ml_dataset, var_name, z, labels,
            labels_are_indices,
            exception_type
        )
    cmap_name, cmap_range = get_var_cmap_params(var, cmap_name, cmap_range,
                                                valid_range)
    tile_grid = ml_dataset.tile_grid
    image = SourceArrayImage(array,
                             image_id=f'ai-{image_id}',
                             tile_size=tile_grid.tile_size,
                             flip_y=tile_grid.is_j_axis_up,
                             trace_perf=trace_perf)
    image = NormalizeArrayImage(image,
                                image_id=f'tai-{image_id}',
                                norm_range=cmap_range,
                                trace_perf=trace_perf)
    if cmap_name is None and cmap_range is None:
        # TODO: Return a ColorMappedRawImage(...) whose tiles
        #   are binary, compressed numpy arrays
        return image
    return ColorMappedRgbaImage(image,
                                image_id=f'cmrgbai-{image_id}',
                                cmap_name=cmap_name,
                                encode=True,
                                format='PNG',
                                tile_cache=tile_cache,
                                trace_perf=trace_perf)
Exemple #8
0
    def test_flip_y_not_tiled_evenly(self):
        a = np.arange(0, 30, dtype=np.int32).reshape((5, 6))
        source_array_image = SourceArrayImage(a, (2, 2), flip_y=True)

        self.assertEqual(source_array_image.size, (6, 5))
        self.assertEqual(source_array_image.tile_size, (2, 2))
        self.assertEqual(source_array_image.num_tiles, (3, 3))

        self.assertEqual(
            source_array_image.get_tile(0, 0).tolist(), [[24, 25], [18, 19]])
        self.assertEqual(
            source_array_image.get_tile(1, 0).tolist(), [[26, 27], [20, 21]])
        self.assertEqual(
            source_array_image.get_tile(2, 0).tolist(), [[28, 29], [22, 23]])

        self.assertEqual(
            source_array_image.get_tile(0, 1).tolist(), [[12, 13], [6, 7]])
        self.assertEqual(
            source_array_image.get_tile(1, 1).tolist(), [[14, 15], [8, 9]])
        self.assertEqual(
            source_array_image.get_tile(2, 1).tolist(), [[16, 17], [10, 11]])

        tile_0_2 = source_array_image.get_tile(0, 2).tolist()
        self.assertEqual(tile_0_2[0], [0, 1])
        self.assertTrue(np.isnan(tile_0_2[1][0]))
        self.assertTrue(np.isnan(tile_0_2[1][1]))
        tile_1_2 = source_array_image.get_tile(1, 2).tolist()
        self.assertEqual(tile_1_2[0], [2, 3])
        self.assertTrue(tile_1_2[1][0])
        self.assertTrue(tile_1_2[1][1])
        tile_2_2 = source_array_image.get_tile(2, 2).tolist()
        self.assertEqual(tile_2_2[0], [4, 5])
        self.assertTrue(tile_2_2[1][0])
        self.assertTrue(tile_2_2[1][1])