I have a netcdf4 data set that contains array and information about latitude and longitude which can be accessed with the following R command:

ncvar_get(dataname, 'lon');
ncvar_get(dataname, 'lat');


dataname <- nc_open(paste(filename,".nc",sep=""))

I have another file containing the location (with latitude and longitude also) of the grid contained in dataname. I'd like to implement interpolation (spline, kriging, etc.) using these two files but can't find any tutorial which is clear about the subject.

Could anyone guide me?

(package that should be used, I have seen gstat and gam but examples provided are far away similar to what I want to do, practical implementation)

Thanks in advance.

  • You don't seem to indicate the variable to be interpolated. Are you trying to regrid some information in (another file) onto to the grid given by the first file? – Dave X Apr 7 '14 at 17:06

Here's a blog on Accessing netCDF Data by Coordinates that specifically deals with finding the data associated with (lat,lon) locations, using nearest points.

If you want to find the nearest K points and use some kind of interpolation, you can still use the same cKDTree software as described in the blog, but just provide your own interpolation formula.

If you want a more packaged solution callable from C or C++, the open source Fimex library for File Interpolation, Manipulation and EXtraction can do what you want.

| improve this answer | |

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.