Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
Close
From: plankton <andreas.westhoff@dl...>  20090717 16:16:20

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  View this message in context: http://www.nabble.com/griddatareturnsnantp24537481p24537481.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: Jeff Whitaker <jswhit@fa...>  20090722 21:58:04

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 > > > > Andreas: Can you provide a standalone script that I can run which demonstrates the problem? Otherwise, it's hard to know what's going on. Jeff  Jeffrey S. Whitaker Phone : (303)4976313 Meteorologist FAX : (303)4976449 NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@... 325 Broadway Office : Skaggs Research Cntr 1D113 Boulder, CO, USA 803033328 Web : http://tinyurl.com/5telg 
From: plankton <andreas.westhoff@dl...>  20090723 10:22:04

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/griddatareturnsnantp24537481p24623042.html Sent from the matplotlib  users mailing list archive at Nabble.com. 