Skip to content

Commit

Permalink
FIX: Fixing reproject merge_dims error.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpu-creare committed Apr 29, 2021
1 parent 2ec227a commit 8f09cd0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 6 additions & 2 deletions podpac/core/algorithm/reprojection.py
@@ -1,5 +1,5 @@
"""
Reprojection Algorithm Node
Reprojection Algorithm Node
"""

from __future__ import division, unicode_literals, print_function, absolute_import
Expand Down Expand Up @@ -79,7 +79,11 @@ def reprojection_coordinates(self):

def _source_eval(self, coordinates, selector, output=None):
coords = self.reprojection_coordinates.intersect(coordinates, outer=True)
coords = merge_dims([coords, coordinates.drop(self.reproject_dims or self.reprojection_coordinates.dims)])
my_coords = coordinates.drop(self.reproject_dims or self.reprojection_coordinates.dims)
if coords.crs != coordinates.crs:
# Better to evaluate in reproject coordinate crs than eval crs for next step of interpolation
my_coords = my_coords.transform(coords.crs)
coords = merge_dims([coords, my_coords])
return self.source.eval(coords, output=output, _selector=selector)

@property
Expand Down
36 changes: 35 additions & 1 deletion podpac/core/algorithm/test/test_reprojection.py
Expand Up @@ -3,7 +3,7 @@
import pytest

import numpy as np
from numpy.testing import assert_equal, assert_array_equal
from numpy.testing import assert_equal, assert_array_equal, assert_almost_equal
import traitlets as tl

import podpac
Expand All @@ -19,6 +19,11 @@ class TestReprojection(object):
source_coarse = Array(
source=[[0, 4, 8], [36, 40, 44], [72, 76, 80]], coordinates=coarse_coords, interpolation="bilinear"
)
source_coarse2 = Array(
source=[[0, 4, 8], [36, 40, 44], [72, 76, 80]],
coordinates=coarse_coords.transform("EPSG:3857"),
interpolation="bilinear",
)

def test_reprojection_Coordinates(self):
reproject = Reproject(source=self.source, interpolation="bilinear", coordinates=self.coarse_coords)
Expand Down Expand Up @@ -63,3 +68,32 @@ def test_reprojection_source_str(self):
node = podpac.Node.from_json(reproject.json)
o3 = node.eval(self.coarse_coords)
assert_array_equal(o1.data, o3.data)

def test_reprojection_Coordinates_crs(self):
# same eval and source but different reproject
reproject = Reproject(
source=self.source,
interpolation={"method": "bilinear", "params": {"fill_value": "extrapolate"}},
coordinates=self.coarse_coords.transform("EPSG:3857"),
)
o1 = reproject.eval(self.source_coords)
# We have to use a second source here because the reprojected source
# gets interpreted as having it's source coordinates in EPSG:3857
# and when being subsampled, there's a warping effect...
o2 = self.source_coarse2.eval(self.source_coords)
assert_almost_equal(o1.data, o2.data, decimal=13)

node = podpac.Node.from_json(reproject.json)
o3 = node.eval(self.source_coords)
assert_array_equal(o1.data, o3.data)

# same eval and reproject but different source
o1 = reproject.eval(self.source_coords.transform("EPSG:3857"))
o2 = self.source_coarse2.eval(self.source_coords.transform("EPSG:3857"))
assert_almost_equal(o1.data, o2.data, decimal=13)

# same source and reproject but different eval
reproject = Reproject(source=self.source, interpolation="bilinear", coordinates=self.coarse_coords)
o1 = reproject.eval(self.source_coords.transform("EPSG:3857"))
o2 = self.source_coarse.eval(self.source_coords.transform("EPSG:3857"))
assert_almost_equal(o1.data, o2.data, decimal=13)

0 comments on commit 8f09cd0

Please sign in to comment.