# NOT RUN {
fname <- system.file("extdata", "A1128551.DLY", package="seas")
print(fname)
dat <- read.msc(fname)
print(head(dat))
seas.temp.plot(dat)
year.plot(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
# }
# NOT RUN {
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"
seas.var.plot(Summerland, var="solar", col="yellow", width=5)
# }
Run the code above in your browser using DataLab