Commit 6804a809 authored by GROUAZEL's avatar GROUAZEL
Browse files

fix an error with the mask in interpolation. (the mask argument should not be...

fix an error with the mask in interpolation. (the mask argument should not be overwritten in the loop over the different parameters)
parent 74500e9e
......@@ -195,19 +195,17 @@ class Resampler(object):
missing = source.get_field(fieldname).fillvalue
else:
missing = fillvalue
logging.debug('missing value: %s',missing)
if mask is None:
srcmask = numpy.array(data.mask, copy=True)
logging.debug('resampler | mask %s data type%s data.mask %s',mask,type(data),data.mask)
if extrapolation != 0:
logging.info('Read source and extrapolate over missing data')
logging.debug('Read source and extrapolate over missing data')
# call extrapolation procedure (replace NaN with interpolated
# values)
logging.debug('data %s',data.shape)
data = cls.extrapolate(data, extrapolation)
# masked data to missing value
data = data.filled(missing)
logging.debug('resampler | source lon %s lat %s z %s',source_lons.shape,source_lats.shape,data.shape)
logging.info("interpolation to target grid")
# re-interpolate source over target
# ---------------------------------
source_lons_new = Resampler.__monotonic(source_lons)
......@@ -233,7 +231,7 @@ class Resampler(object):
)
else:
# extrapolate the source mask
mask = Resampler.__closest_neighbour(source_lats,
extrapolate_mask = Resampler.__closest_neighbour(source_lats,
source_lons,
srcmask.astype('int8'),
source.get_model_name(),
......@@ -242,7 +240,7 @@ class Resampler(object):
target.get_model_name(),
)
interpolated_data = numpy.ma.masked_where(
mask == 1,
extrapolate_mask == 1,
interpolated_data,
copy=False
)
......@@ -309,11 +307,10 @@ class Resampler(object):
`pyresample <https://pyresample.readthedocs.org/en/latest/index.html>`_
package documentation.
"""
logging.info('%s %s | __get_pyresample_def',__name__,__file__)
if (srclon>180).any():
srclon = utils.wrap_longitudes(srclon)
if srcmodel == 'Swath' or srcmodel == 'Image' or \
srcmodel == 'Trajectory':
srcmodel == 'Trajectory' or srcmodel =='PointCollection':
source_def = geometry.SwathDefinition(lons=srclon,
lats=srclat
)
......@@ -336,10 +333,15 @@ class Resampler(object):
lats=tgtlat
)
if radius is None:
y, x = srclat.shape
resolution = abs(srclat[y / 2, x / 2] - srclat[y / 2 + 1, x / 2])
if srcmodel =='PointCollection':
# resolution = abs(srclat[0] - srclat[1])
# resolution = numpy.amin(abs(numpy.diff(srclat)))
resolution = 1
else:
y, x = srclat.shape
resolution = abs(srclat[y / 2, x / 2] - srclat[y / 2 + 1, x / 2])
radius = resolution * 100000. / 2. * 1.6
logging.info("Radius for resampling : %s", radius)
logging.debug("Radius for resampling : %s", radius)
return source_def, target_def, radius
@classmethod
......@@ -470,7 +472,6 @@ class Resampler(object):
target_lons,
target.__class__.__name__,
radius)
if new:
# create a clone of target without any field
outfeature = target.extract_subset(fields=[])
......@@ -650,6 +651,8 @@ class Resampler(object):
logging.debug("Resample to regular grid")
srclons = src.get_lon()
srclats = src.get_lat()
logging.debug('srclons: %s',srclons)
logging.debug('srclats: %s',srclats)
if not target.projection.is_cylindrical():
raise Exception('Projection is not valid for this type of regridding')
tarlon = target.get_lon()
......@@ -673,6 +676,7 @@ class Resampler(object):
val = src.get_values(fieldname)
else:
val = data[i]
logging.debug('val %s %s',val.shape,val.mean())
lons = numpy.ma.masked_where(val.mask, srclons).compressed()
lats = numpy.ma.masked_where(val.mask, srclats).compressed()
# create empty field if add_empty_fields is set when there are
......@@ -692,10 +696,14 @@ class Resampler(object):
logging.warning("Converting to double this field: %s" %
fieldname)
val = val.astype('float64')
logging.debug('latmin %s latmax %s lonmin %s lonmax %s',latmin , latmax , lonmin , lonmax)
val_comp = val.compressed()
logging.debug('shape val_compressed: %s',val_comp.shape)
logging.debug('lats compressed :%s',lats.shape)
result, nbsampl = fastregrid.fastregrid(
lats,
lons,
val.compressed(),
val_comp,
latmin, latmax, lonmin, lonmax,
lonbin, latbin
)
......
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