R/p15Calc.R

# Author: Julian Ramirez, [email protected]
# Date :  December 2009
# Version 0.1
# Licence GPL v3

p15Calc <- function(rlist, outfile, format='') {
	
	if (!is.list(rlist)) {
		stop('First argument should be a list or rasters (prec)')
	}
	
	if (!file.exists(outfile)) {
			cat("", "\n", "Precipitation seasonality (P15)", "\n")
			
			tmpstack <- stack(rlist)
			b15fun <- function(x) {round((100 * sqrt((sd(x)^2) * 11 / 12)) / (1 + sum(x) / 12))}
			p15 <- calc(tmpstack, b15fun, progress="text", filename=outfile, format=format, overwrite=TRUE)
			rm(tmpstack)
			
		} else {
			cat("", "\n", "File bio_15 already exists, skipping calculation, but loading", "\n")
			p15 <- raster(outfile)
		}
		return(p15)
}

Try the BioCalc package in your browser

Any scripts or data that you put into this service are public.

BioCalc documentation built on May 2, 2019, 4:41 p.m.