コード例 #1
0
    def testUpdateColorMap(self):
        colormap = Colormap(name='gray',
                            normalization='linear',
                            vmin=0,
                            vmax=1)

        # check inital state
        self.plot.addImage(data=self.data, colormap=colormap, legend='toto')
        self.plot.setActiveImage('toto')

        self.assertTrue(self.colorBar.getColorScaleBar().minVal == 0)
        self.assertTrue(self.colorBar.getColorScaleBar().maxVal == 1)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._vmin == 0)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._vmax == 1)
        self.assertIsInstance(
            self.colorBar.getColorScaleBar().getTickBar()._normalizer,
            colors._LinearNormalization)

        # update colormap
        colormap.setVMin(0.5)
        self.assertTrue(self.colorBar.getColorScaleBar().minVal == 0.5)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._vmin == 0.5)

        colormap.setVMax(0.8)
        self.assertTrue(self.colorBar.getColorScaleBar().maxVal == 0.8)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._vmax == 0.8)

        colormap.setNormalization('log')
        self.assertIsInstance(
            self.colorBar.getColorScaleBar().getTickBar()._normalizer,
            colors._LogarithmicNormalization)
コード例 #2
0
ファイル: testColorBar.py プロジェクト: dnaudet/silx
    def testUpdateColorMap(self):
        colormap = Colormap(name='gray',
                            normalization='linear',
                            vmin=0,
                            vmax=1)

        # check inital state
        self.plot.addImage(data=self.data, colormap=colormap, legend='toto')
        self.plot.setActiveImage('toto')

        self.assertTrue(self.colorBar.getColorScaleBar().minVal == 0)
        self.assertTrue(self.colorBar.getColorScaleBar().maxVal == 1)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._vmin == 0)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._vmax == 1)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._norm == "linear")

        # update colormap
        colormap.setVMin(0.5)
        self.assertTrue(self.colorBar.getColorScaleBar().minVal == 0.5)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._vmin == 0.5)

        colormap.setVMax(0.8)
        self.assertTrue(self.colorBar.getColorScaleBar().maxVal == 0.8)
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._vmax == 0.8)

        colormap.setNormalization('log')
        self.assertTrue(
            self.colorBar.getColorScaleBar().getTickBar()._norm == 'log')
コード例 #3
0
    def testVMinVMax(self):
        """Test getter and setter associated to vmin and vmax values"""
        vmin = 1.0
        vmax = 2.0

        colormapObject = Colormap(name='viridis',
                                  vmin=vmin,
                                  vmax=vmax,
                                  normalization=Colormap.LINEAR)

        with self.assertRaises(ValueError):
            colormapObject.setVMin(3)

        with self.assertRaises(ValueError):
            colormapObject.setVMax(-2)

        with self.assertRaises(ValueError):
            colormapObject.setVRange(3, -2)

        self.assertTrue(colormapObject.getColormapRange() == (1.0, 2.0))
        self.assertTrue(colormapObject.isAutoscale() is False)
        colormapObject.setVRange(None, None)
        self.assertTrue(colormapObject.getVMin() is None)
        self.assertTrue(colormapObject.getVMax() is None)
        self.assertTrue(colormapObject.isAutoscale() is True)
コード例 #4
0
ファイル: test_colors.py プロジェクト: vallsv/silx
    def testVMinVMax(self):
        """Test getter and setter associated to vmin and vmax values"""
        vmin = 1.0
        vmax = 2.0

        colormapObject = Colormap(name='viridis',
                                  vmin=vmin,
                                  vmax=vmax,
                                  normalization=Colormap.LINEAR)

        with self.assertRaises(ValueError):
            colormapObject.setVMin(3)

        with self.assertRaises(ValueError):
            colormapObject.setVMax(-2)

        with self.assertRaises(ValueError):
            colormapObject.setVRange(3, -2)

        self.assertTrue(colormapObject.getColormapRange() == (1.0, 2.0))
        self.assertTrue(colormapObject.isAutoscale() is False)
        colormapObject.setVRange(None, None)
        self.assertTrue(colormapObject.getVMin() is None)
        self.assertTrue(colormapObject.getVMax() is None)
        self.assertTrue(colormapObject.isAutoscale() is True)
コード例 #5
0
 def testEditableMode(self):
     """Make sure the colormap will raise NotEditableError when try to
     change a colormap not editable"""
     colormap = Colormap()
     colormap.setEditable(False)
     with self.assertRaises(NotEditableError):
         colormap.setVRange(0., 1.)
     with self.assertRaises(NotEditableError):
         colormap.setVMin(1.)
     with self.assertRaises(NotEditableError):
         colormap.setVMax(1.)
     with self.assertRaises(NotEditableError):
         colormap.setNormalization(Colormap.LOGARITHM)
     with self.assertRaises(NotEditableError):
         colormap.setName('magma')
     with self.assertRaises(NotEditableError):
         colormap.setColormapLUT([[0., 0., 0.], [1., 1., 1.]])
     with self.assertRaises(NotEditableError):
         colormap._setFromDict(colormap._toDict())
     state = colormap.saveState()
     with self.assertRaises(NotEditableError):
         colormap.restoreState(state)
コード例 #6
0
ファイル: test_colors.py プロジェクト: vallsv/silx
 def testEditableMode(self):
     """Make sure the colormap will raise NotEditableError when try to
     change a colormap not editable"""
     colormap = Colormap()
     colormap.setEditable(False)
     with self.assertRaises(NotEditableError):
         colormap.setVRange(0., 1.)
     with self.assertRaises(NotEditableError):
         colormap.setVMin(1.)
     with self.assertRaises(NotEditableError):
         colormap.setVMax(1.)
     with self.assertRaises(NotEditableError):
         colormap.setNormalization(Colormap.LOGARITHM)
     with self.assertRaises(NotEditableError):
         colormap.setName('magma')
     with self.assertRaises(NotEditableError):
         colormap.setColormapLUT(numpy.array([0, 1]))
     with self.assertRaises(NotEditableError):
         colormap._setFromDict(colormap._toDict())
     state = colormap.saveState()
     with self.assertRaises(NotEditableError):
         colormap.restoreState(state)