From ba0b959f12e6b8b55150aa1897cfec1a2c8d4aff Mon Sep 17 00:00:00 2001 From: andream Date: Thu, 21 May 2026 13:07:30 +0000 Subject: [PATCH 1/3] add force argument --- pyresample/resampler.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyresample/resampler.py b/pyresample/resampler.py index 2d6dbcf92..d372c3073 100644 --- a/pyresample/resampler.py +++ b/pyresample/resampler.py @@ -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` @@ -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( From 555776b9437729fcb884f53fefacc5c9a2700211 Mon Sep 17 00:00:00 2001 From: andream Date: Thu, 21 May 2026 13:18:22 +0000 Subject: [PATCH 2/3] add test for force argument --- pyresample/test/test_resamplers/test_resampler.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyresample/test/test_resamplers/test_resampler.py b/pyresample/test/test_resamplers/test_resampler.py index d7065058e..4bbeb07cf 100644 --- a/pyresample/test/test_resamplers/test_resampler.py +++ b/pyresample/test/test_resamplers/test_resampler.py @@ -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": @@ -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( From 2e7a3c85c5ba23fd8d0e925e6755e96e179f00d4 Mon Sep 17 00:00:00 2001 From: andream Date: Thu, 21 May 2026 13:29:23 +0000 Subject: [PATCH 3/3] add space --- pyresample/resampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyresample/resampler.py b/pyresample/resampler.py index d372c3073..16ac3393a 100644 --- a/pyresample/resampler.py +++ b/pyresample/resampler.py @@ -95,7 +95,7 @@ def compute(self, data, **kwargs): """ raise NotImplementedError - def resample(self, data, cache_dir=None, mask_area=None, force=False,**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`