![](https://secure.gravatar.com/avatar/f0e14e3d3fedba744ede17396d394c73.jpg?s=120&d=mm&r=g)
2009/8/13 John [H2O] <washakie@gmail.com>:
I'm sorry, pleading ignorance here...
But is my approach correct? Could you possibly provide a link to an example where data is projected first before the interpolation? Or, alternatively, a brief example (if only in sudo code).
I just am not sure what I am doing here is correct:
149 # In this approach we work with projected data 150 x,y = m(x,y) 151 xres,yres = res 152 newx= np.arange(m.xmin,m.xmax,(m.xmax-m.xmin)/xres) 153 newy= np.arange(m.ymin,m.ymax,(m.ymax-m.ymin)/yres) 154 Znew = mlab.griddata(x,y,z,newx,newy)
It seems to work, yes, but what do you mean there is nothing to do? Should my 'xres' simply be the lengths of the original x,y which are lon,lat ?
I think what Robert is suggesting you try is to interpolate the data onto your 0.5x0.5 degree grid after projecting the grid *and* data locations into your map projection i.e. m = Basemap(# projection parameters) # your data locations in proj co-ordinate system are x, y # your data locs in degrees are lon, lat x, y = m(lon, lat) # 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) There is "nothing to do" because Znew has same the same size and order as grid_x, grid_y, grid_lon.ravel() & grid_lat.ravel() so you can plot the data in either co-ordinate system (obviously being aware of the co-ordinate space where the interpolation was made).
Robert Kern-2 wrote:
On Wed, Aug 12, 2009 at 18:06, John [H2O]<washakie@gmail.com> wrote:
Robert Kern-2 wrote:
Are you using lat/lon as X/Y for griddata? Or are you projecting it first? You should project. Not seeing your code or data, I'm not sure I can diagnose what is going wrong with the interpolation.
-- Robert Kern
I have been trying to follow your suggestion of projecting first.. see example later, but I'm not sure if I am doing it correctly. One question is how then would I return the interpolated array back to a lat/lon grid... it seems transform_scalar is set up to go from lat/lon TO projection. I guess it could be used to 'unproject' the data as well?
The output Z values will be in the same order as the inputs. There is nothing to do.
-- Robert Kern
Cheers, Scott