예제 #1
0
    def test_h5py_raw_pyramid_fast(self):
        pyramid = ImagePyramid.create_from_array(self.dataset, tile_size=(270, 270))
        self.assertEqual((270, 270), pyramid.tile_size)
        self.assertEqual((2, 1), pyramid.num_level_zero_tiles)
        self.assertEqual(5, pyramid.num_levels)

        level_image = pyramid.get_level_image(0)

        t1 = time.clock()
        tile00 = level_image.get_tile(0, 0)
        tile10 = level_image.get_tile(1, 0)
        t2 = time.clock()
        print("ndarray fast pyramid took: ", t2 - t1)
예제 #2
0
    def test_h5py_raw_pyramid_fast(self):
        pyramid = ImagePyramid.create_from_array(self.dataset,
                                                 tile_size=(270, 270))
        self.assertEqual((270, 270), pyramid.tile_size)
        self.assertEqual((2, 1), pyramid.num_level_zero_tiles)
        self.assertEqual(5, pyramid.num_levels)

        level_image = pyramid.get_level_image(0)

        t1 = time.clock()
        tile00 = level_image.get_tile(0, 0)
        tile10 = level_image.get_tile(1, 0)
        t2 = time.clock()
        print("ndarray fast pyramid took: ", t2 - t1)
예제 #3
0
    def on_get(self, req, resp, z, y, x):
        GLOBAL_LOCK.acquire()

        file_path = _get_file_from_req(req)
        dataset = _open_dataset(file_path)

        var_name = req.get_param('var', required=True)
        cmap_name = req.get_param('cmap', default='jet')
        cmap_min = _get_param_as_float(req, 'min', default=0.0)
        cmap_max = _get_param_as_float(req, 'max', default=1.0)

        image_id = '%s|%s|%s|%s|%s' % (file_path, var_name, cmap_name,
                                       cmap_min, cmap_max)

        global PYRAMIDS
        if image_id in PYRAMIDS:
            pyramid = PYRAMIDS[image_id]
        else:
            variable = dataset[var_name]

            pyramid = ImagePyramid.create_from_array(variable.values)
            pyramid = pyramid.apply(lambda image: TransformArrayImage(
                image,
                # no_data_value=variable.fillvalue,
                force_masked=True,
                flip_y=is_y_flipped(variable)))
            pyramid = pyramid.apply(lambda image: ColorMappedRgbaImage(
                image,
                value_range=(cmap_min, cmap_max),
                cmap_name=cmap_name,
                encode=True,
                format='PNG'))
            PYRAMIDS[image_id] = pyramid
            print('num_level_zero_tiles:', pyramid.num_level_zero_tiles)
            print('num_levels:', pyramid.num_levels)

        print('PERF: >>> Tile:', current_thread(), file_path, var_name,
              cmap_name, z, y, x)

        t1 = time.clock()
        tile = pyramid.get_tile(int(x), int(y), int(z))
        t2 = time.clock()

        resp.data = tile
        resp.content_type = 'image/png'
        resp.status = falcon.HTTP_OK

        print('PERF: <<< Tile:', current_thread(), file_path, var_name,
              cmap_name, z, y, x, 'took', t2 - t1, 'seconds')
        GLOBAL_LOCK.release()
예제 #4
0
파일: main.py 프로젝트: mzuehlke/demo
    def on_get(self, req, resp, z, y, x):
        GLOBAL_LOCK.acquire()

        file_path = _get_file_from_req(req)
        dataset = _open_dataset(file_path)

        var_name = req.get_param('var', required=True)
        cmap_name = req.get_param('cmap', default='jet')
        cmap_min = _get_param_as_float(req, 'min', default=0.0)
        cmap_max = _get_param_as_float(req, 'max', default=1.0)

        image_id = '%s|%s|%s|%s|%s' % (file_path, var_name, cmap_name, cmap_min, cmap_max)

        global PYRAMIDS
        if image_id in PYRAMIDS:
            pyramid = PYRAMIDS[image_id]
        else:
            variable = dataset[var_name]

            pyramid = ImagePyramid.create_from_array(variable.values)
            pyramid = pyramid.apply(lambda image: TransformArrayImage(image,
                                                                      # no_data_value=variable.fillvalue,
                                                                      force_masked=True,
                                                                      flip_y=is_y_flipped(variable)
                                                                      ))
            pyramid = pyramid.apply(lambda image: ColorMappedRgbaImage(image,
                                                                       value_range=(cmap_min, cmap_max),
                                                                       cmap_name=cmap_name,
                                                                       encode=True, format='PNG'))
            PYRAMIDS[image_id] = pyramid
            print('num_level_zero_tiles:', pyramid.num_level_zero_tiles)
            print('num_levels:', pyramid.num_levels)

        print('PERF: >>> Tile:', current_thread(), file_path, var_name, cmap_name, z, y, x)

        t1 = time.clock()
        tile = pyramid.get_tile(int(x), int(y), int(z))
        t2 = time.clock()

        resp.data = tile
        resp.content_type = 'image/png'
        resp.status = falcon.HTTP_OK

        print('PERF: <<< Tile:', current_thread(), file_path, var_name, cmap_name, z, y, x, 'took', t2 - t1, 'seconds')
        GLOBAL_LOCK.release()
