Esempio n. 1
0
    def __getPixmap(self):
        if self.__pixmap is not None:
            return self.__pixmap

        calibrant = self.__getConfiguredCalibrant()
        if calibrant is None:
            return None
        tths = numpy.array(calibrant.get_2th())

        tth_min, tth_max = 0, numpy.pi
        size = 360
        agregation = numpy.zeros((1, size))
        for tth in tths:
            pos = int((tth - tth_min) / (tth_max - tth_min) * size)
            if pos < 0:
                continue
            if pos >= size:
                continue
            agregation[0, pos] += 1
        agregation = -agregation

        colormap = Colormap()
        rgbImage = colormap.applyToData(agregation)[:, :, :3]
        qimage = imageutils.convertArrayToQImage(rgbImage)
        qpixmap = qt.QPixmap.fromImage(qimage)
        self.__pixmap = qpixmap
        return self.__pixmap
 def testAutoscaleFromDataReference(self):
     colormap = Colormap(name='gray', normalization='linear')
     data = numpy.array([50])
     reference = numpy.array([0, 100])
     value = colormap.applyToData(data, reference)
     self.assertEqual(len(value), 1)
     self.assertEqual(value[0, 0], 128)
Esempio n. 3
0
    def __getPixmap(self):
        if self.__pixmap is not None:
            return self.__pixmap

        calibrant = self.__getConfiguredCalibrant()
        if calibrant is None:
            return None
        tths = numpy.array(calibrant.get_2th())

        tth_min, tth_max = 0, numpy.pi
        size = 360
        agregation = numpy.zeros((1, size))
        for tth in tths:
            pos = int((tth - tth_min) / (tth_max - tth_min) * size)
            if pos < 0:
                continue
            if pos >= size:
                continue
            agregation[0, pos] += 1
        agregation = -agregation

        colormap = Colormap()
        rgbImage = colormap.applyToData(agregation)[:, :, :3]
        qimage = imageutils.convertArrayToQImage(rgbImage)
        qpixmap = qt.QPixmap.fromImage(qimage)
        self.__pixmap = qpixmap
        return self.__pixmap
 def testAutoscaleFromItemReference(self):
     colormap = Colormap(name='gray', normalization='linear')
     data = numpy.array([50])
     image = items.ImageData()
     image.setData(numpy.array([[0, 100]]))
     value = colormap.applyToData(data, reference=image)
     self.assertEqual(len(value), 1)
     self.assertEqual(value[0, 0], 128)
    def testNaNColor(self):
        """Test Colormap.applyToData with NaN values"""
        colormap = Colormap(name='gray', normalization='linear')
        colormap.setNaNColor('red')
        self.assertEqual(colormap.getNaNColor(), qt.QColor(255, 0, 0))

        data = numpy.array([50., numpy.nan])
        image = items.ImageData()
        image.setData(numpy.array([[0, 100]]))
        value = colormap.applyToData(data, reference=image)
        self.assertEqual(len(value), 2)
        self.assertTrue(numpy.array_equal(value[0], (128, 128, 128, 255)))
        self.assertTrue(numpy.array_equal(value[1], (255, 0, 0, 255)))
    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)))
Esempio n. 7
0
    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)))
Esempio n. 8
0
    def __getPixmap(self, size=360):
        if self.__pixmap is not None and self.__cachedSize == size:
            return self.__pixmap
        calibrant = self.__getConfiguredCalibrant()
        if calibrant is None:
            return None
        tths = numpy.array(calibrant.get_2th())

        tth_min, tth_max = 0, numpy.pi
        histo = numpy.histogram(tths, bins=size, range=(tth_min, tth_max))
        agregation = histo[0].reshape(1, -1)
        colormap = Colormap(name="reversed gray",
                            vmin=agregation.min(),
                            vmax=agregation.max())
        rgbImage = colormap.applyToData(agregation)[:, :, :3]
        qimage = imageutils.convertArrayToQImage(rgbImage)
        qpixmap = qt.QPixmap.fromImage(qimage)
        self.__pixmap = qpixmap
        self.__cachedSize = size
        return self.__pixmap
    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)
Esempio n. 10
0
    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)