plankton wrote:
> 
> Greetings all,
> 
> I rotate a vector field and than I tried to interpolate it to a new grid
> using griddata. 
> 
> CODE:
> 
>         x_grid_unique = unique(x_grid)
>         y_grid_unique = unique(y_grid)
>         x_meshgrid,  y_meshgrid =   meshgrid(x_grid_unique, y_grid_unique)
>         x_rot_meshgrid = reshape(x_rot,  [ len(x_meshgrid[:, 0]),
> len(x_meshgrid[0, :])] )
>         y_rot_meshgrid = reshape(y_rot,  [ len(x_meshgrid[:, 0]),
> len(x_meshgrid[0, :])] )
>         u_rot_meshgrid = reshape(u_rot,  [ len(x_meshgrid[:, 0]),
> len(x_meshgrid[0, :])] )
>         v_rot_meshgrid = reshape(v_rot,  [ len(x_meshgrid[:, 0]),
> len(x_meshgrid[0, :])] )
>         u_interpolate = griddata(x_rot,  y_rot, u_rot,  x_rot_meshgrid, 
> y_rot_meshgrid)
>         v_interpolate = griddata(x_rot,  y_rot, v_rot,  x_rot_meshgrid, 
> y_rot_meshgrid)
> 
> 
> 
> I unfortunately griddata returns some nan (It seems that there are
> multiple occurrences of the same [X,Y] pair in the data). In matlab you
> can use griddata with additional options  e.g. ru =
> griddata(nx,ny,nu,rx,ry,'linear', {'QJ'}) to fix this, but this seems to
> be not possible using the griddata function in matplotlib. Is there any
> other way to avoid a return of nan?
> 
> For any help many thanks in advance
> 
> Andreas
> 
> 
> 
> 

Problem solved more or less. Griddata produces only at the boundary of the
vector field nan, which seems to be the result of my data matrixes u and v.
They contain serveral colums and rows with zeros at the boundary, which
leads to nan at the boundary. Finaly this is not a  great problem and can be
fixed easily by adding zeros at the boundary after using griddata. 
But maybe this can be fixed otherwise e.g. using griddata with parameters,
so that it is not necessary to fix the matrix by rewriting the boundary.
Therefore, following a sample script, which demonstrates the problem. 

SAMPLE SCRIPT

--CODE--

from pylab import *

def rotate(x,  y,  angle):
        x_rot = x * cos(angle) -  y * sin(angle)
        y_rot = x * sin(angle) + y * cos(angle)
        return  x_rot,  y_rot 
    
def generate_new_grid(x_rot, y_rot, x_elements,  y_elements):
        xmin = min(x_rot)
        xmax = max(x_rot) 
        ymin = min(y_rot)
        ymax = max(y_rot) 
        x  = linspace(xmin, xmax, x_elements)
        y = linspace(ymin, ymax, y_elements)
        x_tecplot_vector = zeros(25,  float)
        y_tecplot_vector = zeros(25,  float)
        for i in range(5):
            first = i *5
            last = (i+1) * 5
            x_tecplot_vector[first:last]  = x
            y_tecplot_vector[first:last]   = y[i]
        return x_tecplot_vector,  y_tecplot_vector 

# ###################################

u = zeros(25,  float)
u[12] = 1
v =  zeros(25,  float)
v[11] = 2
x =  zeros(5,  float)
y =  zeros(5,  float)
x  = linspace(1, 5, 5)
y = linspace(1, 5, 5)
x_grid,  y_grid= generate_new_grid(x, y, 5,  5)
print y_grid
# ###################################
angle = 0.1
x_rot,  y_rot = rotate(x_grid,  y_grid, angle)
x_elements = 5  
y_elements = 5
x_grid,  y_grid= generate_new_grid(x_rot, y_rot, x_elements,  y_elements)
u_rot,  v_rot = rotate(u,  v, angle)
x_meshgrid,  y_meshgrid =   meshgrid(x_grid, y_grid)
x_rot_meshgrid = reshape(x_grid,  [ 5, 5] )
y_rot_meshgrid = reshape(y_grid,  [ 5, 5] )
u_rot_meshgrid = reshape(u_rot,  [ 5, 5] )
u_interpolate = griddata(x_rot,  y_rot, u_rot,  x_rot_meshgrid, 
y_rot_meshgrid)
#save('test.dat',  u_interpolate)
print u_interpolate


--CODE--




-- 
View this message in context: 
http://www.nabble.com/griddata-returns-nan-tp24537481p24623042.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to