Skip to content

Instantly share code, notes, and snippets.

@JaszzyJas
Created October 8, 2015 23:36
Show Gist options
  • Save JaszzyJas/f6a4b2dbe237bc0c43db to your computer and use it in GitHub Desktop.
Save JaszzyJas/f6a4b2dbe237bc0c43db to your computer and use it in GitHub Desktop.
Random DD stuff
## Define function that will convert temperatures to Celcius and divide by 8 [same as * 1/8] (as each measurement represents 1/8 of a day)
#Note: need to add a part here where any value <0 = 0 and not a negative, as heating DD's are calculated only using the 'above the threshold'
extractDD=function(path) {
vals=(values(raster(path,varname="TMP"))-273.15)/8
if(vals < 0) {
vals = 0
}
if (sum(is.na(vals))>0)
stop(paste0("this raster has na values: ", path))
return(vals)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment