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

Fix EWA resampling when input data is larger than the output area #398

Merged
merged 2 commits into from
Nov 18, 2021
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
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