file <- system.file("data/A1128551.DLY",package="seas")
print(file)
dat <- read.msc(file)
print(head(dat))
plot.seas.temp(dat)
plot.year(dat)
# Show how to convert from daily to monthly data
dat$yearmonth <- factor(paste(format(dat$date,"%Y-%m"),15,sep="-"))
mlydat <- data.frame(date=as.Date(levels(dat$yearmonth)))
mlydat$year <- factor(format(mlydat$date,"%Y"))
mlydat$month <- mkseas(mlydat,"mon")
# means for temperature data
mlydat$t_max <- as.numeric(tapply(dat$t_max, dat$yearmonth,
mean,na.rm=TRUE))
mlydat$t_min <- as.numeric(tapply(dat$t_min, dat$yearmonth,
mean,na.rm=TRUE))
mlydat$t_mean <- as.numeric(tapply(dat$t_mean, dat$yearmonth,
mean,na.rm=TRUE))
# sums for precipitation-related data
mlydat$rain <- as.numeric(tapply(dat$rain, dat$yearmonth,
sum,na.rm=TRUE))
mlydat$snow <- as.numeric(tapply(dat$snow, dat$yearmonth,
sum,na.rm=TRUE))
mlydat$precip <- as.numeric(tapply(dat$precip, dat$yearmonth,
sum,na.rm=TRUE))
print(head(mlydat),12)
# Show how to convert from a HLY file into daily summaries
# this is currently shown somewhere at http://www.sfu.ca/~mwtoews/
hlydat <- read.msc(bzfile("HLY11_L1127800.bz2"), flags=TRUE)
hlydat$date <- factor(hlydat$date)
# sum the solar radiation for each day to find the 'total daily'
sumdat <- tapply(hlydat$solar, hlydat$date, sum, na.rm=TRUE)
dlydat <- data.frame(date=as.Date(names(sumdat)),
solar=as.numeric(sumdat))
# sum the number of hours without measurements
sumdat <- tapply(hlydat$solar, hlydat$date,
function(v)(24 - sum(!is.na(v))))
dlydat$na <- as.integer(sumdat)
# quality control to remove days with less than 4 hours missing
Summerland <- dlydat[dlydat$na < 4,]
attr(Summerland$solar,"units") <- "W/(m^2*day"
attr(Summerland$solar,"long.name") <- "Daily total global solar radiation"
plot.seas.var(Summerland,var="solar", col="yellow", width=5)
Run the code above in your browser using DataLab