Exemple #1
0
    def applyToData(self, data, reference=None):
        """Apply the colormap to the data

        :param Union[numpy.ndarray,~silx.gui.plot.item.ColormapMixIn] data:
            The data to convert or the item for which to apply the colormap.
        :param Union[numpy.ndarray,~silx.gui.plot.item.ColormapMixIn,None] reference:
            The data or item to use as reference to compute autoscale
        """
        if reference is None:
            reference = data
        vmin, vmax = self.getColormapRange(reference)

        if hasattr(data, "getColormappedData"):  # Use item's data
            data = data.getColormappedData()

        return _colormap.cmap(data, self._colors, vmin, vmax,
                              self._getNormalizer(), self.__nanColor)
Exemple #2
0
    def _test(self, data, colors, vmin, vmax, normalization, nan_color):
        """Run test of colormap against alternative implementation

        :param numpy.ndarray data: Data to convert
        :param numpy.ndarray colors: Color look-up-table
        :param float vmin: Lower bound of the colormap range
        :param float vmax: Upper bound of the colormap range
        :param str normalization: Normalization to use
        :param Union[numpy.ndarray, None] nan_color: Color to use for NaN
        """
        image = colormap.cmap(data, colors, vmin, vmax, normalization,
                              nan_color)

        ref_image = self.ref_colormap(data, colors, vmin, vmax, normalization,
                                      nan_color)

        self.assertTrue(numpy.allclose(ref_image, image))
        self.assertEqual(image.dtype, colors.dtype)
        self.assertEqual(image.shape, data.shape + (colors.shape[-1], ))
Exemple #3
0
    def _test(self, data, colors, vmin, vmax, normalization, nan_color):
        """Run test of colormap against alternative implementation

        :param numpy.ndarray data: Data to convert
        :param numpy.ndarray colors: Color look-up-table
        :param float vmin: Lower bound of the colormap range
        :param float vmax: Upper bound of the colormap range
        :param str normalization: Normalization to use
        :param Union[numpy.ndarray, None] nan_color: Color to use for NaN
        """
        image = colormap.cmap(
            data, colors, vmin, vmax, normalization, nan_color)

        ref_image = self.ref_colormap(
            data, colors, vmin, vmax, normalization, nan_color)

        self.assertTrue(numpy.allclose(ref_image, image))
        self.assertEqual(image.dtype, colors.dtype)
        self.assertEqual(image.shape, data.shape + (colors.shape[-1],))