예제 #5
0
파일: main.py 프로젝트: mzuehlke/demo
def _get_variable_image_config(variable):
    t1 = time.clock()
    max_size, tile_size, num_level_zero_tiles, num_levels = ImagePyramid.compute_layout(array=variable)
    t2 = time.clock()
    print("PERF(%s): ImagePyramid.compute_layout took %f seconds" % (variable.name,t2 - t1))
    return {
        # todo - compute imageConfig.sector from variable attributes. See frontend todo.
        'sector': {
            'minLongitude': -180.0,
            'minLatitude': -90.0,
            'maxLongitude': 180.0,
            'maxLatitude': 90.0
        },
        'numLevels': num_levels,
        'numLevelZeroTilesX': num_level_zero_tiles[0],
        'numLevelZeroTilesY': num_level_zero_tiles[1],
        'tileWidth': tile_size[0],
        'tileHeight': tile_size[1]
    }
예제 #6
0
def _get_variable_image_config(variable):
    t1 = time.clock()
    max_size, tile_size, num_level_zero_tiles, num_levels = ImagePyramid.compute_layout(
        array=variable)
    t2 = time.clock()
    print("PERF: ImagePyramid.compute_layout took %f seconds" % (t2 - t1))
    return {
        # todo - compute imageConfig.sector from variable attributes. See frontend todo.
        'sector': {
            'minLongitude': -180.0,
            'minLatitude': -90.0,
            'maxLongitude': 180.0,
            'maxLatitude': 90.0
        },
        'numLevels': num_levels,
        'numLevelZeroTilesX': num_level_zero_tiles[0],
        'numLevelZeroTilesY': num_level_zero_tiles[1],
        'tileWidth': tile_size[0],
        'tileHeight': tile_size[1]
    }
예제 #7
0
    def test_create_from_array(self):
        width = 8640
        height = 4320

        # Typical NetCDF shape: time, lat, lon
        array = np.zeros((1, height, width))

        pyramid = ImagePyramid.create_from_array(array, (270, 270))

        self.assertEqual((270, 270), pyramid.tile_size)
        self.assertEqual((2, 1), pyramid.num_level_zero_tiles)
        self.assertEqual(5, pyramid.num_levels)

        level_image_0 = pyramid.get_level_image(0)
        self.assertEqual((540, 270), level_image_0.size)
        self.assertEqual((270, 270), level_image_0.tile_size)
        self.assertEqual((2, 1), level_image_0.num_tiles)

        level_image_1 = pyramid.get_level_image(1)
        self.assertEqual((1080, 540), level_image_1.size)
        self.assertEqual((270, 270), level_image_1.tile_size)
        self.assertEqual((4, 2), level_image_1.num_tiles)

        level_image_2 = pyramid.get_level_image(2)
        self.assertEqual((2160, 1080), level_image_2.size)
        self.assertEqual((270, 270), level_image_2.tile_size)
        self.assertEqual((8, 4), level_image_2.num_tiles)

        level_image_3 = pyramid.get_level_image(3)
        self.assertEqual((4320, 2160), level_image_3.size)
        self.assertEqual((270, 270), level_image_3.tile_size)
        self.assertEqual((16, 8), level_image_3.num_tiles)

        level_image_4 = pyramid.get_level_image(4)
        self.assertEqual((8640, 4320), level_image_4.size)
        self.assertEqual((270, 270), level_image_4.tile_size)
        self.assertEqual((32, 16), level_image_4.num_tiles)

        tile_4_0_0 = level_image_4.get_tile(0, 0)
        self.assertEqual((1, 270, 270), tile_4_0_0.shape)
        self.assertEqual(0, tile_4_0_0[..., 0, 0])
        self.assertEqual(0, tile_4_0_0[..., 269, 269])

        tile_4_31_15 = level_image_4.get_tile(31, 15)
        self.assertEqual((1, 270, 270), tile_4_31_15.shape)
        self.assertAlmostEqual(0, tile_4_31_15[..., 0, 0])
        self.assertAlmostEqual(0, tile_4_31_15[..., 269, 269])

        tile_3_0_0 = level_image_3.get_tile(0, 0)
        self.assertEqual((1, 270, 270), tile_3_0_0.shape)
        self.assertAlmostEqual(0, tile_3_0_0[..., 0, 0])
        self.assertAlmostEqual(0, tile_3_0_0[..., 269, 269])

        tile_3_15_7 = level_image_3.get_tile(15, 7)
        self.assertEqual((1, 270, 270), tile_3_0_0.shape)
        self.assertAlmostEqual(0, tile_3_15_7[..., 0, 0])
        self.assertAlmostEqual(0, tile_3_15_7[..., 269, 269])

        tile_0_0_0 = level_image_0.get_tile(0, 0)
        self.assertEqual((1, 270, 270), tile_0_0_0.shape)
        self.assertAlmostEqual(0, tile_0_0_0[..., 0, 0])
        self.assertAlmostEqual(0, tile_0_0_0[..., 269, 269])

        tile_0_1_0 = level_image_0.get_tile(1, 0)
        self.assertEqual((1, 270, 270), tile_0_1_0.shape)
        self.assertAlmostEqual(0, tile_0_1_0[..., 0, 0])
        self.assertAlmostEqual(0, tile_0_1_0[..., 269, 269])
