Sentinel-2 Enhanced Vegetation Index - r

I am using Sentinel-2 data to calculate the NDVI and the Enhanced Vegetation Index (EVI):
NDVI <- (B8 - B4) / (B8 + B4)
## Works great
EVI <- 2.5*(B8-B4)/((B8+6*B4-7.5*B2)+1)
## Wonky
B8, B4, and B2 are RasterLayers of the Sentinel 2 bands (B8 = VNIR, 10 m, 842 nm, B4...etc.):
These all look fine and work with the simpler NDVI calculation, even if I use B2 in place of B4 - it works.
The EVI hist(EVI) looks like I thought it should look, but I get a different result if I plot it again after recalculating:
A warning message also results now:
>hist(EVI)
Warning message:
In .hist1(x, maxpixels = maxpixels, main = main, plot = plot, ...) :
0% of the raster cells were used. 100000 values used.
The plot(EVI) legend is ramped from -1 to 5, but the values do not seem to match up:
maxValue(EVI)
#[1] 3199.469
minValue(EVI)
#[1] -1370.398
quantile(EVI, probs = c(0.25,0.5,0.75))
# 25% 50% 75%
#0.2694335 0.3377984 0.4481901
EVI
#class : RasterLayer
#dimensions : 10980, 10980, 120560400 (nrow, ncol, ncell)
#resolution : 10, 10 (x, y)
#extent : 399960, 509760, 6190200, 6300000 (xmin, xmax, ymin, ymax)
#crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
#source : r_tmp_2022-04-14_170725_107992_82859.grd
#names : layer
#values : -1370.398, 3199.469 (min, max)
QUESTION: Why would the EVI values be so high? I would expect a maxValue to be slightly >1 minValue to be slightly <-1. NDVI looks okay:
NDVI
#class : RasterLayer
#dimensions : 10980, 10980, 120560400 (nrow, ncol, ncell)
#resolution : 10, 10 (x, y)
#extent : 399960, 509760, 6190200, 6300000 (xmin, xmax, ymin, ymax)
#crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
#source : r_tmp_2022-04-14_162459_107992_94886.grd
#names : layer
#values : -2.4375, 0.9981395 (min, max)
If I manually plug the EVI values:
> EVI_Max = 2.5 * ((maxValue(B8) - maxValue(B4)) / ((maxValue(B8) + (6*maxValue(B4)) - (7.5*maxValue(B2))) + 1))
> EVI_Max
[1] 0.1979678
> EVI_Maxb = 2.5 * ((maxValue(B8) - maxValue(B4)) / ((minValue(B8) + (6*minValue(B4)) - (7.5*minValue(B2))) + 1))
> EVI_Maxb
[1] 0.8300415
> EVI_Maxc = 2.5 * ((minValue(B8) - minValue(B4)) / ((maxValue(B8) + (6*maxValue(B4)) - (7.5*maxValue(B2))) + 1))
> EVI_Maxc
[1] 0
The input raster data (this has been run as brick and stack - same results):
B8 <- raster(sen_complete, layer=7)/10000 ##Layer7=B8
B4 <- raster(sen_complete, layer=3)/10000 ##Layer3=B4
B2 <- raster(sen_complete, layer=1)/10000 ##Layer1=B2
> sen_complete
class : RasterBrick
dimensions : 10980, 10980, 120560400, 8 (nrow, ncol, ncell, nlayers)
resolution : 10, 10 (x, y)
extent : 399960, 509760, 6190200, 6300000 (xmin, xmax, ymin, ymax)
crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
source : r_tmp_2022-04-14_102523_107992_02726.grd
names : layer.1, layer.2, layer.3, layer.4, layer.5, layer.6, layer.7, layer.8
min values : 1, 1, 1, 1, 1, 0, 1, 1
max values : 7580, 8784, 12208, 12040, 14475, 15740, 15528, 15605
B8
#class : RasterLayer
#dimensions : 10980, 10980, 120560400 (nrow, ncol, ncell)
#resolution : 10, 10 (x, y)
#extent : 399960, 509760, 6190200, 6300000 (xmin, xmax, ymin, ymax)
#crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
#source : r_tmp_2022-04-14_172529_107992_50061.grd
#names : layer.7
#values : 1e-04, 1.5528 (min, max)
B4
#class : RasterLayer
#dimensions : 10980, 10980, 120560400 (nrow, ncol, ncell)
#resolution : 10, 10 (x, y)
#extent : 399960, 509760, 6190200, 6300000 (xmin, xmax, ymin, ymax)
#crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
#source : r_tmp_2022-04-14_172558_107992_74998.grd
#names : layer.3
#values : 1e-04, 1.2208 (min, max)
B2
#class : RasterLayer
#dimensions : 10980, 10980, 120560400 (nrow, ncol, ncell)
#resolution : 10, 10 (x, y)
#extent : 399960, 509760, 6190200, 6300000 (xmin, xmax, ymin, ymax)
#crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
#source : r_tmp_2022-04-14_172617_107992_52307.grd
#names : layer.1
#values : 1e-04, 0.758 (min, max)
s <- stack(B2, B4, B8)
> s
class : RasterStack
dimensions : 10980, 10980, 120560400, 3 (nrow, ncol, ncell, nlayers)
resolution : 10, 10 (x, y)
extent : 399960, 509760, 6190200, 6300000 (xmin, xmax, ymin, ymax)
crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
names : layer.1, layer.3, layer.7
min values : 1e-04, 1e-04, 1e-04
max values : 0.7580, 1.2208, 1.5528
The output for visual comparison:
> par(mfrow=c(2,1))
> plot(NDVI)
> plot(EVI)
Recreate with random data:
> rtest_B8 <- raster(ncol=10980, nrow=10980)
> rtest_B4 <- raster(ncol=10980, nrow=10980)
> rtest_B2 <- raster(ncol=10980, nrow=10980)
> minValue(raster(sen_complete, layer=7))
[1] 1
> maxValue(raster(sen_complete, layer=7))
[1] 15528
> minValue(raster(sen_complete, layer=3))
[1] 1
> maxValue(raster(sen_complete, layer=3))
[1] 12208
> minValue(raster(sen_complete, layer=1))
[1] 1
> maxValue(raster(sen_complete, layer=1))
[1] 7580
> set.seed(0)
> values(rtest_B8) <- runif(ncell(rtest), min = (minValue(raster(sen_complete, layer=7))), max = maxValue(raster(sen_complete, layer=7)))
> set.seed(999)
> values(rtest_B4) <- runif(ncell(rtest), min = (minValue(raster(sen_complete, layer=3))), max = maxValue(raster(sen_complete, layer=3)))
> set.seed(-999)
> values(rtest_B2) <- runif(ncell(rtest), min = (minValue(raster(sen_complete, layer=1))), max = maxValue(raster(sen_complete, layer=1)))
> rtest_B8 <- rtest_B8/10000
> rtest_B4 <- rtest_B4/10000
> rtest_B2 <- rtest_B2/10000
> EVI_test <- 2.5*(rtest_B8-rtest_B4)/((rtest_B8+6*rtest_B4-7.5*rtest_B2)+1)
> plot(EVI_test)
> EVI_test
class : RasterLayer
dimensions : 10980, 10980, 120560400 (nrow, ncol, ncell)
resolution : 0.03278689, 0.01639344 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : r_tmp_2022-04-15_132504_107992_89378.grd
names : layer
values : -8154455, 6779455 (min, max)
> NDVI_test <- (rtest_B8 - rtest_B4) / (rtest_B8 + rtest_B4)
> plot(NDVI_test)
> NDVI_test
class : RasterLayer
dimensions : 10980, 10980, 120560400 (nrow, ncol, ncell)
resolution : 0.03278689, 0.01639344 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : r_tmp_2022-04-15_132601_107992_94720.grd
names : layer
values : -0.9998338, 0.9998693 (min, max)
> hist(EVI_test)
Warning message:
In .hist1(x, maxpixels = maxpixels, main = main, plot = plot, ...) :
0% of the raster cells were used. 100000 values used.
> hist(NDVI_test)
Warning message:
In .hist1(x, maxpixels = maxpixels, main = main, plot = plot, ...) :
0% of the raster cells were used. 100000 values used.
> i1 <- which.max(EVI_test)
> s1 <- stack(rtest_B2, rtest_B4, rtest_B8)
> s <- stack(B2, B4, B8)
> s1[i1]
layer.1 layer.2 layer.3
[1,] 0.3627138 0.06103937 1.354118
> i2 <- which.max(EVI)
> s[i2]
NULL
> i3 <- which.max(NDVI)
> s[i3]
layer.1 layer.3 layer.7
[1,] 1e-04 1e-04 0.1074
> i4 <- which.max(NDVI_test)
> s1[i4]
layer.1 layer.2 layer.3
[1,] 0.3392011 0.0001000134 1.53007
> which.max(values(EVI))
[1] 73288066
> which.min(values(EVI))
[1] 103184643
Adding image of zoom and click in search of max EVI, but it does not look like there is anything greater than 1.113 - that is the highest number I have.

