Skip to content

Commit

Permalink
Merge pull request #855 from ioam/iris_inverted
Browse files Browse the repository at this point in the history
Fix inverted coords on iris interface
  • Loading branch information
jlstevens committed Sep 9, 2016
2 parents 1fce4b9 + 2fd08f8 commit dec82e4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
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

0 comments on commit dec82e4

Please sign in to comment.