Interpolate precipitation and temperature point values on 2D grids

Hi all,

I want to ask that how to interpolate grid data to specific points? My question is similar to this, but I'd like to try to achieve it in R since I forget details in python.

In my case, X and Y represent longitude and latitude, while Z represent monthly precipitation data. One uncertainty is that is it reasonable to not consider elevation data? I see from some literature that they created gridded precipitation data from station data, without considering elevation data.

If Z represent temperature, how to change the code and to consider elevation data? Thanks for your help.

Several ways to achieve that depending on the type of interpolation (bilinear, spline, kriging..) and your grid!
you can have a look at the packages akima or fields for example .

would you mind sharing some data? would be easier to help.

1 Like

I find a small sample,

Grid 1 has the coords (latitude, longitude) as (39.9375, -105.3125),
Grid 2 has coords as (39.9375, -105.4375),
Grid 3 has coords as (40.0625, -105.3125),
and grid 4 has coords as (40.0625, -105.4375).

Precipitation data at the four grid cells are: 1200, 1000, 800, 900,
Temperature data at the four grid cells are: 8, 10, 5, 6.4,
Elevations at the four grid cells are: 2100, 2500, 2000, 2420,

How to interpolate the grid data to this point: (40.01, -105.3)? Also, this is for one point and one value at each grid cell. If I have 12 monthly values (including precipitation and temperature) at each grid cell, and many points, how to achieve that? Thanks for your help.

not very kind to give the data like that :wink: you can use reprex to produce a nice output or dput(yourdata)!

here is a simple solution, since your grid is regular, I used the raster package to perform the interpolation
To take into account the altitude you have to dig a little bit more and find another method.

You can also perform more complex interpolation (based on fields package for example) using the function interpolate see the help of the function.


# data 
df <- data.frame(
  lon = c(39.9375, 39.9375, 40.0625, 40.0625),
  lat = c(-105.3125, -105.4375, -105.3125, -105.4375),
  pr  = c(1200, 1000, 800, 900),
  tem = c(8, 10, 5, 6.4),
  z   = c(2100, 2500, 2000, 2420)
# interpolate data on that pt
pt <- matrix(c(40.01, -105.3), ncol = 2)

# illustration
points(pt, cex = 1.2, pch = 16)

# make a raster brick (regular grid, multiple variables)
ras <- rasterFromXYZ(df) 
# perform interpolation (simple or bilinear)
extract(a, y = pt, method = "simple")
extract(a, y = pt, method = "bilinear")

I think you can manage to do it on multiple timesteps!

Good luck,


Thanks, your code works.
I'd like to ask that are there only two interpolation methods here, i.e. simple and bilinear? Are there any other methods, such as inverse distance weighting, thin plate spline, etc? Your hint is very helpful, but I am wondering how to find out the way to incorporate elevation data here? Thanks again.

yes, I mentioned it, have a look at fields package for interpolation method (kriging...) & to use it with a raster input take a look at the function interpolate.

Thanks. It may be good for precipitation, but I could not find other solutions considering elevation data for temperature interpolation. Could you or anyone give me some suggestions? Thanks very much.

It's pretty difficult to answer.. Here you have several method but I can't say which one is the best for your problem. To add altitude you may have a look at some scientific articles or what is done in climate model...

In my opinion, precipitation are more "sensible" to interpolate than temperature... So I would say that a bilinear interpolation could works for temperature but not for precipitation. I mean you can have a lot of precipitation and 2km away no more precipitation, it's more "discrete" than temperature. Also if your data come from a climate model and you want to "downscale it", you may want a conservative approach (don't add precipitation but better distribute it).

If you want to correct your interpolation with the altitude you can add a "certain amount" of temperature using a "base profile" (e.g. each 1000 meters you loose 6.5 °C) but would it be reliable?

It's just some idea like that... Not really helpful I guess (sorry)
Maybe if you describe better your problem I could help more but I'm not sure of it!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.