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

Fix inverted coords on iris interface #855

Merged
merged 2 commits into from Sep 9, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions holoviews/core/data/grid.py
Expand Up @@ -129,7 +129,7 @@ def canonicalize(cls, dataset, data, coord_dims=None):
dimensions of the dataset.
"""
if coord_dims is None:
coord_dims = dataset.dimensions('key', True)
coord_dims = dataset.dimensions('key', True)[::-1]

# Reorient data
invert = False
Expand All @@ -141,7 +141,7 @@ def canonicalize(cls, dataset, data, coord_dims=None):
invert = True
else:
slices.append(slice(None))
data = data.__getitem__(slices[::-1]) if invert else data
data = data.__getitem__(slices) if invert else data

# Transpose data
dims = [name for name in coord_dims[::-1]
Expand All @@ -150,7 +150,7 @@ def canonicalize(cls, dataset, data, coord_dims=None):
inds = [dims.index(kd.name) for kd in dataset.kdims]
inds += dropped
if inds:
data = data.transpose(inds[::-1])
data = data.transpose(inds)

# Allow lower dimensional views into data
if len(dataset.kdims) < 2:
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/data/iris.py
Expand Up @@ -137,7 +137,7 @@ def values(cls, dataset, dim, expanded=True, flat=True):
dim = dataset.get_dimension(dim)
if dim in dataset.vdims:
coord_names = [c.name() for c in dataset.data.dim_coords]
data = dataset.data.copy().data.T
data = dataset.data.copy().data
data = cls.canonicalize(dataset, data, coord_names)
return data.T.flatten() if flat else data
elif expanded:
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/data/xarray.py
Expand Up @@ -132,7 +132,7 @@ def coords(cls, dataset, dim, ordered=False, expanded=False):
def values(cls, dataset, dim, expanded=True, flat=True):
data = dataset.data[dim].data
if dim in dataset.vdims:
coord_dims = dataset.data[dim].dims[::-1]
coord_dims = dataset.data[dim].dims
data = cls.canonicalize(dataset, data, coord_dims=coord_dims)
return data.T.flatten() if flat else data
elif expanded:
Expand Down
13 changes: 13 additions & 0 deletions tests/testdataset.py
Expand Up @@ -447,6 +447,19 @@ def init_data(self):
self.grid_zs), kdims=['x', 'y'],
vdims=['z'])

def test_canonical_vdim(self):
x = np.array([ 0. , 0.75, 1.5 ])
y = np.array([ 1.5 , 0.75, 0. ])
z = np.array([[ 0.06925999, 0.05800389, 0.05620127],
[ 0.06240918, 0.05800931, 0.04969735],
[ 0.05376789, 0.04669417, 0.03880118]])
dataset = Dataset((x, y, z), kdims=['x', 'y'], vdims=['z'])
canonical = np.array([[ 0.05376789, 0.04669417, 0.03880118],
[ 0.06240918, 0.05800931, 0.04969735],
[ 0.06925999, 0.05800389, 0.05620127]])
self.assertEqual(dataset.dimension_values('z', flat=False),
canonical)

def test_dataset_dim_vals_grid_kdims_xs(self):
self.assertEqual(self.dataset_grid.dimension_values(0, expanded=False),
np.array([0, 1]))
Expand Down