Esempio n. 1
0
 def test_from_range(self, model, format, tmp_path):
     N = np.random.randint(2, 256)
     c = Colormap.from_range(np.random.rand(3),
                             np.random.rand(3),
                             model=model,
                             N=N)  # noqa
     eval(f'c.save_{format}(tmp_path/"color_out")')
Esempio n. 2
0
 def test_write_filehandle(self, format, name, tmp_path):
     c = Colormap.from_predefined('Dark2')  # noqa
     fname = tmp_path / name
     with open(fname, 'w') as f:  # noqa
         eval(f'c.save_{format}(f)')
     for i in range(10):
         if fname.exists(): return
         time.sleep(.5)
     assert False
Esempio n. 3
0
 def test_eq(self):
     assert Colormap.from_predefined('strain') == Colormap.from_predefined(
         'strain')
     assert Colormap.from_predefined('strain') != Colormap.from_predefined(
         'stress')
     assert Colormap.from_predefined(
         'strain', N=128) != Colormap.from_predefined('strain', N=64)
     assert not Colormap.from_predefined('strain', N=128) == 1
Esempio n. 4
0
 def test_shade(self, ref_path, update, bounds):
     data = np.add(*np.indices((10, 11)))
     img_current = Colormap.from_predefined('orientation').shade(
         data, bounds=bounds)
     if update:
         img_current.save(ref_path / f'shade_{bounds}.png')
     else:
         img_reference = Image.open(ref_path / f'shade_{bounds}.png')
         diff = ImageChops.difference(img_reference.convert('RGB'),
                                      img_current.convert('RGB'))
         assert not diff.getbbox()
Esempio n. 5
0
 def test_compare_reference(self, format, ext, tmp_path, ref_path, update):
     name = 'binary'
     c = Colormap.from_predefined(name)  # noqa
     if update:
         os.chdir(ref_path)
         eval(f'c.save_{format}()')
     else:
         os.chdir(tmp_path)
         eval(f'c.save_{format}()')
         time.sleep(.5)
         assert filecmp.cmp(tmp_path / (name + ext),
                            ref_path / (name + ext))
Esempio n. 6
0
 def test_from_range_types(self, low, high):
     assert Colormap.from_range(low, high) == Colormap.from_range(
         np.array(low), np.array(high))
Esempio n. 7
0
    def test_conversion(self):
        specials = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
                             [0., 0., 1.], [1., 1., 0.], [0., 1., 1.],
                             [1., 0., 1.], [1., 1., 1.]])
        rgbs = np.vstack((specials, np.random.rand(100, 3)))
        for rgb in rgbs:
            print('rgb', rgb)

            # rgb2hsv2rgb
            hsv = Colormap._rgb2hsv(rgb)
            print('hsv', hsv)
            assert np.allclose(Colormap._hsv2rgb(hsv), rgb)

            # rgb2hsl2rgb
            hsl = Colormap._rgb2hsl(rgb)
            print('hsl', hsl)
            assert np.allclose(Colormap._hsl2rgb(hsl), rgb)

            # rgb2xyz2rgb
            xyz = Colormap._rgb2xyz(rgb)
            print('xyz', xyz)
            assert np.allclose(Colormap._xyz2rgb(xyz), rgb, atol=1.e-6, rtol=0)

            # xyz2lab2xyz
            lab = Colormap._xyz2lab(xyz)
            print('lab', lab)
            assert np.allclose(Colormap._lab2xyz(lab), xyz)

            # lab2msh2lab
            msh = Colormap._lab2msh(lab)
            print('msh', msh)
            assert np.allclose(Colormap._msh2lab(msh), lab)

            # lab2rgb2lab
            assert np.allclose(Colormap._rgb2lab(Colormap._lab2rgb(lab)),
                               lab,
                               atol=1.e-6,
                               rtol=0)

            # rgb2msh2rgb
            assert np.allclose(Colormap._msh2rgb(Colormap._rgb2msh(rgb)),
                               rgb,
                               atol=1.e-6,
                               rtol=0)

            # hsv2msh
            assert np.allclose(Colormap._hsv2msh(hsv), msh, atol=1.e-6, rtol=0)

            # hsl2msh
            assert np.allclose(Colormap._hsv2msh(hsv), msh, atol=1.e-6, rtol=0)

            # xyz2msh
            assert np.allclose(Colormap._xyz2msh(xyz), msh, atol=1.e-6, rtol=0)
Esempio n. 8
0
 def test_repr(self, patch_plt_show):
     print(Colormap.from_predefined('stress'))
Esempio n. 9
0
 def test_at_value(self, N, cmap, at, result):
     assert np.allclose(Colormap.from_predefined(cmap, N=N).at(at)[..., :3],
                        result,
                        rtol=0.005)
Esempio n. 10
0
 def test_mul(self):
     c = o = Colormap.from_predefined('jet')
     o *= 2
     assert c + c == o
Esempio n. 11
0
 def test_add(self):
     c = Colormap.from_predefined('jet')
     c += c
     assert (np.allclose(c.colors[:len(c.colors) // 2],
                         c.colors[len(c.colors) // 2:]))
Esempio n. 12
0
 def test_invert(self):
     c_1 = Colormap.from_predefined('strain')
     c_2 = ~c_1
     assert (not np.allclose(c_1.colors,  c_2.colors)) and \
                 np.allclose(c_1.colors,(~c_2).colors)
Esempio n. 13
0
 def test_reversed(self):
     c_1 = Colormap.from_predefined('stress')
     c_2 = c_1.reversed()
     assert (not np.allclose(c_1.colors,c_2.colors)) and \
                 np.allclose(c_1.colors,c_2.reversed().colors)
Esempio n. 14
0
 def test_invalid_color(self, model):
     with pytest.raises(ValueError):
         c = Colormap.from_range(-2. + np.random.rand(3),
                                 np.random.rand(3),
                                 N=10,
                                 model=model)  # noqa
Esempio n. 15
0
 def test_from_predefined(self, name, format, tmp_path):
     N = np.random.randint(2, 256)
     c = Colormap.from_predefined(name, N)  # noqa
     os.chdir(tmp_path)
     eval(f'c.save_{format}()')
Esempio n. 16
0
 def test_list(self):
     Colormap.list_predefined()