def test_reint(): from datacube_ows.styles.colormap import ColorMapStyleDef band = np.array([0., 0., 1., 1., 2., 2.]) da = DataArray(band, name='foo') assert (band.dtype.kind == "f") data = ColorMapStyleDef.reint(band) assert (data.dtype.kind == "i") assert (da.dtype.kind == "f") data = ColorMapStyleDef.reint(da) assert (data.dtype.kind == "i") data = ColorMapStyleDef.reint(data) assert (data.dtype.kind == "i")
def test_createcolordata_alpha(): from datacube_ows.styles.colormap import ColorMapStyleDef from colour import Color band = np.array([0, 0, 1, 1, 2, 2]) da = DataArray(band, name='foo') rgb = Color("#FFFFFF") data = ColorMapStyleDef.create_colordata(da, rgb, 0.0, (band >= 0)) assert (data["alpha"] == 0).all()
def test_createcolordata_mask(): from datacube_ows.styles.colormap import ColorMapStyleDef from colour import Color band = np.array([0, 0, 1, 1, 2, 2]) da = DataArray(band, name='foo') rgb = Color("#FFFFFF") data = ColorMapStyleDef.create_colordata(da, rgb, 0.0, (band > 0)) assert (np.isnan(data["red"][0:1:1])).all() assert (np.isfinite(data["red"][2:5:1])).all()
def StyleDef(product, cfg): try: if "component_ratio" in cfg: return HybridStyleDef(product, cfg) elif cfg.get("components", False): return ComponentStyleDef(product, cfg) elif cfg.get("value_map", False): return ColorMapStyleDef(product, cfg) elif cfg.get("color_ramp", False) or cfg.get("range", False): return ColorRampDef(product, cfg) except KeyError: raise ConfigException( "Required field missing in style %s of layer %s" % (cfg.get("name", ""), product.name))