2

I've got a large netcdf (a small portion of the data is here) with the data in an even grid associated with an Albers Equal Area Conic projection. I've got the corresponding latitudes and longitudes here and here.

I want to take the information in this netcdf, and get interpolated values along a regular lat/lon grid, from 18.2W to 53E and 32.8S to 20N. For output, I'd like a 3-dimensional array with the x, y, and z axes being lon, lat, and time. Or a set of rasters that I can coerce to a 3d array in R.

How can this be done?

I know that I could write an R script where for each point in my regular lat/lon grid I identify the four nearest surrounding Albers points and take their inverse-euclidian-distance-weighted average. But this will be painfully slow to compute and difficult to program.

Are there any programs or tools that can help me to batch-interpolate a netcdf with a deep time dimension?

I'll have >100 of these to do, and each grid is 1152x1152.

I seek solutions in R, or anything that can be run in some sort of batch mode.


This was a case where I simply didn't know the names of the tools to use. Apparently, the "projectRaster" function in the raster package (which relies on gdal) does what I need once I coerce my netcdf slices into raster objects. I had to do a bit of digging in metadata and obscure documentation to figure out proj4 syntax, but that was the extent of the difficulties.

  • 1
    Use the raster package, you can reproject/resample the whole thing in one step using raster's cunning tricks. But, I would question why you really need to reinterpolate the thing, do you really need to do that? – mdsumner Jun 2 '14 at 5:43
  • I've got rainfall data on a regular .1x.1 degree grid, and I want to put it into a data frame with NDVI data. Will look into the raster package. Any hints on which particular functions do it? – generic_user Jun 2 '14 at 6:35
  • Also, is "reproject" what I want? I'm not sure it is -- I want a data frame, not a picture. – generic_user Jun 2 '14 at 6:35
  • Use extract with your lonlat points as SpatialPoints, extract will transform automatically. But there is a lot here to unpack if you are not usedto it – mdsumner Jun 2 '14 at 8:59
  • 1
    Resampling a grid with a simple linear procedure like IDW (or, better, bilinear interpolation) that uses a small local neighborhood is a sparse matrix multiplication--and therefore is reasonably fast to execute in almost any language. Setting it up takes only a few dozen lines of code in R and so is not hard to program or debug. As @radouxju suggests, though, you don't have to re-invent the wheel: use a GIS (or GIS utility like GDAL) to do it. – whuber Jun 2 '14 at 22:23
2

If you are looking for another software that manages well the large, I suggest to use gdal.

gdalwarp will do exactly what you want in a single command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.