Esempio n. 1
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)
    npmap = np.array([True, True, True])
    damap = DataArray(npmap)

    with patch('datacube_ows.styles.colormap.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, damap)
        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)
        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, damap)
        alpha_channel = result["alpha"].values
        assert (alpha_channel == 255).all()
Esempio n. 2
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])
    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)

    npmap = np.array([True, True, True, True, True, True])
    damap = DataArray(npmap)

    with patch('datacube_ows.styles.colormap.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, damap)
        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)