Skip to content

Commit

Permalink
Added unit tests for datashading QuadMesh
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 20, 2017
1 parent 36a2ec4 commit a68631d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
31 changes: 29 additions & 2 deletions tests/testdatashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from nose.plugins.attrib import attr

import numpy as np
from holoviews import Curve, Points, Image, Dataset, RGB, Path, Graph
from holoviews import Curve, Points, Image, Dataset, RGB, Path, Graph, TriMesh, QuadMesh
from holoviews.element.comparison import ComparisonTestCase

try:
import datashader as ds
from holoviews.operation.datashader import (
aggregate, regrid, ds_version, stack, directly_connect_edges
aggregate, regrid, ds_version, stack, directly_connect_edges, rasterize
)
except:
ds_version = None
Expand All @@ -19,6 +20,9 @@ class DatashaderAggregateTests(ComparisonTestCase):
Tests for datashader aggregation
"""

def setUp(self):
raise SkipTest()

def test_aggregate_points(self):
points = Points([(0.2, 0.3), (0.4, 0.7), (0, 0.99)])
img = aggregate(points, dynamic=False, x_range=(0, 1), y_range=(0, 1),
Expand Down Expand Up @@ -150,11 +154,34 @@ def test_regrid_disabled_expand(self):
self.assertEqual(regridded, img)


@attr(optional=1)
class DatashaderRasterizeTests(ComparisonTestCase):
"""
Tests for datashader aggregation
"""

def test_rasterize_trimesh(self):
simplices = [(0, 1, 2, 0.5), (3, 2, 1, 1.5)]
vertices = [(0., 0.), (0., 1.), (1., 0), (1, 1)]
trimesh = TriMesh((simplices, vertices), vdims=['z'])
img = rasterize(trimesh, width=3, height=3, dynamic=False, aggregator=ds.mean('z'))
image = Image(np.array([[1.5, 1.5, np.NaN], [0.5, 1.5, np.NaN], [np.NaN, np.NaN, np.NaN]]),
bounds=(0, 0, 1, 1))
self.assertEqual(img, image)

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., np.NaN], [0, 1, np.NaN], [np.NaN, np.NaN, np.NaN]]),
bounds=(-.5, -.5, 1.5, 1.5))
self.assertEqual(img, image)


@attr(optional=1)
class DatashaderStackTests(ComparisonTestCase):

def setUp(self):
raise SkipTest()
self.rgb1_arr = np.array([[[0, 1], [1, 0]],
[[1, 0], [0, 1]],
[[0, 0], [0, 0]]], dtype=np.uint8).T*255
Expand Down
18 changes: 17 additions & 1 deletion tests/testraster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import numpy as np
from holoviews.element import Raster, Image, Curve, QuadMesh
from holoviews.element import Raster, Image, Curve, QuadMesh, TriMesh
from holoviews.element.comparison import ComparisonTestCase

class TestRaster(ComparisonTestCase):
Expand Down Expand Up @@ -75,3 +75,19 @@ def test_cast_image_to_quadmesh(self):
self.assertEqual(qmesh.group, img.group)
self.assertEqual(qmesh.label, img.label)

def test_quadmesh_to_trimesh(self):
qmesh = QuadMesh(([0, 1], [0, 1], np.array([[0, 1], [2, 3]])))
trimesh = qmesh.trimesh()
simplices = np.array([[0, 1, 3, 0],
[1, 2, 4, 2],
[3, 4, 6, 1],
[4, 5, 7, 3],
[4, 3, 1, 0],
[5, 4, 2, 2],
[7, 6, 4, 1],
[8, 7, 5, 3]])
vertices = np.array([(-0.5, -0.5), (-0.5, 0.5), (-0.5, 1.5),
(0.5, -0.5), (0.5, 0.5), (0.5, 1.5),
(1.5, -0.5), (1.5, 0.5), (1.5, 1.5)])
self.assertEqual(trimesh.array(), simplices)
self.assertEqual(trimesh.nodes.array([0, 1]), vertices)

0 comments on commit a68631d

Please sign in to comment.