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 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 testGetColorMapRange(self): """Make sure the getColormapRange function of colormap is correctly applying """ # test linear scale data = numpy.array([-1, 1, 2, 3, float('nan')]) cl1 = Colormap(name='gray', normalization=Colormap.LINEAR, vmin=0, vmax=2) cl2 = Colormap(name='gray', normalization=Colormap.LINEAR, vmin=None, vmax=2) cl3 = Colormap(name='gray', normalization=Colormap.LINEAR, vmin=0, vmax=None) cl4 = Colormap(name='gray', normalization=Colormap.LINEAR, vmin=None, vmax=None) self.assertTrue(cl1.getColormapRange(data) == (0, 2)) self.assertTrue(cl2.getColormapRange(data) == (-1, 2)) self.assertTrue(cl3.getColormapRange(data) == (0, 3)) self.assertTrue(cl4.getColormapRange(data) == (-1, 3)) # test linear with annoying cases self.assertEqual(cl3.getColormapRange((-1, -2)), (0, 0)) self.assertEqual(cl4.getColormapRange(()), (0., 1.)) self.assertEqual(cl4.getColormapRange( (float('nan'), float('inf'), 1., -float('inf'), 2)), (1., 2.)) self.assertEqual(cl4.getColormapRange( (float('nan'), float('inf'))), (0., 1.)) # test log scale data = numpy.array([float('nan'), -1, 1, 10, 100, 1000]) cl1 = Colormap(name='gray', normalization=Colormap.LOGARITHM, vmin=1, vmax=100) cl2 = Colormap(name='gray', normalization=Colormap.LOGARITHM, vmin=None, vmax=100) cl3 = Colormap(name='gray', normalization=Colormap.LOGARITHM, vmin=1, vmax=None) cl4 = Colormap(name='gray', normalization=Colormap.LOGARITHM, vmin=None, vmax=None) self.assertTrue(cl1.getColormapRange(data) == (1, 100)) self.assertTrue(cl2.getColormapRange(data) == (1, 100)) self.assertTrue(cl3.getColormapRange(data) == (1, 1000)) self.assertTrue(cl4.getColormapRange(data) == (1, 1000)) # test log with annoying cases self.assertEqual(cl3.getColormapRange((0.1, 0.2)), (1, 1)) self.assertEqual(cl4.getColormapRange((-2., -1.)), (1., 1.)) self.assertEqual(cl4.getColormapRange(()), (1., 10.)) self.assertEqual(cl4.getColormapRange( (float('nan'), float('inf'), 1., -float('inf'), 2)), (1., 2.)) self.assertEqual(cl4.getColormapRange( (float('nan'), float('inf'))), (1., 10.))
def testGetColorMapRange(self): """Make sure the getColormapRange function of colormap is correctly applying """ # test linear scale data = numpy.array([-1, 1, 2, 3, float('nan')]) cl1 = Colormap(name='gray', normalization=Colormap.LINEAR, vmin=0, vmax=2) cl2 = Colormap(name='gray', normalization=Colormap.LINEAR, vmin=None, vmax=2) cl3 = Colormap(name='gray', normalization=Colormap.LINEAR, vmin=0, vmax=None) cl4 = Colormap(name='gray', normalization=Colormap.LINEAR, vmin=None, vmax=None) self.assertTrue(cl1.getColormapRange(data) == (0, 2)) self.assertTrue(cl2.getColormapRange(data) == (-1, 2)) self.assertTrue(cl3.getColormapRange(data) == (0, 3)) self.assertTrue(cl4.getColormapRange(data) == (-1, 3)) # test linear with annoying cases self.assertEqual(cl3.getColormapRange((-1, -2)), (0, 0)) self.assertEqual(cl4.getColormapRange(()), (0., 1.)) self.assertEqual(cl4.getColormapRange( (float('nan'), float('inf'), 1., -float('inf'), 2)), (1., 2.)) self.assertEqual(cl4.getColormapRange( (float('nan'), float('inf'))), (0., 1.)) # test log scale data = numpy.array([float('nan'), -1, 1, 10, 100, 1000]) cl1 = Colormap(name='gray', normalization=Colormap.LOGARITHM, vmin=1, vmax=100) cl2 = Colormap(name='gray', normalization=Colormap.LOGARITHM, vmin=None, vmax=100) cl3 = Colormap(name='gray', normalization=Colormap.LOGARITHM, vmin=1, vmax=None) cl4 = Colormap(name='gray', normalization=Colormap.LOGARITHM, vmin=None, vmax=None) self.assertTrue(cl1.getColormapRange(data) == (1, 100)) self.assertTrue(cl2.getColormapRange(data) == (1, 100)) self.assertTrue(cl3.getColormapRange(data) == (1, 1000)) self.assertTrue(cl4.getColormapRange(data) == (1, 1000)) # test log with annoying cases self.assertEqual(cl3.getColormapRange((0.1, 0.2)), (1, 1)) self.assertEqual(cl4.getColormapRange((-2., -1.)), (1., 1.)) self.assertEqual(cl4.getColormapRange(()), (1., 10.)) self.assertEqual(cl4.getColormapRange( (float('nan'), float('inf'), 1., -float('inf'), 2)), (1., 2.)) self.assertEqual(cl4.getColormapRange( (float('nan'), float('inf'))), (1., 10.))