Commit d6d8a2e8 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Use NumpyBilinearResampler instead of the deprecated resample_bilinear().


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 0ee463de
......@@ -48,7 +48,7 @@ with warnings.catch_warnings():
# NOTE: In case of ImportError: dlopen: cannot load any more object with static TLS,
# one could add 'from pykdtree.kdtree import KDTree' here (before pyresample import)
from pyresample.geometry import AreaDefinition, SwathDefinition, create_area_def
from pyresample.bilinear import resample_bilinear
from pyresample.bilinear import NumpyBilinearResampler
from pyresample.kd_tree import resample_nearest, resample_gauss, resample_custom
from .version import __version__ as _libver
......@@ -102,10 +102,6 @@ class SensorMapGeometryTransformer(object):
sigmas=(radius_of_influence / 2))
self.opts.update(opts)
if resamp_alg == 'bilinear':
del self.opts['radius_of_influence']
self.opts['radius'] = radius_of_influence
# NOTE: If pykdtree is built with OpenMP support (default) the number of threads is controlled with the
# standard OpenMP environment variable OMP_NUM_THREADS. The nprocs argument has no effect on pykdtree.
os.environ['OMP_NUM_THREADS'] = '%d' % (self.opts['nprocs'] if 'nprocs' in self.opts else 1)
......@@ -284,34 +280,40 @@ class SensorMapGeometryTransformer(object):
:param target_geo_def: target geo definition
:return:
"""
opts = self.opts.copy()
if self.resamp_alg == 'nearest':
opts = {k: v for k, v in self.opts.items() if k not in ['sigmas']}
opts.pop('sigmas', None)
result = resample_nearest(source_geo_def, data, target_geo_def, **opts).astype(data.dtype)
elif self.resamp_alg == 'bilinear':
opts = {k: v for k, v in self.opts.items() if k not in ['sigmas']}
opts.pop('sigmas', None)
with warnings.catch_warnings():
# suppress a UserWarning coming from pyresample v0.15.0
warnings.filterwarnings('ignore', category=UserWarning,
message='You will likely lose important projection information when converting '
'to a PROJ string from another format.')
result = resample_bilinear(data, source_geo_def, target_geo_def, **opts).astype(data.dtype)
kw_rsp = dict(fill_value=opts.pop('fill_value', 0),
nprocs=opts.pop('nprocs', 1))
result = \
NumpyBilinearResampler(source_geo_def, target_geo_def, **opts)\
.resample(data, **kw_rsp)\
.astype(data.dtype)
elif self.resamp_alg == 'gauss':
opts = {k: v for k, v in self.opts.items()}
# ensure that sigmas are provided as list if data is 3-dimensional
if data.ndim != 2:
n_sigmas = len(opts['sigmas']) # noqa
if not isinstance(opts['sigmas'], list):
opts['sigmas'] = [opts['sigmas']] * data.ndim
if not len(opts['sigmas']) == data.ndim:
if not n_sigmas == data.ndim:
raise ValueError("The 'sigmas' parameter must have the same number of values like data.ndim."
"n_sigmas: %d; data.ndim: %d" % (len(opts['sigmas']), data.ndim))
"n_sigmas: %d; data.ndim: %d" % (n_sigmas, data.ndim))
result = resample_gauss(source_geo_def, data, target_geo_def, **opts).astype(data.dtype)
elif self.resamp_alg == 'custom':
opts = {k: v for k, v in self.opts.items()}
if 'weight_funcs' not in opts:
raise ValueError(opts, "Options must contain a 'weight_funcs' item.")
result = resample_custom(source_geo_def, data, target_geo_def, **opts).astype(data.dtype)
......@@ -404,7 +406,6 @@ class SensorMapGeometryTransformer(object):
f"geometry to sensor geometry due to changes in upstream packages. Using 'gauss' instead. "
f"Note that bilinear resampling works in sensormapgeo<=0.5.0.", RuntimeWarning)
self.resamp_alg = 'gauss'
self.opts['radius_of_influence'] = self.opts.pop('radius')
# get area_definition
self.area_definition = AreaDefinition('', '', '', CRS(src_prj), data.shape[1], data.shape[0],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment