Created
February 14, 2015 11:55
-
-
Save oscarperpinan/e86d61832fc384904a4a to your computer and use it in GitHub Desktop.
This file contains 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
library(zoo) | |
library(rasterVis) | |
## DESCRIPTION: http://iridl.ldeo.columbia.edu/SOURCES/.CAC/.sst/ | |
setwd(tempdir()) | |
download.file('http://iridl.ldeo.columbia.edu/SOURCES/.CAC/.sst/data.nc', destfile = 'SST.nc') | |
SST <- stack('SST.nc') | |
idx <- seq(as.Date('1970-01-01'), as.Date('2003-03-01'), by='month') | |
tt <- as.yearmon(idx) | |
SST <- setZ(SST, tt) | |
names(SST) <- as.character(tt) | |
## Extract month value from a Date or yearmon object | |
month <- function(x)format(x, '%m') | |
## Compute anomaly using monthly grouping with ave | |
anomaly <- function(x){ | |
## Monthly means | |
mm <- ave(x, month(tt), FUN = mean) | |
## Monthly standard deviation | |
msd <- ave(x, month(tt), FUN = sd) | |
## anomaly | |
(x - mm)/msd | |
} | |
## Use anomaly with calc | |
SSTanom <- calc(SST, anomaly) | |
SSTanom <- setZ(SSTanom, tt) | |
## Ok, let's see the result | |
hovmoller(SSTanom, par.settings = RdBuTheme) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment