Last active
August 3, 2021 02:38
-
-
Save diodon/ecf01fab6c2916945f39b996da5768e1 to your computer and use it in GitHub Desktop.
HeatAccumulation: calculate BK curve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getAcumExposure = function(ts, tmin=27.5, tinc=1){ | |
| ## calculate accumulated exposure | |
| ## this version does not have gaps in temp bins | |
| ## ts is a times series of daily values | |
| ## tmin is the starint temp to accumulate | |
| ## tinc is the number of decimal places to round temperature | |
| ## removes NA's | |
| ts = ts[!is.na(ts)] | |
| ts = ts[ts>=tmin] | |
| if (length(ts)==0){ | |
| return(NA) ## this is the case when tmin is higher than ts max | |
| } | |
| ts = round(ts, tinc) | |
| tsDF <- data.frame(temp = seq(tmin, max(ts, na.rm=T), by=10^-tinc), nDays=NA) | |
| for (i in 1:nrow(tsDF)){ | |
| tsDF$nDays[i] <- sum(ts >= tsDF$temp[i]) | |
| } | |
| ## add last temp with zero days | |
| tsDF <- rbind(tsDF, data.frame(temp=max(tsDF$temp+10^-tinc), nDays=0)) | |
| return(tsDF) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment