pyresample icon indicating copy to clipboard operation
pyresample copied to clipboard

`gradient_search` producing nan output for some resampling operations

Open simonrp84 opened this issue 2 years ago • 1 comments

In the latest pyresample release the gradient_search resampler is returning arrays containing only np.nan values for some resampling operations. Previous releases did not do this.

In my workflow I'm resampling a gridded lat/lon dataset onto the SEVIRI grid, and I've used that to produce this example:

from pyresample import create_area_def
from datetime import datetime
import dask.array as da
from satpy import Scene
import xarray as xr
import numpy as np

dater = datetime.utcnow()

lon = np.arange(-180, 180, 0.25)
lat = np.arange(-90, 90+0.25, 0.25)

inv = np.random.uniform(low=0., high=1., size=(lat.shape[0], lon.shape[0]))

area_ext = (np.nanmin(lon), np.nanmin(lat), np.nanmax(lon), np.nanmax(lat))
targ_area = create_area_def("source_area",
                            "EPSG:4326",
                            area_extent=area_ext,
                            width=inv.shape[1],
                            height=inv.shape[0])

ecm_scn = Scene()

ecm_scn['test'] = xr.DataArray(da.from_array(inv),
                            coords={'y': lat, 'x': lon},
                            attrs={'start_time': dater})

ecm_scn['test'].attrs['area'] = targ_area

print("Nearest")
ecm_snm_res = ecm_scn.resample('msg_seviri_fes_3km', resampler='nearest')
print(np.nanmin(ecm_snm_res['test']), np.nanmean(ecm_snm_res['test']), np.nanmax(ecm_snm_res['test']))

print("Bilinear")
ecm_snm_res = ecm_scn.resample('msg_seviri_fes_3km', resampler='bilinear')
print(np.nanmin(ecm_snm_res['test']), np.nanmean(ecm_snm_res['test']), np.nanmax(ecm_snm_res['test']))

print("Gradient search")
ecm_snm_res = ecm_scn.resample('msg_seviri_fes_3km', resampler='gradient_search')
print(np.nanmin(ecm_snm_res['test']), np.nanmean(ecm_snm_res['test']), np.nanmax(ecm_snm_res['test']))

Prints:

Nearest
1.757739096830413e-06 0.5006533072205385 0.9999969024153488

Bilinear
0.002291159924354849 0.5006759644036226 0.9965275266396012

Gradient search
nan nan nan

simonrp84 avatar Aug 05 '22 14:08 simonrp84

Thanks a lot for reporting this!

mraspaud avatar Aug 05 '22 18:08 mraspaud