Skip to content
Open
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
7 changes: 5 additions & 2 deletions pyresample/resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def compute(self, data, **kwargs):
"""
raise NotImplementedError

def resample(self, data, cache_dir=None, mask_area=None, **kwargs):
def resample(self, data, cache_dir=None, mask_area=None, force=False, **kwargs):
"""Resample `data` by calling `precompute` and `compute` methods.

Only certain resampling classes may use `cache_dir` and the `mask`
Expand All @@ -112,13 +112,16 @@ def resample(self, data, cache_dir=None, mask_area=None, **kwargs):
mask_area (bool): Mask geolocation data where data values are
invalid. This should be used when data values
may affect what neighbors are considered valid.
force (bool): Force resampling by skipping the check for source
and target geometries equality. Can be useful e.g. for
gapfilling data.
kwargs: Keyword arguments to pass to both the ``precompute`` and
``compute`` stages of the resampler.

Returns (xarray.DataArray): Data resampled to the target area

"""
if self._geometries_are_the_same():
if not force and self._geometries_are_the_same():
return data
# default is to mask areas for SwathDefinitions
if mask_area is None and isinstance(
Expand Down
12 changes: 9 additions & 3 deletions pyresample/test/test_resamplers/test_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def test_resampler(src, dst):
(True, "dask"), # same dask tasks are equal
(True, "swath_def"), # same underlying arrays are equal
])
def test_base_resampler_does_nothing_when_src_and_dst_areas_are_equal(_geos_area, use_swaths, copy_dst_swath):
"""Test that the BaseResampler does nothing when the source and target areas are the same."""
@pytest.mark.parametrize("force", [False, True])
def test_base_resampler_does_nothing_when_src_and_dst_areas_are_equal(_geos_area, use_swaths, copy_dst_swath, force):
"""Test that the BaseResampler does nothing when the source and target areas are the same, unless forced."""
src_geom = _geos_area if not use_swaths else _xarray_swath_def_from_area(_geos_area)
dst_geom = src_geom
if copy_dst_swath == "dask":
Expand All @@ -97,7 +98,12 @@ def test_base_resampler_does_nothing_when_src_and_dst_areas_are_equal(_geos_area

resampler = BaseResampler(src_geom, dst_geom)
some_data = xr.DataArray(da.zeros(src_geom.shape, dtype=np.float64), dims=('y', 'x'))
assert resampler.resample(some_data) is some_data

if not force:
assert resampler.resample(some_data, force=force) is some_data
else:
with pytest.raises(NotImplementedError):
resampler.resample(some_data, force=force)


@pytest.mark.parametrize(
Expand Down
Loading