code123
code123

Reputation: 2146

Interpolate gridded climate data to different resolutions in R

I have raster data with a resolution of 0.5 degrees. I would like to interpolate these to 0.125 and to 1 degree using nearest neighbour interpolation

How can this be implemented in R? Below is some example data:

library(raster)
ras <- raster(res=0.5)
#get polygons for Iceland
iceland <- getData('GADM', country="Iceland", level=1)
cr <- crop(ras, iceland, snap="out")
values(cr) <- 1:ncell(cr)
fr <- mask(cr, iceland)

plot(fr)
lines(iceland)

Upvotes: 1

Views: 594

Answers (1)

Robert Hijmans
Robert Hijmans

Reputation: 47146

Example data

library(raster)
ras <- raster(res=0.5)
#get polygons for Iceland
iceland <- getData('GADM', country="Iceland", level=1)
cr <- crop(ras, iceland, snap="out")
values(cr) <- 1:ncell(cr)
fr <- mask(cr, iceland)

1 degree

a <- aggregate(fr, 2, mean, na.rm=TRUE)
 

0.125 degree

d <- disaggregate(fr, 4)

Dis-aggregating data like that may be practical, but it may not be appropriate. It obviously is not a good way to change the resolution of climate data (but you asked how to do it, and that is what this site is for)

If the new resolution cannot be obtained by multiplying or dividing with an integer, there is resample

target <- raster(fr)
res(target) <- 1/13
r <- resample(fr, target, "ngb")

#or alternatively
rb <- resample(fr, target, "bilinear")

Upvotes: 1

Related Questions