def test_make_lut(): """Should create valid lookup table.""" cm = {1: [100, 100, 100, 255], 2: [255, 255, 255, 255]} lut = colormap.make_lut(cm) assert len(lut) == 256 assert lut[0].tolist() == [0, 0, 0, 0] assert lut[1].tolist() == [100, 100, 100, 255] assert lut[4].tolist() == [0, 0, 0, 0]
def main(out_dir, img_height): """Create PNG images from rio-tiler colormaps """ out_dir = Path(out_dir) out_dir.mkdir(exist_ok=True, parents=True) for cmap_name in cmap_list: arr = make_lut(get_colormap(cmap_name)) # Add axis arr = arr[np.newaxis, ...] # Make n pixels high arr = np.vstack([arr] * img_height) # Write to image imageio.imwrite(out_dir / f'{cmap_name}.png', arr)
def make_colormap(name): """Use rio-tiler colormap to create matplotlib colormap """ colormap = make_lut(cmap.get(name)) # rescale to 0-1 return ListedColormap(colormap / 255, name=name)