예제 #8
0
    def test_create_from_image(self):
        width = 8640
        height = 4320

        pyramid = ImagePyramid.create_from_image(MyTiledImage((width, height), (270, 270)),
                                                 create_ndarray_downsampling_image,
                                                 aggregator=aggregate_ndarray_mean)

        self.assertEqual((270, 270), pyramid.tile_size)
        self.assertEqual((2, 1), pyramid.num_level_zero_tiles)
        self.assertEqual(5, pyramid.num_levels)

        level_image_0 = pyramid.get_level_image(0)
        self.assertEqual((540, 270), level_image_0.size)
        self.assertEqual((270, 270), level_image_0.tile_size)
        self.assertEqual((2, 1), level_image_0.num_tiles)

        level_image_1 = pyramid.get_level_image(1)
        self.assertEqual((1080, 540), level_image_1.size)
        self.assertEqual((270, 270), level_image_1.tile_size)
        self.assertEqual((4, 2), level_image_1.num_tiles)

        level_image_2 = pyramid.get_level_image(2)
        self.assertEqual((2160, 1080), level_image_2.size)
        self.assertEqual((270, 270), level_image_2.tile_size)
        self.assertEqual((8, 4), level_image_2.num_tiles)

        level_image_3 = pyramid.get_level_image(3)
        self.assertEqual((4320, 2160), level_image_3.size)
        self.assertEqual((270, 270), level_image_3.tile_size)
        self.assertEqual((16, 8), level_image_3.num_tiles)

        level_image_4 = pyramid.get_level_image(4)
        self.assertEqual((8640, 4320), level_image_4.size)
        self.assertEqual((270, 270), level_image_4.tile_size)
        self.assertEqual((32, 16), level_image_4.num_tiles)

        tile_4_0_0 = level_image_4.get_tile(0, 0)
        self.assertEqual((270, 270), tile_4_0_0.shape)
        self.assertEqual(0, tile_4_0_0[0, 0])
        self.assertEqual(0, tile_4_0_0[269, 269])

        tile_4_31_15 = level_image_4.get_tile(31, 15)
        self.assertEqual((270, 270), tile_4_31_15.shape)
        self.assertAlmostEqual(0.93772423, tile_4_31_15[0, 0])
        self.assertAlmostEqual(0.93772423, tile_4_31_15[269, 269])

        tile_3_0_0 = level_image_3.get_tile(0, 0)
        self.assertEqual((270, 270), tile_3_0_0.shape)
        self.assertAlmostEqual(0, tile_3_0_0[0, 0])
        self.assertAlmostEqual(0.06250723, tile_3_0_0[269, 269])

        tile_3_15_7 = level_image_3.get_tile(15, 7)
        self.assertEqual((270, 270), tile_3_0_0.shape)
        self.assertAlmostEqual(0.87521702, tile_3_15_7[0, 0])
        self.assertAlmostEqual(0.93772423, tile_3_15_7[269, 269])

        tile_0_0_0 = level_image_0.get_tile(0, 0)
        self.assertEqual((270, 270), tile_0_0_0.shape)
        self.assertAlmostEqual(0, tile_0_0_0[0, 0])
        self.assertAlmostEqual(0.93760848, tile_0_0_0[269, 269])

        tile_0_1_0 = level_image_0.get_tile(1, 0)
        self.assertEqual((270, 270), tile_0_1_0.shape)
        self.assertAlmostEqual(0.00011574, tile_0_1_0[0, 0])
        self.assertAlmostEqual(0.93772423, tile_0_1_0[269, 269])