Skip to content

Commit 54bb77a

Browse files
author
cpelley
committed
ENH: Return nan values where no source cells contribute to a target cell.
TODO: Update tests
1 parent 20eb3f5 commit 54bb77a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

stratify/_conservative.pyx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@ cdef apply_weights(np.ndarray[np.float64_t, ndim=3] src_point,
5151
"""
5252
Perform conservative interpolation.
5353
54-
Conservation interpolation on of a dataset between a provided source
55-
coordinate and a target coordinate.
54+
Conservation interpolation of a dataset between a provided source
55+
coordinate and a target coordinate. Where no source cells contribute to a
56+
target cell, a np.nan value is returned.
5657
5758
Parameters
5859
----------
5960
src_points (3d double array) - Source coordinate, taking the form
6061
[axis_interpolation, z_varying, 2].
6162
tgt_points (3d double array) - Target coordinate, taking the form
6263
[axis_interpolation, z_varying, 2].
63-
src_data (3d double array) - The source data, the phenonenon data to be
64+
src_data (3d double array) - The source data, the phenomenon data to be
6465
interpolated from ``src_points`` to ``tgt_points``. Taking the form
6566
[broadcasting_dims, axis_interpolation, z_varying].
6667
@@ -85,6 +86,8 @@ cdef apply_weights(np.ndarray[np.float64_t, ndim=3] src_point,
8586
raise ValueError(msg)
8687
results[..., ind] = (
8788
weights * src_data[..., ind][..., None]).sum(axis=1)
89+
# Return np.nan for those target cells where no source contributes.
90+
results[:, weights.sum(axis=0) == 0, :] = np.nan
8891
return results
8992

9093

0 commit comments

Comments
 (0)