bleutner/RStoolbox

topCor on small raster: Error in .local(x, size, ...) : size <= ncell(x) is not TRUE

latenooker opened this issue · 2 comments

Hello,

I'm trying to apply a topographic correction to a stack of MODIS images, and I'm getting an error that I assume has to do with with the fixed sample size of 10000 used by .kestimate (my raster stack has 5046 cells). Is there a straightforward way to pass a different sample size to .kestimate?

Thanks,
Nate

topCor(modis_4band_means, dem = srtm_MODIS, solarAngles = c(1, 0.7), method = "C")

Error in .local(x, size, ...) : size <= ncell(x) is not TRUE

traceback()

8: stop(simpleError(msg, call = sys.call(-1)))
7: stopifnot(size <= ncell(x))
6: .local(x, size, ...)
5: sampleRandom(stack(img, illu, slope, strat), size = 10000)
4: sampleRandom(stack(img, illu, slope, strat), size = 10000)
3: as.data.frame(sampleRandom(stack(img, illu, slope, strat), size = 10000))
2: .kestimate(img, illu, slope, method = "stat")
1: topCor(modis_4band_means, dem = srtm_MODIS, solarAngles = c(1,
0.7), method = "C")

modis_4band_means
class : RasterBrick
dimensions : 58, 87, 5046, 4 (nrow, ncol, ncell, nlayers)
resolution : 288, 288.6207 (x, y)
extent : 694419.2, 719475.2, 2149977, 2166717 (xmin, xmax, ymin, ymax)
crs : +proj=utm +zone=14 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
source : memory
names : layer.1, layer.2, layer.3, layer.4
min values : 0.015384210, 0.115567346, 0.009112088, 0.042510675
max values : 0.13556559, 0.36798491, 0.08137419, 0.19660914

I got around this error by redefining local versions of .kestimate and topCor, but I wondered if there's a less hacky solution.

Thanks for the report. I'll fix that with the next release.