def test_qmesh_contours(self): qmesh = QuadMesh(([0, 1, 2], [1, 2, 3], np.array([[0, 1, 0], [3, 4, 5.], [6, 7, 8]]))) op_contours = contours(qmesh, levels=[0.5]) contour = Contours([[(0, 1.166667, 0.5), (0.5, 1., 0.5), (np.NaN, np.NaN, 0.5), (1.5, 1., 0.5), (2, 1.1, 0.5)]], vdims=qmesh.vdims) self.assertEqual(op_contours, contour)
def test_rasterize_quadmesh(self): qmesh = QuadMesh(([0, 1], [0, 1], np.array([[0, 1], [2, 3]]))) img = rasterize(qmesh, width=3, height=3, dynamic=False, aggregator=ds.mean('z')) image = Image(np.array([[2, 3, 3], [2, 3, 3], [0, 1, 1]]), bounds=(-.5, -.5, 1.5, 1.5)) self.assertEqual(img, image)
def test_qmesh_curvilinear_contours(self): x = y = np.arange(3) xs, ys = np.meshgrid(x, y) zs = np.array([[0, 1, 0], [3, 4, 5.], [6, 7, 8]]) qmesh = QuadMesh((xs, ys + 0.1, zs)) op_contours = contours(qmesh, levels=[0.5]) contour = Contours([[(0, 0.266667, 0.5), (0.5, 0.1, 0.5), (np.NaN, np.NaN, 0.5), (1.5, 0.1, 0.5), (2, 0.2, 0.5)]], vdims=qmesh.vdims) self.assertEqual(op_contours, contour)
def test_rasterize_quadmesh_string_aggregator(self): qmesh = QuadMesh(([0, 1], [0, 1], np.array([[0, 1], [2, 3]]))) img = rasterize(qmesh, width=3, height=3, dynamic=False, aggregator='mean') image = Image(np.array([[2., 3., np.NaN], [0, 1, np.NaN], [np.NaN, np.NaN, np.NaN]]), bounds=(-.5, -.5, 1.5, 1.5)) self.assertEqual(img, image)
def test_quadmesh_string_signature(self): qmesh = QuadMesh(([0, 1], [0, 1], np.array([[0, 1], [0, 1]])), ['a', 'b'], 'c') self.assertEqual(qmesh.kdims, [Dimension('a'), Dimension('b')]) self.assertEqual(qmesh.vdims, [Dimension('c')])
def test_qmesh_slice_xcoords_ycoords(self): sliced = QuadMesh((self.xs[1:], self.ys[:-1], self.zs[:-1, 1:])) self.assertEqual(self.qmesh[100:1000, 2:7], sliced)
def test_qmesh_slice_ycoords(self): sliced = QuadMesh((self.xs, self.ys[:-1], self.zs[:-1, :])) self.assertEqual(self.qmesh[:, 2:7], sliced)
def test_qmesh_index_ycoords(self): sliced = QuadMesh((self.xs, self.ys[-2:], self.zs[-1:, :])) self.assertEqual(self.qmesh[:, 7], sliced)
def test_qmesh_index_xcoords(self): sliced = QuadMesh((self.xs[2:4], self.ys, self.zs[:, 2:3])) self.assertEqual(self.qmesh[300, :], sliced)
def setUp(self): n = 4 self.xs = np.logspace(1, 3, n) self.ys = np.linspace(1, 10, n) self.zs = np.arange((n - 1)**2).reshape(n - 1, n - 1) self.qmesh = QuadMesh((self.xs, self.ys, self.zs))