Skip to content

Commit

Permalink
Update contours operation to work with QuadMesh (#2702)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed May 21, 2018
1 parent 18ca8a4 commit 234a3e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions holoviews/operation/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ def _process(self, element, key=None):
elif isinstance(element, Image):
data = [np.flipud(element.dimension_values(2, flat=False))]
elif isinstance(element, QuadMesh):
data = (element.dimension_values(0, False),
element.dimension_values(1, False),
element.data[2])
data = (element.dimension_values(0, False, flat=False),
element.dimension_values(1, False, flat=False),
element.dimension_values(2, flat=False))

if isinstance(self.p.levels, int):
levels = self.p.levels+2 if self.p.filled else self.p.levels+3
Expand Down
26 changes: 25 additions & 1 deletion tests/operation/testoperation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from nose.plugins.attrib import attr

from holoviews import (HoloMap, NdOverlay, NdLayout, GridSpace, Image,
Contours, Polygons, Points, Histogram, Curve, Area)
Contours, Polygons, Points, Histogram, Curve, Area,
QuadMesh)
from holoviews.element.comparison import ComparisonTestCase
from holoviews.operation.element import (operation, transform, threshold,
gradient, contours, histogram,
Expand Down Expand Up @@ -63,6 +64,29 @@ def test_image_contours(self):
vdims=img.vdims)
self.assertEqual(op_contours, contour)

@attr(optional=1) # Requires matplotlib
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)

@attr(optional=1) # Requires matplotlib
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)

@attr(optional=1) # Requires matplotlib
def test_image_contours_filled(self):
img = Image(np.array([[0, 1, 0], [3, 4, 5.], [6, 7, 8]]))
Expand Down

0 comments on commit 234a3e4

Please sign in to comment.