コード例 #1
0
def test_RBGAMapped_Masking(product_layer_mask_map, style_cfg_map_mask):
    def fake_make_mask(data, **kwargs):
        val = kwargs["bar"]
        return data == val

    band = np.array([0, 0, 1, 1, 2, 2])
    today = datetime.date.today()
    da = DataArray(band, name='foo')
    ds = DatasetCollection()
    ds.add_time(today, Dataset(data_vars={'foo': da}))

    with patch('datacube_ows.band_mapper.make_mask',
               new_callable=lambda: fake_make_mask) as fmm:
        style_def = StyleDef(product_layer_mask_map, style_cfg_map_mask)
        data = style_def.transform_data(ds, None, None)
        r = data["red"]
        g = data["green"]
        b = data["blue"]
        a = data["alpha"]

        assert (r[2:3:1] == 0)
        assert (g[2:3:1] == 0)
        assert (b[2:3:1] == 0)
        assert (a[2:3:1] == 0)
        assert (r[4:5:1] == 255)
        assert (g[4:5:1] == 255)
        assert (b[4:5:1] == 255)
        assert (a[4:5:1] == 255)
コード例 #2
0
def test_alpha_style_map(product_layer_alpha_map, style_cfg_map_alpha_1,
                         style_cfg_map_alpha_2, style_cfg_map_alpha_3):
    def fake_make_mask(data, **kwargs):
        return data

    band = np.array([True, True, True])
    time = datetime.date.today()
    da = DataArray(band, name='foo')
    dsc = DatasetCollection()
    ds = Dataset(data_vars={'foo': da})
    dsc.add_time(time, ds)

    with patch('datacube_ows.band_mapper.make_mask',
               new_callable=lambda: fake_make_mask) as fmm:
        style_def = StyleDef(product_layer_alpha_map, style_cfg_map_alpha_1)

        result = style_def.transform_data(dsc, None, None)
        alpha_channel = result["alpha"].values
        assert (alpha_channel == 0).all()

        style_def = StyleDef(product_layer_alpha_map, style_cfg_map_alpha_2)

        result = style_def.transform_data(dsc, None, None)
        alpha_channel = result["alpha"].values
        assert (alpha_channel == 127).all()

        style_def = StyleDef(product_layer_alpha_map, style_cfg_map_alpha_3)

        result = style_def.transform_data(dsc, None, None)
        alpha_channel = result["alpha"].values
        assert (alpha_channel == 255).all()
コード例 #3
0
def test_alpha_style_map(product_layer_alpha_map, style_cfg_map_alpha_1,
                         style_cfg_map_alpha_2, style_cfg_map_alpha_3):
    def fake_make_mask(data, **kwargs):
        return data

    band = np.array([True, True, True])
    timarray = [np.datetime64(datetime.date.today())]
    times = DataArray(timarray, coords=[timarray], dims=["time"], name="time")
    da = DataArray(band, name='foo')
    dst = Dataset(data_vars={'foo': da})
    ds = concat([dst], times)

    with patch('datacube_ows.band_mapper.make_mask',
               new_callable=lambda: fake_make_mask) as fmm:
        style_def = StyleDef(product_layer_alpha_map, style_cfg_map_alpha_1)

        result = style_def.transform_data(ds, None, None)
        alpha_channel = result["alpha"].values
        assert (alpha_channel == 0).all()

        style_def = StyleDef(product_layer_alpha_map, style_cfg_map_alpha_2)

        result = style_def.transform_data(ds, None, None)
        alpha_channel = result["alpha"].values
        assert (alpha_channel == 127).all()

        style_def = StyleDef(product_layer_alpha_map, style_cfg_map_alpha_3)

        result = style_def.transform_data(ds, None, None)
        alpha_channel = result["alpha"].values
        assert (alpha_channel == 255).all()
コード例 #4
0
def test_dynamic_range_compression_scale_range(product_layer, style_cfg_lin):
    style_cfg_lin["scale_range"] = [-3000, 3000]

    style_def = StyleDef(product_layer, style_cfg_lin)

    assert style_def.scale_min == -3000
    assert style_def.scale_max == 3000

    band = np.zeros(3)
    band[0] = -3000
    band[1] = 0
    band[2] = 3000

    compressed = style_def.compress_band("red", band)

    assert compressed[0] == 0
    assert compressed[1] == 255 / 2
    assert compressed[2] == 255
コード例 #5
0
 def parse_styling(self, cfg):
     self.styles = list([StyleDef(self, s) for s in cfg["styles"]])
     self.style_index = {s.name: s for s in self.styles}
     if "default_style" in cfg:
         if cfg["default_style"] not in self.style_index:
             raise ConfigException(
                 "Default style %s is not in the 'styles' for layer %s" %
                 (cfg["default_style"], self.name))
         self.default_style = self.style_index[cfg["default_style"]]
     else:
         self.default_style = self.styles[0]
コード例 #6
0
def test_dynamic_range_compression_scale_factor(product_layer, style_cfg_lin):
    del style_cfg_lin["scale_range"]
    style_cfg_lin["scale_factor"] = 2.5

    style_def = StyleDef(product_layer, style_cfg_lin)

    assert style_def.scale_min == 0.0
    assert style_def.scale_max == 637.5

    band = np.zeros(3)
    band[0] = -3000
    band[1] = 0
    band[2] = 3000
コード例 #7
0
def test_correct_style_hybrid(product_layer, style_cfg_lin):
    style_cfg_lin["component_ratio"] = 1.0
    style_cfg_lin["range"] = [1, 2]
    style_cfg_lin["index_function"] = {
        "function": "datacube_ows.band_utils.constant",
        "pass_product_cfg": True,
        "kwargs": {
            "const": "0.1"
        }
    }
    style_def = StyleDef(product_layer, style_cfg_lin)

    assert isinstance(style_def, bm.HybridStyleDef)
コード例 #8
0
def test_correct_style_ramp(product_layer, style_cfg_ramp):
    style_def = StyleDef(product_layer, style_cfg_ramp)

    assert isinstance(style_def, bm.RgbaColorRampDef)
コード例 #9
0
def test_correct_style_map(product_layer, style_cfg_map):
    style_def = StyleDef(product_layer, style_cfg_map)

    assert isinstance(style_def, bm.RGBAMappedStyleDef)
コード例 #10
0
def test_correct_style_linear(product_layer, style_cfg_lin):
    style_def = StyleDef(product_layer, style_cfg_lin)

    assert isinstance(style_def, bm.LinearStyleDef)