LutzGross/esys-escript.github.io

Order 0 interpolation table

Opened this issue · 1 comments

this would be similar to the order 1 interpolation already available but would set values by cell (constant on cells in the input data).

This would be similar to this function (but maybe with the existing interface, extra order argument?):

def overlayArrayOnToBox(u, data, xmin, xmax, ymin, ymax, zmin, zmax):
dx=float(xmax-xmin)/data.shape0
nx=data.shape0
if len(data.shape) == 1:
dy=float(ymax-ymin)
dz=float(zmax-zmin)
ny=1
nz=1
elif len(data.shape) == 2:
dy=float(ymax-ymin)
dz=float(zmax-zmin)/data.shape1
ny=1
nz=data.shape1
else:
dy=float(ymax-ymin)/data.shape1
dz=float(zmax-zmin)/data.shape2
nx=u.shape1
nx=u.shape2

assert dx > 0, "dx must be positive"
assert dy > 0, "dy must be positive"
assert dz > 0, "dz must be positive"
X=u.getFunctionSpace().getX()
for p in xrange( u.getNumberOfDataPoints() ):
x,y,z=X.getTupleForDataPoint(p)
if xmin<= x and x <= xmax and ymin<= y and y <= ymax and zmin<= z and z <= zmax:
if len(data.shape) == 1:
ix=min(nx-1,max(0,int((x-xmin)/dx)))
u.setValueOfDataPoint(p, data[ix])
elif len(data.shape) == 2:
ix=min(nx-1,max(0,int((x-xmin)/dx)))
iz=min(nz-1,max(0,int((z-zmin)/dz)))
u.setValueOfDataPoint(p, data[ix,iz])
else:
ix=min(nx-1,max(0,int((x-xmin)/dx)))
iy=min(ny-1,max(0,int((y-ymin)/dy)))
iz=min(nz-1,max(0,int((z-zmin)/dz)))
u.setValueOfDataPoint(p, data[ix,iy,iz])
return u

duplicate of #42