Skip to content

Commit

Permalink
Merge pull request #398 from djhoese/bugfix-ewa-zero
Browse files Browse the repository at this point in the history
Fix EWA resampling when input data is larger than the output area
  • Loading branch information
djhoese authored Nov 18, 2021
2 parents d219e1f + e2cf8af commit 0f8c559
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pyresample/ewa/_fornav_templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ int compute_ewa(size_t chan_count, int maximum_weight_mode,
u0 = uimg[swath_offset];
v0 = vimg[swath_offset];

if (u0 < 0.0 || v0 < 0.0 || __isnan(u0) || __isnan(v0)) {
if (u0 < -this_ewap->u_del || v0 < -this_ewap->v_del || __isnan(u0) || __isnan(v0)) {
continue;
}

Expand Down Expand Up @@ -352,15 +352,14 @@ int compute_ewa_single(int maximum_weight_mode,
IMAGE_TYPE this_val;
unsigned int swath_offset;
unsigned int grid_offset;
size_t chan;

got_point = 0;
for (row = 0, swath_offset=0; row < swath_rows; row+=1) {
for (col = 0, this_ewap = ewap; col < swath_cols; col++, this_ewap++, swath_offset++) {
u0 = uimg[swath_offset];
v0 = vimg[swath_offset];

if (u0 < 0.0 || v0 < 0.0 || __isnan(u0) || __isnan(v0)) {
if (u0 < -this_ewap->u_del || v0 < -this_ewap->v_del || __isnan(u0) || __isnan(v0)) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions pyresample/ewa/dask_ewa.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ def _run_fornav_single(self, data, out_chunks, target_geo_def, fill_value, **kwa
ll2cr_blocks = self.cache['ll2cr_blocks'].items()
ll2cr_numblocks = ll2cr_result.shape if isinstance(ll2cr_result, np.ndarray) else ll2cr_result.numblocks
fornav_task_name = "fornav-{}".format(data.name)
maximum_weight_mode = kwargs.get('maximum_weight_mode', False)
weight_sum_min = kwargs.get('weight_sum_min', -1.0)
maximum_weight_mode = kwargs.setdefault('maximum_weight_mode', False)
weight_sum_min = kwargs.setdefault('weight_sum_min', -1.0)
output_stack = self._generate_fornav_dask_tasks(out_chunks,
ll2cr_blocks,
fornav_task_name,
Expand Down
22 changes: 22 additions & 0 deletions pyresample/test/test_ewa_fornav.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ def test_fornav_swath_larger(self):
self.assertTrue(((out == 1) | np.isnan(out)).all(),
msg="Unexpected interpolation values were returned")

def test_fornav_swath_wide_input(self):
"""Test that a swath with large input pixels on the left edge of the output."""
from pyresample.ewa import _fornav
swath_shape = (400, 800)
data_type = np.float32
# Create a fake row and cols array
rows = np.empty(swath_shape, dtype=np.float32)
rows[:] = np.linspace(-500, 500, 400)[:, None]
cols = np.empty(swath_shape, dtype=np.float32)
cols[:] = np.linspace(-500, 500, 800) + 0.5
rows_per_scan = 16
# Create a fake data swath
data = np.ones(swath_shape, dtype=data_type)
out = np.empty((800, 1000), dtype=data_type)

grid_points_covered = _fornav.fornav_wrapper(cols, rows, (data,), (out,),
np.nan, np.nan, rows_per_scan)
one_grid_points_covered = grid_points_covered[0]
# the upper-left 500x500 square should be filled with 1s at least
assert 500 * 500 <= one_grid_points_covered <= 505 * 505
np.testing.assert_allclose(out[:500, :500], 1)

def test_fornav_swath_smaller(self):
"""Test that a swath smaller than the output grid is entirely used."""
from pyresample.ewa import _fornav
Expand Down

0 comments on commit 0f8c559

Please sign in to comment.