######################################################################################## # script to plot total solar uv irradiance between wavelength 116nm - 310nm # solar uv from SORCE # http://lasp.colorado.edu/sorce/ssi_data/ # 8 Nov 2011 # Joseph Wheatley # www.joewheatley.net ######################################################################################## require(ggplot2) file.in <- "http://lasp.colorado.edu/sorce/ssi_data/solstice/fuv/txt/sorce_fuv_latest.txt.zip" download.file(file.in, "temp.txt.zip") file.in <- unzip("temp.txt.zip") uvF <- read.table(file.in, skip=79,header=F) names(uvF) <- c("date","date_julian","wave_min","wave_max","mode","version","irradiance","error","quality") file.in <- "http://lasp.colorado.edu/sorce/ssi_data/solstice/muv/txt/sorce_muv_latest.txt.zip" download.file(file.in, "temp.txt.zip") file.in <- unzip("temp.txt.zip") uvM <- read.table(file.in, skip=79,header=F) names(uvM) <- c("date","date_julian","wave_min","wave_max","mode","version","irradiance","error","quality") #clean up unlink(file.in) unlink("temp.txt.zip") #merge data uvF <- subset(uvF, select=c(date,wave_max,irradiance)) uvM <- subset(uvM, select=c(date,wave_max,irradiance)) uv <- merge(uvF,uvM, all=T) uv$year <- substr(uv$date,1,4) uv$month <- substr(uv$date,5,6) uv$day <- substr(uv$date,7,8) dates <- as.Date(paste(uv$year,uv$month,uv$day,sep="-")) uv$date <- dates uv$year <- NULL uv$month <- NULL uv$day <- NULL #switch to wide format uv.wide <- cast(uv,date~wave_max, value="irradiance") uv.wide <- data.frame(uv.wide) nDate <- length(uv.wide$date) #total uv irradiance uv.wide$total <- sapply(1:nDate,function(d) sum(unlist(uv.wide[d,])[-1])) #total irradiance dataframe uv.tot <- data.frame(dates=uv.wide$date,uvtotal=uv.wide$total) g <- ggplot(uv.tot, aes(dates,uvtotal)) + geom_point(aes(colour="115-310nm"))+scale_colour_discrete("") g <- g +stat_smooth(colour="grey50",method="loess",span=0.5,size=1) g <- g + opts(title=expression(paste("solar UV irradiance (", Wm^{-2}, ")", sep = "")))+xlab("") + ylab("") #g <- g+ geom_text(aes(x,y,label=text), data.frame(x=uv.tot$dates[1000],y=19.3,text="data:lasp.colorado.edu/sorce/data/ssi_data.htm"),size=4) print(g)