Commit acb6d906 authored by jfpiolle's avatar jfpiolle
Browse files

fix for pyresample latest version

parent e5075964
......@@ -83,19 +83,19 @@ class Resampler(object):
mask = numpy.ma.getmaskarray(data).copy()
else:
mask = numpy.ma.getmaskarray(data)
for dummy in range(extrapolation):
# Find points to inpaint
eroded_mask = ndimage.morphology.binary_erosion(mask, border_value=1)
indexinp = numpy.where(mask & ~eroded_mask)
# Find neighbours
xneighb = numpy.repeat(indexinp[1], 8).reshape((-1, 8)) + \
numpy.array([-1, 0, 1, 1, 1, 0, -1, -1])
yneighb = numpy.repeat(indexinp[0], 8).reshape((-1, 8)) + \
numpy.array([-1, -1, -1, 0, 1, 1, 1, 0])
# Avoid neighbours to be out of bounds
# V1 : clip (some neighbours will be duplicated)
# numpy.clip(xneighb, 0, array.shape[1]-1, out=xneighb)
......@@ -105,7 +105,7 @@ class Resampler(object):
(yneighb < 0) | (yneighb > array.shape[0]-1))
xneighb[indexout] = indexinp[1][indexout[0]]
yneighb[indexout] = indexinp[0][indexout[0]]
# Replace with neighbours mean and update mask
try:
newpts = nanmean(array[[yneighb, xneighb]], axis=1)
......@@ -114,7 +114,7 @@ class Resampler(object):
'set to NaN')
array[indexinp] = newpts
mask[indexinp] = False
data = numpy.ma.MaskedArray(array, mask, copy=False)
return data
......@@ -318,7 +318,7 @@ class Resampler(object):
elif srcmodel == 'Grid':
if len(srclon.shape) == 1:
srclon, srclat = numpy.meshgrid(srclon, srclat)
source_def = geometry.GridDefinition(lons=srclon,
lats=srclat
)
......@@ -447,16 +447,16 @@ class Resampler(object):
if fields == []:
logging.warning("No fields requested? slipping resampling")
return
# Get source and target grid definitions
# --------------------------------------
source_lons = source.get_lon()
source_lats = source.get_lat()
source_lons = source.get_lon().astype('float32')
source_lats = source.get_lat().astype('float32')
source_times = source.get_times()
if isinstance(source, Grid):
source_lons, source_lats = numpy.meshgrid(source_lons, source_lats)
source_times = numpy.resize(source_times, source_lons.shape)
target_lons = target.get_lon()
target_lats = target.get_lat()
target_lons = target.get_lon().astype('float32')
target_lats = target.get_lat().astype('float32')
if isinstance(target, Grid) and len(target_lons.shape) == 1:
target_lons, target_lats = numpy.meshgrid(target_lons, target_lats)
source_def, target_def, radius = Resampler.__get_pyresample_def(
......@@ -467,12 +467,14 @@ class Resampler(object):
target_lons,
target.__class__.__name__,
radius)
if new:
# create a clone of target without any field
outfeature = target.extract_subset(fields=[])
else:
outfeature = target
first = True
resampled_fields = []
if add_geolocation:
resampled_fields.extend(['lat', 'lon', 'time'])
......@@ -515,8 +517,10 @@ class Resampler(object):
# the target
if not (values.min() == 0. and values.max() == 0):
return None
if outfeature.has_field(fieldname):
raise Exception('Field already existing in target grid')
newfieldname = prefix + fieldname
if outfeature.has_field(newfieldname):
raise Exception('Field {} already existing in target grid'.format(newfieldname))
else:
if fieldname in ['lat', 'lon', 'time']:
var = copy.copy(source._geolocation_fields[fieldname].variable)
......@@ -524,7 +528,7 @@ class Resampler(object):
else:
var = source.get_field(fieldname).variable
sourcefield = source.get_field(fieldname)
var.shortname = prefix + var.shortname
var.shortname = newfieldname
new_dims = target.get_geolocation_dimsizes()
field = Field(var,
new_dims,
......@@ -536,6 +540,7 @@ class Resampler(object):
valid_max=sourcefield.valid_max,
)
outfeature.add_field(field)
if add_reference:
# Add the indices (in the source feature data) of the
# selected pixels
......
Markdown is supported
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