This formula
EVI <- 2.5*(B8-B4)/((B8+6*B4-7.5*B2)+1)
Suggests that the denominator could be very small and that would lead to a large EVI. But there is no reason to assume that the max EVI will be reached when all the Bs are at their maximum value.
What I would do is find the cell with the maximum EVI value, and then look at the input values in that cell. Perhaps like this
i <- which.max(EVI)
s <- stack(B2, B4, B8)
s[i]

I solved this issue after re-writing my script using the newer terra package; updating my code from the raster package. The terra package provided the solution with: resample {terra}
The notes state: "near: nearest neighbor...It is not a good choice for continuous values. This is used by default if the first layer of x is categorical."
My issue was tied to the Sentinel-2 Scene Classification (SCL) and Cloud (Cld) classification layers, which are categorical data:
1: Saturated defective, 2: Dark feature shadow, 3: Cloud shadow, 4: Vegetation, 5: Not vegetated, 6: Water, 7: Unclassified, 8: Cloud medium probability, 9: Cloud high probability, 10: Thin cirrus, 11: Snow ice.
The raster resample calculation I used was calling method=bilinear. This converted the discrete (factor / categorical) to continuous data and caused the errors to follow in the masking process. The coding was repaired by using method=near and class: SpatRaster.

Related

convert raster from coarse to finer resolution

