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]) da = DataArray(band, name='foo') ds = Dataset(data_vars={'foo': da}) with patch('datacube_wms.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()
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]) da = DataArray(band, name='foo') ds = Dataset(data_vars={'foo': da}) with patch('datacube_wms.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)