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

Added fixes for longitude wrapping when projecting Image #260

Merged
merged 8 commits into from
Dec 22, 2018
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
3 changes: 3 additions & 0 deletions geoviews/element/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def __init__(self, data, kdims=None, vdims=None, **params):
% type(data).__name__)
super(Feature, self).__init__(data, kdims=kdims, vdims=vdims, **params)

def __call__(self, *args, **kwargs):
return self.opts(*args, **kwargs)

def range(self, dim, data_range=True, dimension_range=True):
didx = self.get_dimension_index(dim)
if didx in [0, 1] and data_range:
Expand Down
13 changes: 6 additions & 7 deletions geoviews/operation/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _process_element(self, element):
if np.all(X[0, 1:] < X[0, :-1]):
X = X[:, ::-1]
Y = element.interface.coords(element, 1, True, True, False)
if np.all(Y[1:, 0] > X[:-1, 0]):
if np.all(Y[1:, 0] < Y[:-1, 0]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Copy-paste error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, yes.

Y = Y[::-1, :]

if X.shape != zs.shape:
Expand Down Expand Up @@ -302,8 +302,6 @@ def _process(self, img, key=None):
if self.p.fast:
return self._fast_process(img, key)
proj = self.p.projection
if proj == img.crs:
return img
x0, x1 = img.range(0)
y0, y1 = img.range(1)
xn, yn = img.interface.shape(img, gridded=True)[:2]
Expand All @@ -319,10 +317,11 @@ def _process(self, img, key=None):
else:
projected, extents = arr, trgt_ext
arrays.append(projected)
projected = np.dstack(arrays) if len(arrays) > 1 else arrays[0]
data = np.flipud(projected)
bounds = (extents[0], extents[2], extents[1], extents[3])
return img.clone(data, bounds=bounds, kdims=img.kdims,
xunit = ((extents[1]-extents[0])/float(xn))/2.
yunit = ((extents[3]-extents[2])/float(yn))/2.
xs = np.linspace(extents[0]+xunit, extents[1]-xunit, xn)
ys = np.linspace(extents[2]+yunit, extents[3]-yunit, yn)
return img.clone((xs, ys, *arrays), bounds=None, kdims=img.kdims,
vdims=img.vdims, crs=proj, xdensity=None,
ydensity=None)

Expand Down
37 changes: 37 additions & 0 deletions geoviews/tests/testprojection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import numpy as np
import cartopy.crs as ccrs

from geoviews.element import Image
from geoviews.element.comparison import ComparisonTestCase
from geoviews.operation import project


class TestProjection(ComparisonTestCase):

def test_image_latlon360_wrapping(self):
xs = np.linspace(0, 360, 5)
ys = np.linspace(-90, 90, 3)
img = Image((xs, ys, xs[np.newaxis, :]*ys[:, np.newaxis]))
proj = project(img, projection=ccrs.PlateCarree())
zs = proj.dimension_values('z', flat=False)
self.assertEqual(zs, np.array([
[-24300., -0., -8100.],
[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.],
[ 24300., 0., 8100.]
]))

def test_image_project_latlon_to_mercator(self):
xs = np.linspace(0, 360, 5)
ys = np.linspace(-90, 90, 3)
img = Image((xs, ys, xs[np.newaxis, :]*ys[:, np.newaxis]))
proj = project(img)
zs = proj.dimension_values('z', flat=False)
self.assertEqual(zs, np.array([
[-24300., -0., -8100.],
[-24300., -0., -8100.],
[ 0., 0., 0.],
[ 24300., 0., 8100.],
[ 24300., 0., 8100.]
]))
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def package_assets(example_path):

_required = [
'bokeh >=0.12.15',
'cartopy >=0.14.2', # prevents pip alone (requires external package manager)
'holoviews >=1.11.0a9',
'cartopy >=0.16.0', # prevents pip alone (requires external package manager)
'holoviews ==1.11.0a11',
'numpy >=1.0',
'param >=1.6.1'
]
Expand Down