This is my raster properties:
class : RasterLayer
dimensions : 3001, 3000, 9003000 (nrow, ncol, ncell)
resolution : 0.12, 0.034 (x, y)
extent : -180, 180, -40.034, 62 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : test.tif
names : test
I want to convert this into a raster with a resolution of 0.008333333 in both x and y direction
library(raster)
tar_res <- 0.008333333
disagg_raster <- disaggregate(my_raster,
fact = c(res(my_raster)[1]/tar_res, res(my_raster)[2]/tar_res))
disagg_raster
class : RasterLayer
dimensions : 12004, 42000, 504168000 (nrow, ncol, ncell)
resolution : 0.008571429, 0.0085 (x, y)
extent : -180, 180, -40.034, 62 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
How do I get the resolution to be 0.008333333 in both x and y direction?
If you cannot get there by (dis) aggregating you can use resample instead.
# example data
library(terra)
r <- rast(nrow=3001, ncol=3000, ymin=-40.034, ymax=62)
# create empty template with the desired geometry
tmp <- rast(r)
res(tmp) <- 1/120
ymax(tmp) <- ymax(r)
# resample
x <- resample(r, tmp)
See here for a more general and longer answer.

how to get cell dimensions from rasterized ```SpatialPolygonsDataFrame```?

I have SpatialPolygonsDataFrame class in R, which I want to rasterize. I rasterize the the polygon using this code below:
> p <- shapefile('MadaGranary')
> p
class : SpatialPolygonsDataFrame
features : 1
extent : 100.1269, 100.5313, 5.793798, 6.446769 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
variables : 1
names : id
value : 1
> crs(p) <- NULL
> # Define RasterLayer object
> r.raster <- raster(extent(p), res = 100)
> #rasterize
> p.r <- rasterize(p, r.raster)
> print(p.r)
class : RasterLayer
dimensions : 1, 1, 1 (nrow, ncol, ncell)
resolution : 100, 100 (x, y)
extent : 100.1269, 200.1269, -93.55323, 6.446769 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : memory
names : layer
values : NA, NA (min, max)
attributes :
ID id
1 1
Unfortunately, this chunk of code has assigned cell dimensions to dimensions : 1, 1, 1 (nrow, ncol, ncell), and its very important for me to get the actual values of ncols and nrows.
And when I print p.r, I need to get the values of dimensions : (nrow, ncol, ncell) in the console so that I will be able to save all attributes in order to use it another analysis later.
attention:The resolutionoutput that I need to get should be real values representing ncols and nrow in the new raster, but not just dimensions : 1, 1, 1 (nrow, ncol, ncell) as shown in my code.
Can any one help please??
If you want to set nrow and ncol then you do so (and not set the resolution, which expresses the size of each cell). Here is an example:
library(raster)
#Loading required package: sp
e <- extent(0,1,0,1)
r <- raster(e, nrow=100, ncol=100)
r
#class : RasterLayer
#dimensions : 100, 100, 10000 (nrow, ncol, ncell)
#resolution : 0.01, 0.01 (x, y)
#extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)
#crs : NA

