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)
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')
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)