Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image grid fixes #2117

Merged
merged 4 commits into from
Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion holoviews/core/data/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..sheetcoords import Slice
from .. import util
from .grid import GridInterface
from .interface import Interface
from .interface import Interface, DataError


class ImageInterface(GridInterface):
Expand Down Expand Up @@ -45,6 +45,15 @@ def init(cls, eltype, data, kdims, vdims):
data = data[:, ::-1]
if inverty:
data = data[::-1, :]

expected = (len(ys), len(xs))
shape = data.shape[:2]
error = DataError if len(shape) > 1 else ValueError
if shape != expected and not (not expected and shape == (1,)):
raise error('Key dimension values and value array %s '
'shapes do not match. Expected shape %s, '
'actual shape: %s' % (vdim, expected, shape), cls)

if not isinstance(data, np.ndarray) or data.ndim not in [2, 3]:
raise ValueError('ImageInterface expects a 2D array.')

Expand Down
2 changes: 2 additions & 0 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ def _process(self, element, key=None):
xarr = element.data[vd.name]
if 'datetime' in (xtype, ytype):
xarr = xarr.copy()
if dims != xarr.dims:
xarr = xarr.transpose(*dims)
else:
arr = element.dimension_values(vd, flat=False)
xarr = xr.DataArray(arr, coords=coord_dict, dims=dims)
Expand Down
10 changes: 9 additions & 1 deletion tests/testdatashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ def test_regrid_mean(self):
regridded = regrid(img, width=2, height=2, dynamic=False)
expected = Image(([2., 7.], [0.75, 3.25], [[1, 5], [6, 22]]))
self.assertEqual(regridded, expected)


def test_regrid_mean_xarray_transposed(self):
img = Image((range(10), range(5), np.arange(10) * np.arange(5)[np.newaxis].T),
datatype=['xarray'])
img.data = img.data.T
regridded = regrid(img, width=2, height=2, dynamic=False)
expected = Image(([2., 7.], [0.75, 3.25], [[1, 5], [6, 22]]))
self.assertEqual(regridded, expected)

def test_regrid_rgb_mean(self):
arr = (np.arange(10) * np.arange(5)[np.newaxis].T).astype('f')
rgb = RGB((range(10), range(5), arr, arr*2, arr*2))
Expand Down
16 changes: 15 additions & 1 deletion tests/testimageinterfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from holoviews import Dimension, Image, Curve, RGB, HSV, Dataset, Table
from holoviews.element.comparison import ComparisonTestCase
from holoviews.core.util import date_range
from holoviews.core.data.interface import DataError

from .testdataset import DatatypeContext

Expand All @@ -23,10 +24,23 @@ def setUp(self):
def init_data(self):
self.array = np.arange(10) * np.arange(10)[:, np.newaxis]
self.image = Image(np.flipud(self.array), bounds=(-10, 0, 10, 10))

def tearDown(self):
self.eltype.datatype = self.restore_datatype

def test_init_data_tuple(self):
xs = np.arange(5)
ys = np.arange(10)
array = xs * ys[:, np.newaxis]
image = Image((xs, ys, array))

def test_init_data_tuple_error(self):
xs = np.arange(5)
ys = np.arange(10)
array = xs * ys[:, np.newaxis]
with self.assertRaises(DataError):
Image((ys, xs, array))

def test_init_data_datetime_xaxis(self):
start = np.datetime64(dt.datetime.today())
end = start+np.timedelta64(1, 's')
Expand Down