0

I have a rasterbrick (of monthly precipitation data from 1901 to 2018) and it is currently in a at a resolution of 0.5, 0.5 x,y.

here are the details of the data:

class      : RasterBrick 
dimensions : 59, 52, 3068, 1416  (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5  (x, y)
extent     : 12, 38, -46.5, -17  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : C:/Users/teyah/AppData/Local/Temp/Rtmp2ffibl/raster/r_tmp_2020-09-28_145010_7728_36039.grd 
names      : X1901.01.16, X1901.02.15, X1901.03.16, X1901.04.16, X1901.05.16, X1901.06.16, X1901.07.16, X1901.08.16, X1901.09.16, X1901.10.16, X1901.11.16, X1901.12.16, X1902.01.16, X1902.02.15, X1902.03.16, ... 
min values :           0,           0,           0,           0,           0,           0,           0,           0,           0,           0,           0,           0,           0,           0,           0, ... 
max values :       249.9,       248.9,       223.7,       134.2,       264.1,       184.6,       191.2,       129.4,       268.5,       226.5,       280.0,       257.4,       190.0,       154.5,       237.5, ... 

I also have a second dataset also of monthly precipitation data from 1850 to 2014 but this one is at a resolution of 1.875, 1.25 x, y.

class      : RasterBrick 
dimensions : 23, 13, 299, 1032  (nrow, ncol, ncell, nlayers)
resolution : 1.875, 1.25  (x, y)
extent     : 13.125, 37.5, -46.25, -17.5  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : C:/Users/teyah/AppData/Local/Temp/Rtmp2ffibl/raster/r_tmp_2020-09-28_145148_7728_36431.grd 
names      :  X2015.01.16,  X2015.02.15,  X2015.03.17,  X2015.04.16,  X2015.05.16,  X2015.06.15,  X2015.07.15,  X2015.08.14,  X2015.09.13,  X2015.10.13,  X2015.11.12,  X2015.12.12,  X2016.01.16,  X2016.02.15,  X2016.03.16, ... 
min values : 3.928237e-08, 3.287400e-07, 6.498354e-07, 4.721920e-08, 1.676487e-07, 9.375419e-09, 3.423606e-09, 1.167969e-09, 1.766427e-07, 9.181048e-08, 2.939261e-06, 9.623330e-08, 3.777944e-07, 1.809338e-07, 8.813624e-07, ... 
max values : 1.244237e-04, 1.455906e-04, 1.142002e-04, 7.299686e-05, 4.577329e-05, 3.548095e-05, 8.001707e-05, 7.494183e-05, 1.162102e-04, 2.004935e-04, 1.395226e-04, 1.564750e-04, 1.730213e-04, 2.217189e-04, 1.081660e-04, ... 

How to I go about converting regridding both of these datasets to a resolution of 1,1 x,y using bilinear interpolation?

2 Answers 2

1

Try aggregate (in the first case) and disaggregate (in the second case) functions from the raster package. Note, the argument fact in aggregate and disaggregate can take 2 forms as described in the help page of these functions:

Aggregation factor expressed as number of cells in each direction (horizontally and vertically). Or two integers (horizontal and vertical aggregation factor) or three integers (when also aggregating over layers).

and

This can be a single integer or two integers c(x,y), in which case the first one is the horizontal disaggregation factor and y the vertical disaggreation factor. If a single integer value is supplied, cells are disaggregated with the same factor in x and y direction

Assuming that your first raster with 0.5 x 0.5 is called x, then you can do:

 aggregate (x, fact = 2)

Assuming that your second raster with 1.875 x 1.25 is called y, then you can do:

 disaggregate (y, fact = 1)
0

Since you are using a reference raster for resampling, this can be done in the terra package. If you have data as a raster object class it can simply be coerced to the terra raster (single or stack) class using terra::rast and back again with raster::stack.

Add packages and create some data.

library(terra)

e <- terra::ext(12, 38, -46.5, -17)

i=59; j=52
r1 <- rast(replicate(10,rast(matrix(runif(i*j), nrow=i, ncol=j))))
  ext(r1) <- e

i=23; j=13
r2 <- rast(replicate(10,rast(matrix(runif(i*j), nrow=i, ncol=j))))
  ext(r2) <- e

Use the terra resample function to resample the coarse raster to the finer resoultion raster using bilinear.

( rs <- terra::resample(r2, r1, method="bilinear") ) 
  par(mfrow=c(2,1))
    plot(r2[[1]])
    plot(rs[[1]])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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