[R-sig-Geo] Error in applying calc to rasterbrick with NA vallues

Jackson Rodrigues j@ck@onmrodr|gue@ @end|ng |rom gm@||@com
Fri May 8 15:59:22 CEST 2020


Dear all,

I am sorry for previous email. I am learning how to handle correctly this
list.

On R-sig-Geo Digest, Vol 201, Issue 5  I got a smart solution for my tests
with parallelization.

However, my original data has NA values, and applying the function created
to my data I get some errors.
I have played around with other commands like na.rm, na.action=na.exclude
or reclassifications and none worked.

Could someone give me some herp again?

best wishes,

Jackson
################
library(raster)
library(trend)

r <- raster(ncol=96, nrow=63, vals=runif(63*96))
n <- 672  # number of copies
s <- stack(lapply(1:n, function(i) rz<-stack(r[i]<-(r^2/3))))
s[s < 0.1] <- NA

# Define the function to apply to each pixel; it should return a numeric
or a vector of numerics with always the same lenght
fun <- function(x){
  out <- pettitt.test(x)[3]$estimate
  return(unname(out))
}

# Check that it works
fun(seq(2000))

# Check that it works with calc
s_out <- calc(s, fun = fun)

Error in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply) :
  cannot use this function

# Parallelize with clusterR
beginCluster()
s_out <- clusterR(s, fun=calc, args=list(fun=fun))

[1] "cannot use this function"
attr(,"class")
[1] "snow-try-error" "try-error"
Error in clusterR(s, fun = calc, args = list(fun = fun)) : cluster error

endCluster()
##############

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list