Skip to content

Commit

Permalink
fix linear/cubic outside convex null
Browse files Browse the repository at this point in the history
  • Loading branch information
revoltek committed Apr 21, 2016
1 parent e24add0 commit ffba98a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions losoto/operations/interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,19 @@ def run( step, parset, H ):
valsNew = scipy.interpolate.griddata(calPoints, calValues, targetPoints, interpMethod)

# fill values outside boudaries with "nearest" solutions
# NOTE: in 1D is useless due to scipy bug but this is compensated in the next if
if interpMethod != 'nearest':
valsNewNearest = scipy.interpolate.griddata(calPoints, calValues, targetPoints, 'nearest')
# NaN is != from itself
valsNew[ np.where(valsNew != valsNew) ] = valsNewNearest [ np.where(valsNew != valsNew) ]
valsNew[ np.isnan(valsNew) ] = valsNewNearest [ np.isnan(valsNew) ]

# fix bug in Scipy which put NaNs outside the convex hull in 1D for 'nearest'
if interpMethod == 'nearest' and len(np.squeeze(vals).shape) == 1:
if len(np.squeeze(vals).shape) == 1:
import scipy.cluster.vq as vq
valsNew = np.squeeze(valsNew)
code, dist = vq.vq(targetPoints, calPoints)
# NaN is != from itself
valsNew[ np.where(valsNew != valsNew) ] = calValues[code][ np.where(valsNew != valsNew) ]
valsNew[ np.isnan(valsNew) ] = calValues[code][ np.isnan(valsNew) ]
valsNew = valsNew.reshape(vals.shape)

if rescale:
Expand Down

0 comments on commit ffba98a

Please sign in to comment.