3
votes

I have a dataset that is 0.25 * 0.25 degree grid resolution. I've another that is 1 * 1 degree resolution and want to make them comparable (both changed to 1 * 1 resolution). The area is 28.5 to 36.5 longitude and -4.5 to 4.5 latitude with monthly data for 2003 to 2012.I've attached the first few lines as an e.g. I've attached the excel file of full data if the below does not help! https://onedrive.live.com/redir?resid=9E74848E574367C6!2625&authkey=!AOcpftTyHVqU8CA&ithint=file%2ccsv I've been looking into the 'sp' (aggregate) and 'raster' packages but cannot figure this out. Any help appreciated as always!

> head(cur.data, 40)
    Longitude Latitude Year Month DecimDate  Rainfall  RainAnom
1     28.625   -4.375 2012    12  2012.917 173.69343  73.74917
2     28.875   -4.375 2012    12  2012.917 186.91148  86.96723
3     29.125   -4.375 2012    12  2012.917 158.17921  58.23495
4     29.375   -4.375 2012    12  2012.917 194.71006  94.76581
5     29.625   -4.375 2012    12  2012.917 160.84774  60.90349
6     29.875   -4.375 2012    12  2012.917 192.01070  92.06645
7     30.125   -4.375 2012    12  2012.917 225.45180 125.50755
8     30.375   -4.375 2012    12  2012.917 234.98836 135.04410
9     30.625   -4.375 2012    12  2012.917 182.77813  82.83388
10    30.875   -4.375 2012    12  2012.917 226.08477 126.14052
11    31.125   -4.375 2012    12  2012.917 271.90741 171.96316
12    31.375   -4.375 2012    12  2012.917 272.48264 172.53839
13    31.625   -4.375 2012    12  2012.917 265.44591 165.50166
14    31.875   -4.375 2012    12  2012.917 266.44458 166.50033
15    32.125   -4.375 2012    12  2012.917 270.94755 171.00329
16    32.375   -4.375 2012    12  2012.917 257.85288 157.90863
17    32.625   -4.375 2012    12  2012.917 265.42979 165.48554
18    32.875   -4.375 2012    12  2012.917 255.23151 155.28726
19    33.125   -4.375 2012    12  2012.917 249.32812 149.38387
20    33.375   -4.375 2012    12  2012.917 165.93709  65.99284
21    33.625   -4.375 2012    12  2012.917 165.71675  65.77250
22    33.875   -4.375 2012    12  2012.917 201.09573 101.15148
23    34.125   -4.375 2012    12  2012.917 216.02753 116.08328
24    34.375   -4.375 2012    12  2012.917 255.53255 155.58830
25    34.625   -4.375 2012    12  2012.917 202.72544 102.78119
26    34.875   -4.375 2012    12  2012.917  71.00399 -28.94026
27    35.125   -4.375 2012    12  2012.917  69.55960 -30.38465
28    35.375   -4.375 2012    12  2012.917  84.89567 -15.04858
29    35.625   -4.375 2012    12  2012.917 144.54023  44.59598
30    35.875   -4.375 2012    12  2012.917 227.81630 127.87205
31    36.125   -4.375 2012    12  2012.917 193.73762  93.79337
32    36.375   -4.375 2012    12  2012.917 156.49207  56.54782
33    28.625   -4.125 2012    12  2012.917 182.18007  82.23582
34    28.875   -4.125 2012    12  2012.917 208.52020 108.57595
35    29.125   -4.125 2012    12  2012.917 175.20243  75.25817
36    29.375   -4.125 2012    12  2012.917 166.91644  66.97218
37    29.625   -4.125 2012    12  2012.917 156.38420  56.43994
38    29.875   -4.125 2012    12  2012.917 167.72313  67.77888
39    30.125   -4.125 2012    12  2012.917 175.48325  75.53899
40    30.375   -4.125 2012    12  2012.917 210.74390 110.79965 
1
do you want to just subset the ones that match, or take a mean of the closest ones?jeremycg
I thought it'd be best to use the mean of the 0.25*0.25 grids that make up each 1*1 grid resolution. It makes sense to me that there is 4*4 grids of 0.25 degree resolution making up every 1 degree resolution grid. Hopefully this makes sense! Thanks very much for taking the time to look - it's a real sticking point to continue my work.Darren J

1 Answers

5
votes

I think the raster package is the way to go:

require(raster)

cur.data <- read.csv("LVB_TRMM_Monthly_Rainfall.csv")

r <- cur.data
coordinates(r) <- ~ Longitude + Latitude
gridded(r) <- TRUE

# Stack each variable as a band in the raster:
tmp <- raster(r, layer = 1)
for (i in 2:5) {
  tmp <- stack(tmp, raster(r, layer = i))
}
r <- tmp

# Aggregate to 1 degree resolution (4 times as coarse):
r <- aggregate(r, fact = 4, fun = mean)

# Get it back to a dataframe
coords <- as.matrix(coordinates(r))
df <- data.frame(Longitude = coords[, 1], Latitude = coords[, 2],
                 as.data.frame(r))

This gives:

  Longitude Latitude Year Month DecimDate Rainfall  RainAnom
1        29        1 2003     1      2003 60.69725 -39.24700
2        30        1 2003     1      2003 39.60284 -60.34141
3        31        1 2003     1      2003 34.12878 -65.81548
4        32        1 2003     1      2003 46.32009 -53.62416
5        33        1 2003     1      2003 71.27627 -28.66799
6        34        1 2003     1      2003 82.92516 -17.01909

However, I see that you have data from different time periods. Perhaps you will want to repeat the above steps for each time period.