Skip to content

Commit

Permalink
FIX: fixing floating point errors causing nan's at tile edges when th…
Browse files Browse the repository at this point in the history
…e request *nearly* matches the source coordinates (up to floating point error)
  • Loading branch information
mpu-creare authored and joffreypeters committed Mar 27, 2021
1 parent c792890 commit 8ac834d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion podpac/core/interpolation/nearest_neighbor_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ def select_coordinates(self, udims, source_coordinates, eval_coordinates, index_
if src_coords.size == 1:
c = src_coords.copy()
else:
c = UniformCoordinates1d(src_start, src_stop, ndelta * src_delta, **src_coords.properties)
c = UniformCoordinates1d(
src_start,
src_stop + ndelta * src_delta / 2, # The delta/2 ensures the endpoint is included
ndelta * src_delta,
**src_coords.properties)

if isinstance(idx, slice):
idx = slice(idx.start, idx.stop, int(ndelta))
Expand Down
14 changes: 12 additions & 2 deletions podpac/core/interpolation/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,21 @@ def _select_uniform(self, source, request, index_type):
return np.arange(source.size)

index = (crds.coordinates - source.start) / source.step
stop_ind = int(np.round((source.stop - source.start) / source.step))
stop_ind = source.size - 1
if len(self.method) > 1:
flr_ceil = {-1: np.floor(index), 1: np.ceil(index)}
else:
flr_ceil = {0: np.round(index)}
# In this case, floating point error really matters, so we have to do a test
up = np.round(index - 1e-6)
down = np.round(index + 1e-6)
# When up and down do not agree, use the index that will be kept.
index_mid = down # arbitrarily default to down when both satisfy criteria
Iup = up != down
Iup[Iup] = (up[Iup] >= 0) & (up[Iup] <= stop_ind) & ((up[Iup] > down.max()) | (up[Iup] < down.min()))
index_mid[Iup] = up[Iup]
flr_ceil = {0: index_mid}
# flr_ceil = {0: index}

inds = []
for m in self.method:
sign = np.sign(m)
Expand Down

0 comments on commit 8ac834d

Please sign in to comment.