[R-sig-Geo] ApproxNA producing different and incorrect results in stacks of large rasters
Jodi Norris
Jodi_Norris at nps.gov
Thu Mar 2 14:52:09 CET 2017
Hello, I’m trying to confirm if there is a bug or at least unexplained
change in behavior in the function approxNA in the most recent version of
the R Raster package (Raster 2.5-8).
I have a small reproducible example below. The original symptoms (too large
to share) were that most the output of the approxNA command appeared to be
the same as the input – it had lots and lots of NA values that had not been
interpolated… but when I switched back to an older version of the package
(2.3-12) and an older version of R (3.3.1) it returns the correct
interpolated results. I have tried it with raster datatype set to INT2S
and with no particular raster datatype set.
I have checked the documentation in case there is some reason that I should
expect the results to differ but there are no changes between the old
package version that worked correctly and the new package version.
In my reproducible example there are fewer errors but they are quite
obvious to see just from the plotting view (included in the example). In
these plots you can see that the northern parts of several layers have NA
values remaining that should have been interpolated.
Official system bug report details are shown at the bottom of this email;
I’m running 64-bit Windows 7 and 64-bit R 3.3.2 with raster 2.5-8 with an
R-Studio interface, but I have tested also on R-console with the same
results and on a different computer that has the same configuration, I have
also tested in 32-bit R with the same results.
A trigger seems to be the presence of NA values in the first or last layer,
but the errors occur in cells that do not have NA values in the first or
last layer: for example the top left cells are only missing in layer 2 in
the original stack, so it should be a very simple interpolation for those
cells from layer 1 to layer 3.
I did follow the R instructions for submitting a bug report a couple of
weeks ago but I’m not sure if that contact info is correct, or if it might
have gone into a spam folder.
Best regards, and thanks for any suggestions
Jodi
##### start Reproducible example
library(raster)
# make a large raster, it must be quite big to have a problem
r <- raster(ncols=8142, nrows=3285)
# make six rasters to stack, use different ranges to better see the
interpolation results
r1 <- setValues(r, round(10 * runif(ncell(r)),0))
r2 <- setValues(r, NA)
r3 <- setValues(r, round(100 * runif(ncell(r)),0))
r4 <- setValues(r, round(1000 * runif(ncell(r)),0))
r5 <- setValues(r, round(50 * runif(ncell(r)),0))
r6 <- setValues(r, round(100 * runif(ncell(r)),0))
# insert some NA values
r1[100:600,] <- NA
r3[,1500:1950] <- NA
r5[,400:800] <- NA
r6[2500:2900,] <- NA
# insert some constant values to make it easier to see if interpolation is
working
r4[300:500,] <- 750
r6[300:400,] <- 20
r6[400:500,] <- 100
# make a stack
s <- stack(r1,r2,r3,r4,r5,r6)
# see what the pre-interpolation stack looks like
plot(s)
# interpolate, this takes a while
x2 <- approxNA(s, method = "linear", rule=2)
# see what the post interpolation looks like, there should be filled in
values for all parts of all layers
# but instead it’s retaining many of the NA values
plot(x2)
## End reproducible example
--please do not edit the information below--
Package: raster
Version: 2.5-8
Maintainer: Robert J. Hijmans <r.hijmans at gmail.com>
Built: R 3.3.1; x86_64-w64-mingw32; 2016-07-19 01:23:33 UTC; windows
R Version:
platform = x86_64-w64-mingw32
arch = x86_64
os = mingw32
system = x86_64, mingw32
status =
major = 3
minor = 3.2
year = 2016
month = 10
day = 31
svn rev = 71607
language = R
version.string = R version 3.3.2 (2016-10-31)
nickname = Sincere Pumpkin Patch
Windows 7 x64 (build 7601) Service Pack 1
Locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
Search Path:
.GlobalEnv, package:raster, package:sp, package:stats,
package:graphics, package:grDevices, package:utils, package:datasets,
package:methods, Autoloads, package:base
Jodi_Norris at nps.gov
Landscape and Quantitative Ecologist
Inventory and Monitoring Program
Southern Colorado Plateau Network
(928)-523-6142
National Park Service SCPN
Northern Arizona University
525 S Beaver, Bldg 20, Rm 131
PO Box 5663
Flagstaff, AZ, 86011-5663
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list