[SciPy-User] [SciPy-user] 2d interpolation, non-regular lat/lon grid - help with delauney/natgrid??

John [H2O] washakie at gmail.com
Thu Aug 13 05:55:32 EDT 2009


Still problems...

I tried something similar before with meshgrid (how is this different from
mgrid?), but I got the same error as below using the method you outline. Is
this a function of the 'dateline' issue you mention? My lons go from
-180,180 and lats 50,90. I've tried shifting from 0,360 for the lons, but I
think the problem is that in projected coordinates I don't have a
monotonically increasing x.

    170 
    171         # interpolate on projected grid

--> 172         Z0 = mlab.griddata(x, y, z, grid_x, grid_y)
    173 

/wrk/bin64/site-packages/matplotlib/mlab.py in griddata(x, y, z, xi, yi,
interp)
   2700         yo = yi.astype(np.float)
   2701         if min(xo[1:]-xo[0:-1]) < 0 or min(yo[1:]-yo[0:-1]) < 0:
-> 2702             raise ValueError, 'output grid defined by xi,yi must be
monotone increasing'
   2703         # allocate array for output (buffer will be overwritten by
nagridd)

   2704         zo = np.empty((yo.shape[0],xo.shape[0]), np.float)

ValueError: output grid defined by xi,yi must be monotone increasing


And my code:
161         x,y = m(lon,lat)
162         # create your lon-lat grid in degrees using e.g. np.mgrid
163         # you might need to be careful doing this step
164         # if your grid straddles the international dateline
165         grid_lon, grid_lat = np.mgrid[lon.min():lon.max():dres, 
166                 lat.min():lat.max():dres]
167 
168         # find the projected co-ordinates for the grid
169         grid_x, grid_y = m(grid_lon.ravel(), grid_lat.ravel())
170         
171         # interpolate on projected grid
172         Z0 = mlab.griddata(x, y, z, grid_x, grid_y) is my code:



Scott Sinclair-4 wrote:
> 
> # create your lon-lat grid in degrees using e.g. np.mgrid
> # you might need to be careful doing this step
> # if your grid straddles the international dateline
> grid_lon, grid_lat = np.mgrid[min_lon:max_lon:0.5, min_lat:max_lat:0.5]
> 
> # find the projected co-ordinates for the grid
> grid_x, grid_y = m(grid_lon.ravel(), grid_lat.ravel())
> 
> # interpolate on projected grid
> Znew = mlab.griddata(x, y, z, grid_x, grid_y)
> Cheers,
> Scott
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
> 
> 

-- 
View this message in context: http://www.nabble.com/2d-interpolation%2C-non-regular-lat-lon-grid-tp24909685p24952162.html
Sent from the Scipy-User mailing list archive at Nabble.com.




More information about the SciPy-User mailing list