def _updateSceneColormap(self): """Synchronizes scene's colormap with Colormap object""" colormap = self.getColormap() sceneCMap = self._plane.colormap indices = numpy.linspace(0., 1., 256) colormapDisp = Colormap(name=colormap.getName(), normalization=Colormap.LINEAR, vmin=None, vmax=None, colors=colormap.getColormapLUT()) colors = colormapDisp.applyToData(indices) sceneCMap.colormap = colors sceneCMap.norm = colormap.getNormalization() range_ = colormap.getColormapRange(data=self._dataRange) sceneCMap.range_ = range_
def testApplyColormapToData(self): """Simple test of applyColormapToData function""" colormap = Colormap(name='gray', normalization='linear', vmin=0, vmax=255) size = 10 expected = numpy.empty((size, 4), dtype='uint8') expected[:, 0] = numpy.arange(size, dtype='uint8') expected[:, 1] = expected[:, 0] expected[:, 2] = expected[:, 0] expected[:, 3] = 255 for dtype in ('uint8', 'int32', 'float32', 'float64'): with self.subTest(dtype=dtype): array = numpy.arange(size, dtype=dtype) result = colormap.applyToData(data=array) self.assertTrue(numpy.all(numpy.equal(result, expected)))
def testApplyToData(self): """Test applyToData on different datasets""" datasets = [ numpy.zeros((0, 0)), # Empty array numpy.array((numpy.nan, numpy.inf)), # All non-finite numpy.array((-numpy.inf, numpy.inf, 1.0, 2.0)), # Some infinite ] for normalization in ('linear', 'log'): colormap = Colormap(name='gray', normalization=normalization, vmin=None, vmax=None) for data in datasets: with self.subTest(data=data): image = colormap.applyToData(data) self.assertEqual(image.dtype, numpy.uint8) self.assertEqual(image.shape[-1], 4) self.assertEqual(image.shape[:-1], data.shape)