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.htm
Phone: (612) 323 9898
	[[alternative HTML version deleted]]

