Skip to content

Commit 0890644

Browse files
authored
Merge pull request #741 from Manny7717/fix/ewa-fill-value
Fix user fill value not being used in EWA
2 parents 7272ffc + 4a46786 commit 0890644

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

‎pyresample/ewa/ewa.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def fornav(cols, rows, area_def, data_in,
108108
If `data_in` is made of numpy arrays then this represents the fill
109109
value used to mark invalid data pixels. This value will also be
110110
used in the output array(s). If None, then np.nan will be used
111-
for float arrays and -999 will be used for integer arrays.
111+
for float arrays and the maximum value of the data type will be
112+
used for integer arrays (ex. 127 for int8).
112113
out : numpy array or tuple of numpy arrays, optional
113114
Specify a numpy array to be written to for each input array. This can
114115
be used as an optimization by providing `np.memmap` arrays or other
@@ -167,7 +168,7 @@ def fornav(cols, rows, area_def, data_in,
167168
rows_per_scan = rows_per_scan or data_in[0].shape[0]
168169

169170
results = _fornav.fornav_wrapper(cols, rows, data_in, out,
170-
np.nan, np.nan, rows_per_scan,
171+
fill, fill, rows_per_scan,
171172
weight_count=weight_count,
172173
weight_min=weight_min,
173174
weight_distance_max=weight_distance_max,
@@ -208,7 +209,7 @@ def _data_in_as_masked_arrays(
208209
if np.issubdtype(data_in[0].dtype, np.floating):
209210
fill = np.nan
210211
elif np.issubdtype(data_in[0].dtype, np.integer):
211-
fill = -999
212+
fill = np.iinfo(data_in[0].dtype).max
212213
else:
213214
raise ValueError(
214215
"Unsupported input data type for EWA Resampling: {}".format(data_in[0].dtype))

‎pyresample/test/test_ewa_fornav.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,49 @@ def test_fornav_swath_larger_float32(self):
194194
msg="Unexpected interpolation values were returned")
195195

196196

197+
def _partial_coverage_swath(dtype):
198+
"""Create an all-ones swath that covers only part of a 1000x1000 grid.
199+
200+
The right side of the grid is left uncovered so the output is guaranteed
201+
to contain fill pixels as well as data pixels.
202+
"""
203+
swath_shape = (1600, 3200)
204+
rows = np.empty(swath_shape, dtype=np.float32)
205+
rows[:] = np.linspace(-500, 2500, swath_shape[0])[:, None]
206+
cols = np.empty(swath_shape, dtype=np.float32)
207+
cols[:] = np.linspace(-2500, 500, swath_shape[1])
208+
data = np.ones(swath_shape, dtype=dtype)
209+
out = np.empty((1000, 1000), dtype=dtype)
210+
return cols, rows, data, out
211+
212+
213+
@pytest.mark.parametrize(
214+
("dtype", "fill", "expected_fill"),
215+
[
216+
(np.int8, 0, 0),
217+
(np.int8, None, 127),
218+
(np.float32, 0.0, 0.0),
219+
(np.float32, None, np.nan),
220+
(np.float64, -999.0, -999.0),
221+
(np.float64, np.nan, np.nan),
222+
],
223+
)
224+
def test_fornav_fill_used_in_output(dtype, fill, expected_fill):
225+
"""Test that the user-supplied or default fill value is written to uncovered pixels (#689)."""
226+
from pyresample.ewa import fornav
227+
cols, rows, data, out = _partial_coverage_swath(dtype)
228+
229+
grid_points_covered, out_res = fornav(cols, rows, None, data,
230+
rows_per_scan=16, fill=fill, out=out)
231+
232+
assert out is out_res
233+
assert grid_points_covered > 0
234+
# The swath was all 1s so every grid cell is either data or the fill value
235+
is_fill = np.isnan(out) if np.isnan(expected_fill) else out == expected_fill
236+
assert ((out == 1) | is_fill).all(), "Output should only contain data and fill values"
237+
assert is_fill.any(), "Uncovered pixels should contain the fill value"
238+
239+
197240
@pytest.mark.parametrize(
198241
("dtype", "input_fill", "output_fill"),
199242
[

0 commit comments

Comments
 (0)