Skip to content
Prev 15184 / 29559 Next

Antw: Re: Antw: Error when using rowSums along with a RasterStack object

? Matteo,

? I am very sorry for taking so long to answer - I took some days off starting in the same day you sent the message.

? I have tested the alternative you proposed. Indeed rowSums makes all the difference, take a look:
class ? ? ? : RasterStack?
dimensions ?: 5568, 8289, 46153152, 45 ?(nrow, ncol, ncell, nlayers)
resolution ?: 0.00898, 0.00898 ?(x, y)
extent ? ? ?: -104.4326, -29.99736, -40.00064, 10 ?(xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0?
min values ?: -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, ...?
max values ?: 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, ...?
layer names : gpp2001001.Gpp_1km, gpp2001009.Gpp_1km, gpp2001017.Gpp_1km, gpp2001025.Gpp_1km, gpp2001033.Gpp_1km, gpp2001041.Gpp_1km, gpp2001049.Gpp_1km, gpp2001057.Gpp_1km, gpp2001065.Gpp_1km, gpp2001073.Gpp_1km, gpp2001081.Gpp_1km, gpp2001089.Gpp_1km, gpp2001097.Gpp_1km, gpp2001105.Gpp_1km, gpp2001113.Gpp_1km, ...?

?> fun <- function(x) {
+ ? ? ? ? x [x > 32760] <- NA
+ ? ? ? ? x <- x * 0.0001
+ ? ? ? ? x <- sum(x,na.rm=FALSE)
+ }
? ? user ? system ?elapsed?
1485.619 ? 47.935 3320.638

? Function 'sum' took ~55 minutes to integrate 45 images
+ ? ? ? ? x [x > 32760] <- NA
+ ? ? ? ? x <- x * 0.0001
+ ? ? ? ? x <- rowSums(x,na.rm=FALSE)

+ }
? ? user ? system ?elapsed?
?393.477 ? 79.516 2197.248?

? Same 45 images took ~36 minutes to be integrated using 'rowSums' function!!

? Thanks for this tip - it will certainly speed up my work!

? All the best,
? Thiago.