# Count values "greater than" in rasterbrick layers

5 messages
Open this post in threaded view
|

## Count values "greater than" in rasterbrick layers

 Dear all, I have a 31-layer rasterbrick where each layer represents daily rainfall records for a certain month. My goal is to perform two calculations in this brick: a) Sum up total rainfall for the entire month b) For the entire month (all rasterbrick layers), calculate the number of days where it rained (i.e. rainfall > 1) Problem a) is straightforward and I solved it with the help of a simple calc command.  Problem b), however, is where I am having troubles. The command I came up with doesn't work, as the final raster has values way greater than 31 (which would be the limit of each cell, if it had rained every day of the month on that cell). This is my code so far. Any suggestions? library(raster) # generate raster data r <- raster(ncol=384, nrow=190) b <- brick(sapply(1:31, function(i) setValues(r, rnorm(ncell(r), i, 3)))) # sum up rain acc.rain <- calc(b, fun=sum) # count wet days wet.days <- calc(b, fun=function(x,na.rm) sum(x[x>1]))   Many thanks in advance, -- Thiago V. dos Santos PhD student Land and Atmospheric Science University of Minnesota http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htmPhone: (612) 323 9898         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: Count values "greater than" in rasterbrick layers

Open this post in threaded view
|