Skip to content

Commit

Permalink
Removed affine dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 27, 2018
1 parent d431f7b commit e1c4526
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION flake8 scipy=1.0.0 numpy freetype nose pandas=0.22.0 jupyter ipython=5.4.1 param matplotlib=2.1.2 xarray networkx affine
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION flake8 scipy=1.0.0 numpy freetype nose pandas=0.22.0 jupyter ipython=5.4.1 param matplotlib=2.1.2 xarray networkx
- source activate test-environment
- conda install -c conda-forge filelock iris plotly=2.7 flexx=0.4.1 ffmpeg netcdf4=1.3.1 --quiet
- conda install -c bokeh datashader dask bokeh=0.12.15 selenium
Expand Down
3 changes: 3 additions & 0 deletions holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ def coords(cls, dataset, dimension, ordered=False, expanded=False, edges=False):
data = cls._infer_interval_breaks(data)
elif not edges and isedges:
data = np.convolve(data, [0.5, 0.5], 'valid')

if isinstance(data, xr.DataArray):
return data.values
return data


Expand Down
13 changes: 10 additions & 3 deletions tests/core/data/testgridinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ def test_dataset_dataframe_init_hm_alias(self):
kdims=['x'], vdims=['x2'])

def test_irregular_grid_data_values(self):
from affine import Affine
transform = Affine(3, 0, 2, 0, -2, -2)
nx, ny = 20, 5
xs, ys = np.meshgrid(np.arange(nx)+0.5, np.arange(ny)+0.5) * transform
xs, ys = np.meshgrid(np.arange(nx)+0.5, np.arange(ny)+0.5)
zs = np.arange(100).reshape(5, 20)
ds = Dataset((xs, ys, zs), ['x', 'y'], 'z')
self.assertEqual(ds.dimension_values(2, flat=False), zs)
self.assertEqual(ds.interface.coords(ds, 'x'), xs)
self.assertEqual(ds.interface.coords(ds, 'y'), ys)

def test_irregular_grid_data_values_inverted_y(self):
nx, ny = 20, 5
xs, ys = np.meshgrid(np.arange(nx)+0.5, np.arange(ny)*-1+0.5)
zs = np.arange(100).reshape(5, 20)
ds = Dataset((xs, ys, zs), ['x', 'y'], 'z')
self.assertEqual(ds.dimension_values(2, flat=False), zs)
Expand Down
25 changes: 7 additions & 18 deletions tests/core/data/testxarrayinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ class XArrayInterfaceTests(GridInterfaceTests):
data_type = xr.Dataset

def get_irregular_dataarray(self, invert_y=True):
from affine import Affine
multiplier = -1 if invert_y else 1
x = np.arange(2, 62, 3)
y = np.arange(2, 12, 2) * multiplier
da = xr.DataArray(
data=[np.arange(100).reshape(5, 20)],
coords={'band': [1], 'x': np.arange(2, 62, 3), 'y': np.arange(2, 12, 2) * multiplier},
coords={'band': [1], 'x': x, 'y': y},
dims=['band', 'y','x'],
attrs={'transform': (3, 0, 2, 0, -2, -2)})
transform = Affine(*da.transform)
nx, ny = da.sizes['x'], da.sizes['y']
x, y = np.meshgrid(np.arange(nx)+0.5, np.arange(ny)+0.5) * transform
return da.assign_coords(**{'xc': xr.DataArray(x, dims=('y','x')),
'yc': xr.DataArray(y, dims=('y','x')),})
xs, ys = (np.tile(x[:, np.newaxis], len(y)).T,
np.tile(y[:, np.newaxis], len(x)))
return da.assign_coords(**{'xc': xr.DataArray(xs, dims=('y','x')),
'yc': xr.DataArray(ys, dims=('y','x')),})

def test_xarray_dataset_with_scalar_dim_canonicalize(self):
xs = [0, 1]
Expand Down Expand Up @@ -124,17 +124,6 @@ def test_xarray_coord_ordering(self):
ds = Dataset(dataset)
self.assertEqual(ds.kdims, ['b', 'c', 'a'])

def test_irregular_grid_data_values(self):
from affine import Affine
transform = Affine(3, 0, 2, 0, -2, -2)
nx, ny = 20, 5
xs, ys = np.meshgrid(np.arange(nx)+0.5, np.arange(ny)+0.5) * transform
zs = np.arange(100).reshape(5, 20)
ds = Dataset((xs, ys, zs), ['x', 'y'], 'z')
self.assertEqual(ds.dimension_values(2, flat=False), zs)
self.assertEqual(ds.interface.coords(ds, 'x').values, xs)
self.assertEqual(ds.interface.coords(ds, 'y').values, ys)

def test_irregular_and_regular_coordinate_inference(self):
data = self.get_irregular_dataarray()
ds = Dataset(data, vdims='Value')
Expand Down

0 comments on commit e1c4526

Please sign in to comment.