def test_matplotlibimage(self): tm._skip_if_no_matplotlib() import numpy as np import matplotlib.pyplot as plt img = np.random.randint(0, 255, (100, 100, 3)) ax = plt.imshow(img) img = cesiumpy.entities.material.TemporaryImage(ax.figure) m = cesiumpy.entities.material.ImageMaterialProperty(img) self.assertTrue( re.match( """new Cesium\\.ImageMaterialProperty\\({image : "\w+\\.png"}\\)""", m.script)) img = cesiumpy.entities.material.TemporaryImage(ax) m = cesiumpy.entities.material.ImageMaterialProperty(img) self.assertTrue( re.match( """new Cesium\\.ImageMaterialProperty\\({image : "\w+\\.png"}\\)""", m.script)) plt.close() fig, axes = plt.subplots(2, 2) msg = "Unable to trim a Figure contains multiple Axes" with nose.tools.assert_raises_regexp(ValueError, msg): img = cesiumpy.entities.material.TemporaryImage(fig) cesiumpy.entities.material.ImageMaterialProperty(img) plt.close()
def test_SingleTimeImageryProvider_tempfile(self): tm._skip_if_no_matplotlib() import numpy as np import matplotlib.pyplot as plt img = np.random.randint(0, 255, (100, 100, 3)) ax = plt.imshow(img) img = cesiumpy.entities.material.TemporaryImage(ax.figure) m = cesiumpy.SingleTileImageryProvider(img, rectangle=(-120.0, 40.0, -100, 60)) self.assertTrue(re.match("""new Cesium\\.SingleTileImageryProvider\\(\\{url : "\w+\\.png", rectangle : Cesium\\.Rectangle\\.fromDegrees\\(-120\\.0, 40\\.0, -100\\.0, 60\\.0\\)\\}\\)""", m.script)) plt.close()
def test_SingleTimeImageryProvider_tempfile(self): tm._skip_if_no_matplotlib() import numpy as np import matplotlib.pyplot as plt img = np.random.randint(0, 255, (100, 100, 3)) ax = plt.imshow(img) img = cesiumpy.entities.material.TemporaryImage(ax.figure) m = cesiumpy.SingleTileImageryProvider(img, rectangle=(-120.0, 40.0, -100, 60)) self.assertTrue( re.match( """new Cesium\\.SingleTileImageryProvider\\(\\{url : "\w+\\.png", rectangle : Cesium\\.Rectangle\\.fromDegrees\\(-120\\.0, 40\\.0, -100\\.0, 60\\.0\\)\\}\\)""", m.script)) plt.close()
def test_contour_xyz(self): _skip_if_no_matplotlib() import numpy as np import matplotlib.mlab as mlab delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np.arange(-2.0, 2.0, delta) X, Y = np.meshgrid(x, y) Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) # difference of Gaussians Z = 10.0 * (Z2 - Z1) viewer = cesiumpy.Viewer() viewer.plot.contour(X, Y, Z) self.assertEqual(len(viewer.entities), 7) self.assertTrue(all(isinstance(x, cesiumpy.Polyline) for x in viewer.entities)) self.assertEqual(viewer.entities[0].material, cesiumpy.color.Color(0.0, 0.0, 0.5, 1.0))
def test_contour_xyz(self): _skip_if_no_matplotlib() import numpy as np import matplotlib.mlab as mlab delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np.arange(-2.0, 2.0, delta) X, Y = np.meshgrid(x, y) Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) # difference of Gaussians Z = 10.0 * (Z2 - Z1) viewer = cesiumpy.Viewer() viewer.plot.contour(X, Y, Z) self.assertEqual(len(viewer.entities), 7) self.assertTrue( all(isinstance(x, cesiumpy.Polyline) for x in viewer.entities)) self.assertEqual(viewer.entities[0].material, cesiumpy.color.Color(0.0, 0.0, 0.5, 1.0))
def test_matplotlibimage(self): tm._skip_if_no_matplotlib() import numpy as np import matplotlib.pyplot as plt img = np.random.randint(0, 255, (100, 100, 3)) ax = plt.imshow(img) img = cesiumpy.entities.material.TemporaryImage(ax.figure) m = cesiumpy.entities.material.ImageMaterialProperty(img) self.assertTrue(re.match("""new Cesium\\.ImageMaterialProperty\\({image : "\w+\\.png"}\\)""", m.script)) img = cesiumpy.entities.material.TemporaryImage(ax) m = cesiumpy.entities.material.ImageMaterialProperty(img) self.assertTrue(re.match("""new Cesium\\.ImageMaterialProperty\\({image : "\w+\\.png"}\\)""", m.script)) plt.close() fig, axes = plt.subplots(2, 2) msg = "Unable to trim a Figure contains multiple Axes" with nose.tools.assert_raises_regexp(ValueError, msg): img = cesiumpy.entities.material.TemporaryImage(fig) cesiumpy.entities.material.ImageMaterialProperty(img) plt.close()
def test_cmap(self): tm._skip_if_no_matplotlib() import matplotlib.pyplot as plt mpl_cmap = plt.get_cmap('winter') cmap = cesiumpy.color.get_cmap('winter') exp = """ColorMap("winter")""" self.assertEqual(repr(cmap), exp) res = cmap(3) exp = mpl_cmap(3) self.assertEqual(res.red, exp[0]) self.assertEqual(res.green, exp[1]) self.assertEqual(res.blue, exp[2]) self.assertEqual(res.alpha, exp[3]) res = cmap([2, 4]) exp = mpl_cmap([2, 4]) for r, e in zip(res, exp): self.assertEqual(r.red, e[0]) self.assertEqual(r.green, e[1]) self.assertEqual(r.blue, e[2]) self.assertEqual(r.alpha, e[3])