R - Calculate mean of rasterbrick

I am trying to calculate the mean of a rasterbrick over specific timesteps in R.
Subsetting the dataset shows a lay-out that appears to be correct (to me), however R does not allow any computations to follow up.
> r_sub <- b[[1699:1862]]
> r_sub
class : RasterStack
dimensions : 127, 147, 18669, 164 (nrow, ncol, ncell, nlayers)
resolution : 5, 5 (x, y)
extent : 603299.4, 604034.4, 6615598, 6616233 (xmin, xmax, ymin, ymax)
crs : NA
names : X2019.02.09.19, X2019.02.09.20, X2019.02.09.21, X2019.02.09.22, X2019.02.09.23, X2019.02.09.24, X2019.02.10.1, X2019.02.10.2, X2019.02.10.3, X2019.02.10.4, X2019.02.10.5, X2019.02.10.6, X2019.02.10.7, X2019.02.10.8, X2019.02.10.9, ...
> r_mean <- calc(r_sub, mean)
Error in Rsx_nc4_get_vara_double: NetCDF: Index exceeds dimension bound
Var: SWIT Ndims: 3 Start: 1698,0,0 Count: 1,127,147
Error in ncvar_get_inner(ncid2use, varid2use, nc$var[[li]]$missval, addOffset, :
C function R_nc4_get_vara_double returned error
How to solve this specific error?
I am guessing that this is related to a problem with your file, not with the code.
I did this and it worked well
library(raster)
b <- brick("filename.nc")
r_sub <- b[[1699:1862]]
r_sub
#class : RasterStack
#dimensions : 160, 320, 51200, 164 (nrow, ncol, ncell, nlayers)
#resolution : 1.125, 1.121277 (x, y)
#extent : -0.5625, 359.4375, -89.70216, 89.70216 (xmin, xmax, ymin, ymax)
#crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
mean(r_sub)
#class : RasterLayer
#dimensions : 160, 320, 51200 (nrow, ncol, ncell)
#resolution : 1.125, 1.121277 (x, y)
#extent : -0.5625, 359.4375, -89.70216, 89.70216 (xmin, xmax, ymin, ymax)
#crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
#source : memory
#names : layer
#values : 3.033032e-07, 0.0002482847 (min, max)
Also, you might want to look into using stackApply

Raster calc returns only one layers when applied to raster stack

I have a raster stack created from daily climate data. Can be found here:
#!/bin/bash
wget -nc -c -nd http://northwestknowledge.net/metdata/data/tmmx_1982.nc
The goal is to get the 95th percentile of temperature values per month from these daily records. Whenever I use calc from the raster package it just returns one layer instead of 12 (e.g., 12 months) What am I missing?!
library(raster)
library(tidyverse)
library(lubridate)
file = "../data/raw/climate/tmmx_1982.nc "
rstr <- raster(file)
> rstr
class : RasterBrick
dimensions : 585, 1386, 810810, 366 (nrow, ncol, ncell, nlayers)
resolution : 0.04166667, 0.04166667 (x, y)
extent : -124.793, -67.043, 25.04186, 49.41686 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0
data source : in memory
names : layer.1, layer.2, layer.3, layer.4, layer.5, layer.6, layer.7, layer.8, layer.9, layer.10, layer.11, layer.12, layer.13, layer.14, layer.15, ...
min values : 1.3268673, 0.7221603, 1.8519223, 1.6214808, 0.8629752, 1.1126643, 1.8769895, 0.9587604, 1.7360761, 2.1099827, 2.1147265, 1.8696048, 1.7619936, 2.0253942, 2.6840794, ...
max values : 73.20462, 60.35675, 64.68890, 53.11994, 60.15675, 55.91125, 77.29095, 64.39179, 48.26004, 64.70559, 79.85970, 62.31242, 53.89768, 52.15949, 80.23198, ...
date_seq <- date_seq[1:nlayers(rstr)]
month_seq <- month(date_seq)
mean_tmp <- stackApply(rstr, month_seq, fun = mean)
> mean_tmp
class : RasterBrick
dimensions : 585, 1386, 810810, 12 (nrow, ncol, ncell, nlayers)
resolution : 0.04166667, 0.04166667 (x, y)
extent : -124.793, -67.043, 25.04186, 49.41686 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0
data source : /tmp/RtmpYf4pQe/raster/r_tmp_2017-09-25_182536_48012_88372.grd
names : index_1, index_2, index_3, index_4, index_5, index_6, index_7, index_8, index_9, index_10, index_11, index_12
min values : 4.586111, 5.656802, 6.444234, 6.875973, 6.281896, 4.495534, 5.081545, 4.396824, 4.316368, 6.413400, 4.233641, 3.119827
max values : 49.12178, 47.61632, 44.70796, 47.57829, 46.97714, 51.61986, 37.77228, 51.30043, 42.51572, 36.86453, 37.96615, 52.15552
mean_90thtmp <- calc(mean_tmp, forceapply = TRUE,
fun = function(x) {quantile(x, probs = 0.90, na.rm = TRUE) })
> mean_90thtmp
class : RasterLayer
dimensions : 585, 1386, 810810 (nrow, ncol, ncell)
resolution : 0.04166667, 0.04166667 (x, y)
extent : -124.793, -67.043, 25.04186, 49.41686 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0
data source : in memory
names : layer
values : 8.84197, 50.52144 (min, max)
Suggestions are very much appreciated!
Thanks!
One option is using a for loop:
x <- stack() # create an empty stack
for (i in 1:nlayers(mean_tmp)){
mean_90thtmp <- calc(mean_tmp[[i]], forceapply = TRUE,
fun = function(x) {quantile(x, probs = 0.90, na.rm = TRUE) })
x <- stack(x , mean_90thtmp )
}
I can't get the stackApply function to work with using quantile as the function.
Here is a method that uses a loop to select all layers from the stack for each month.
library(raster)
rstr <- raster('tmmx_1982.nc')
date_seq <- date_seq[1:nlayers(rstr)]
month_seq <- month(date_seq)
outSt <- stack()
for (mn in 1:12){
st <- subset(rstr, which(month_seq == mn))
mn_90th <- calc(st, fun=function(x) raster::quantile(x, probs=0.9, na.rm=T))
outSt <- addLayer(outSt, mn_90th)
}

R Resample Raster Behaving Inconsistently

I have two netCDF files with different extents and resolutions. I would like to create rasters from both files that are the same extent and resolution. I want the resolution from one file, and the extent from the other.
Here is the code I'm using:
require(raster);
#Get information
iceMaxNineK <- raster("~/Desktop/TRACE-21k_Data/NineK.ICEFRAC.max.avg.nc")
saltNineK <- brick("~/Desktop/TRACE-21k_Data/NineK.SALT.nc", lvar = 4)
#Making everything nice and uniform and useable
#==============================================
#set up an initial "sampling raster"
e <- extent(0, 360, -90, 90) #xmin,xmax,ymin,ymax
e <- raster(e,nrows=1,ncols=1,crs=saltNineK#crs)
res(e) <- res(saltNineK)
values(e) <- 0
#Resample ice
iceMaxNineK <- resample(iceMaxNineK, e, method="ngb")
plot(iceMaxNineK)
#Resample salt
saltNineK <- resample(saltNineK, e, method="ngb")
plot(saltNineK)
Resampling iceMaxNineK works, but resampling saltNineK results in a map that is jammed up into one corner of the defined area of extent, as shown in the pictures below.
First, iceMaxNineK:
Second, saltNineK:
Dimensions of iceMaxNineK before resampling:
class : RasterLayer
dimensions : 48, 96, 4608 (nrow, ncol, ncell)
resolution : 3.75, 3.708898 (x, y)
extent : -1.875, 358.125, -89.01354, 89.01354 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : /Users/Hannah/Desktop/TRACE-21k_Data/NineK.ICEFRAC.max.avg.nc
names : Fraction.of.sfc.area.covered.by.sea.ice
z-value : -8.99945876078469
zvar : ICEFRAC
Dimensions of iceMaxNineK after resampling:
class : RasterLayer
dimensions : 180, 360, 64800 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 0, 360, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : Fraction.of.sfc.area.covered.by.sea.ice
values : 0, 0.9997393 (min, max)
Dimensions of saltNineK before resampling:
class : RasterBrick
dimensions : 116, 100, 11600, 25 (nrow, ncol, ncell, nlayers)
resolution : 1, 1 (x, y)
extent : 0.5, 100.5, 0.5, 116.5 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : /Users/Hannah/Desktop/TRACE-21k_Data/NineK.SALT.nc
names : X400, X1222.02453613281, X2108.88061523438, X3100.537109375, X4239.19677734375, X5577.873046875, X7187.42822265625, X9166.115234375, X11653.9140625, X14854.84765625, X19072.095703125, X24762.70703125, X32618.9296875, X43673.65625, X59384.83984375, ...
centimeters : 400, 475128.78125 (min, max)
varname : SALT
level : 1
Dimensions of saltNineK after resampling:
class : RasterBrick
dimensions : 180, 360, 64800, 25 (nrow, ncol, ncell, nlayers)
resolution : 1, 1 (x, y)
extent : 0, 360, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : X400, X1222.02453613281, X2108.88061523438, X3100.537109375, X4239.19677734375, X5577.873046875, X7187.42822265625, X9166.115234375, X11653.9140625, X14854.84765625, X19072.095703125, X24762.70703125, X32618.9296875, X43673.65625, X59384.83984375, ...
min values : 6.842899, 6.850603, 6.853004, 6.853779, 6.853567, 23.148109, 23.148115, 23.148115, 23.148119, 23.148121, 23.148121, 23.148121, 23.148121, 23.148121, 23.148121, ...
max values : 39.60786, 39.60786, 39.60783, 39.60777, 39.60769, 39.60766, 39.60765, 39.60757, 39.60755, 39.60742, 39.60739, 39.60732, 39.60730, 39.60730, 39.60730, ...
Sample files can be accessed via the following link: https://www.dropbox.com/s/x8oqem317vmr7yq/DataForRResample.zip?dl=0
Thank you for your time.
I have now solved this question. The problem was the input file, which was at a T31_gx3v5 resolution (http://www.cgd.ucar.edu/ccr/TraCE/; Yeager et al., 2006; Otto-Bliesner et al., 2006). R doesn't pick up on this. The layers needed to be regridded to 1X1 degree using the ncl language before importing them into R. For more information on regridding in ncl, follow this link: https://www.ncl.ucar.edu/Document/Functions/Pop_remap/PopLatLon.shtml.

Resources