def test_can_accept_vispy_colormaps_in_dict(): """Test that we can accept vispy colormaps in a dictionary.""" colors_a = np.array([[0, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1]]) colors_b = np.array([[0, 0, 0, 1], [1, 0, 0, 1], [0, 0, 1, 1]]) vispy_cmap_a = VispyColormap(colors_a) vispy_cmap_b = VispyColormap(colors_b) cmap = ensure_colormap({'a': vispy_cmap_a, 'b': vispy_cmap_b}) assert isinstance(cmap, Colormap) np.testing.assert_almost_equal(cmap.colors, colors_a) assert cmap.name == 'a'
def _on_colormap_change(self, event=None): if self.layer.gamma != 1: # when gamma!=1, we instantiate a new colormap with 256 control # points from 0-1 colors = self.layer.colormap.map( np.linspace(0, 1, 256)**self.layer.gamma) cmap = VispyColormap(colors) else: cmap = VispyColormap(*self.layer.colormap) if self.layer.dims.ndisplay == 3: self.node.view_program['texture2D_LUT'] = (cmap.texture_lut() if ( hasattr(cmap, 'texture_lut')) else None) self.node.cmap = cmap
def test_can_accept_vispy_colormaps(): """Test that we can accept vispy colormaps.""" colors = np.array([[0, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1]]) vispy_cmap = VispyColormap(colors) cmap = ensure_colormap(vispy_cmap) assert isinstance(cmap, Colormap) np.testing.assert_almost_equal(cmap.colors, colors)
def test_can_accept_vispy_colormap_name_tuple(): """Test that we can accept vispy colormap named type.""" colors = np.array([[0, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1]]) vispy_cmap = VispyColormap(colors) cmap = ensure_colormap(('special_name', vispy_cmap)) assert isinstance(cmap, Colormap) np.testing.assert_almost_equal(cmap.colors, colors) assert cmap.name == 'special_name'
def test_colormap(name): np.random.seed(0) cmap = AVAILABLE_COLORMAPS[name] # Test can map random 0-1 values values = np.random.rand(50) colors = cmap.map(values) assert colors.shape == (len(values), 4) # Create vispy colormap and check current colormaps match vispy # colormap vispy_cmap = VispyColormap(*cmap) vispy_colors = vispy_cmap.map(values) np.testing.assert_almost_equal(colors, vispy_colors, decimal=6)
def _on_colormap_change(self, event=None): self.node.cmap = VispyColormap(*self.layer.colormap)
def _on_colormap_change(self): self.node.cmap = VispyColormap(*self.layer.colormap)
def vispy(self): """Return a vispy colormap based on data.""" return VispyColormap(self._data)