In the context of a RUSLE erosion modelling I would like to calculate the sum of precipitation at the entry date of phenological phases.
Suppose I have 13 grids, one of which is the phenophase entry date PhenoDate with values from 1 to 356, the other 12 represent average daily shares of the annual precipitation sum for the individual months [dPrecJan,...,dPrecDec].
I would like to calculate the precipitation sum using a set of conditional statements:
If the phenophase begins in january, multiply the phenophase entry date with the january average daily precipitation, else if the phenophase begins in february, multiply [...]
I already tried to implement my conditional statements using the sum of products, where the condition returns either 0 or 1:
PrecSum <- ((PhenoDate<32) * PhenoDate * dPrecJan) + ( (PhenoDate>=32 & PhenoDate<60) * ((31*dPrecJan)+((PhenoDate-31) * dPrecFeb))) + ( (PhenoDate>=60 & PhenoDate<91) * ((31*dPrecJan)+(28*dPrecFeb)+( (PhenoDate-59) * dPrecMar))) + (( [etc.]))
Actually not too complicated construction, but since I use very high-resolution raster layers, the calculation goes beyond my memory capacities.
I'm looking for a memory-efficient construction, which allows to set multiple conditional statements on my raster calculation.