9 |
9 |
library(sp)
|
10 |
10 |
library(spgrass6)
|
11 |
11 |
library(rgdal)
|
12 |
|
library(reshape2)
|
|
12 |
library(reshape)
|
13 |
13 |
library(ncdf4)
|
14 |
14 |
library(geosphere)
|
15 |
15 |
library(rgeos)
|
... | ... | |
69 |
69 |
layerNames(cld) <- as.character(format(months,"%b"))
|
70 |
70 |
#cot=projectRaster(from=cot,crs="+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0",method="ngb")
|
71 |
71 |
cldm=mean(cld,na.rm=T)
|
72 |
|
### TODO: change to bilinear!
|
73 |
|
|
74 |
|
|
|
72 |
### TODO: change to bilinear if reprojecting!
|
|
73 |
|
|
74 |
### load PRISM data for comparison
|
|
75 |
prism=brick("data/prism/prism_climate.nc",varname="ppt")
|
|
76 |
## project to sinusoidal
|
|
77 |
projection(prism)=CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
|
|
78 |
prism=projectRaster(prism,cer)
|
|
79 |
prism[prism<0]=NA #for some reason NAvalue() wasn't working
|
|
80 |
setZ(prism,months,name="time")
|
|
81 |
prism@z=list(months)
|
|
82 |
prism@zname="time"
|
|
83 |
layerNames(prism) <- as.character(format(months,"%b"))
|
|
84 |
|
|
85 |
#### build a pixel by variable matrix
|
|
86 |
vars=c("cer","cld","cot","prism")
|
|
87 |
bd=melt(as.matrix(vars[1]))
|
|
88 |
colnames(bd)=c("cell","month",vars[1])
|
|
89 |
for(v in vars[-1]) {print(v); bd[,v]=melt(as.matrix(get(v)))$value}
|
|
90 |
bd=bd[!is.na(bd$cer)|is.na(bd$prism),]
|
|
91 |
|
|
92 |
## Summarize annual metrics for full rasters
|
|
93 |
|
|
94 |
### get all variables from all months
|
|
95 |
c01=brick(mclapply(vars,function(v) projectRaster(get(v),crs="+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")))
|
|
96 |
layerNames(m01)=paste(vars,months,sep="_")
|
|
97 |
|
|
98 |
m01=brick(mclapply(vars,function(v) mean(get(v))))#mean(cer),mean(cld),mean(cot),mean(prism))
|
|
99 |
layerNames(m01)=vars
|
|
100 |
m01=projectRaster(from=m01,crs="+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
|
|
101 |
m01=crop(m01,extent(-125,-115,41,47))
|
75 |
102 |
### get station data, subset to stations in region, and transform to sinusoidal
|
76 |
103 |
load("data/ghcn/roi_ghcn.Rdata")
|
77 |
104 |
load("data/allstations.Rdata")
|
78 |
105 |
|
|
106 |
st2_sin=spTransform(st2,CRS(projection(cer)))
|
|
107 |
|
79 |
108 |
d2=d[d$variable=="ppt"&d$date>=as.Date("2000-01-01"),]
|
80 |
109 |
d2=d2[,-grep("variable",colnames(d2)),]
|
81 |
110 |
st2=st[st$id%in%d$id,]
|
82 |
111 |
#st2=spTransform(st2,CRS(" +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0"))
|
83 |
112 |
d2[,c("lon","lat")]=coordinates(st2)[match(d2$id,st2$id),]
|
|
113 |
d2$elev=st2$elev[match(d2$id,st2$id)]
|
84 |
114 |
d2$month=format(d2$date,"%m")
|
85 |
115 |
d2$value=d2$value/10 #convert to mm
|
86 |
116 |
|
... | ... | |
101 |
131 |
|
102 |
132 |
|
103 |
133 |
### generate monthly means of station data
|
104 |
|
dc=cast(d2,id+lon+lat~month,value="value",fun=function(x) mean(x,na.rm=T)*30)
|
105 |
|
dcl=melt(dc,id.vars=c("id","lon","lat"),value="ppt")
|
|
134 |
dc=cast(d2,id+lon+lat+elev~month,value="value",fun=function(x) mean(x,na.rm=T)*30)
|
|
135 |
dcl=melt(dc,id.vars=c("id","lon","lat","elev"),value="ppt")
|
|
136 |
colnames(dcl)[colnames(dcl)=="value"]="ppt"
|
|
137 |
|
106 |
138 |
|
107 |
139 |
|
108 |
140 |
## merge station data with mod06
|
109 |
141 |
mod06s=merge(dcl,mod06l)
|
110 |
|
mod06s$lvalue=log(mod06s$value+1)
|
111 |
|
colnames(mod06s)[colnames(mod06s)=="value"]="ppt"
|
112 |
142 |
|
113 |
143 |
|
114 |
|
###################################################################
|
115 |
|
###################################################################
|
116 |
144 |
### draw some plots
|
117 |
145 |
gq=function(x,n=10,cut=F) {
|
118 |
|
if(!cut) unique(quantile(x,seq(0,1,len=n+1)))
|
119 |
|
if(cut) cut(x,unique(quantile(x,seq(0,1,len=n+1))))
|
|
146 |
if(!cut) return(unique(quantile(x,seq(0,1,len=n+1),na.rm=T)))
|
|
147 |
if(cut) return(cut(x,unique(quantile(x,seq(0,1,len=n+1),na.rm=T))))
|
120 |
148 |
}
|
121 |
149 |
|
|
150 |
### add some additional variables
|
|
151 |
mod06s$month=factor(mod06s$month,labels=format(as.Date(paste("2000",1:12,"15",sep="-")),"%b"))
|
|
152 |
mod06s$lppt=log(mod06s$ppt)
|
|
153 |
mod06s$glon=cut(mod06s$lon,gq(mod06s$lon,n=5),include.lowest=T,ordered=T)#gq(mod06s$lon,n=3))
|
|
154 |
mod06s$glon2=cut(mod06s$lon,breaks=c(-125,-122,-115),labels=c("Coastal","Inland"),include.lowest=T,ordered=T)#gq(mod06s$lon,n=3))
|
|
155 |
mod06s$gelev=cut(mod06s$elev,breaks=gq(mod06s$elev,n=3),labels=c("Low","Mid","High"),include.lowest=T,ordered=T)
|
|
156 |
mod06s$gbin=factor(paste(mod06s$gelev,mod06s$glon2,sep="_"),levels=c("Low_Coastal","Mid_Coastal","High_Coastal","Low_Inland","Mid_Inland","High_Inland"),ordered=T)
|
|
157 |
|
|
158 |
|
|
159 |
## melt it
|
|
160 |
mod06sl=melt(mod06s[,!grepl("lppt",colnames(mod06s))],id.vars=c("id","lon","lat","elev","month","ppt","glon","glon2","gelev","gbin"))
|
|
161 |
levels(mod06sl$variable)=c("Effective Radius (um)","Cloudy Days (%)","Optical Thickness (%)")
|
|
162 |
|
|
163 |
###################################################################
|
|
164 |
###################################################################
|
|
165 |
|
122 |
166 |
bgyr=colorRampPalette(c("blue","green","yellow","red"))
|
123 |
167 |
|
124 |
168 |
pdf("output/MOD06_summary.pdf",width=11,height=8.5)
|
... | ... | |
128 |
172 |
at=unique(quantile(as.matrix(cld),seq(0,1,len=100),na.rm=T))
|
129 |
173 |
p=levelplot(cld,xlab.top=title,at=at,col.regions=bgyr(length(at)))+layer(sp.lines(roil, lwd=1.2, col='black'))
|
130 |
174 |
print(p)
|
131 |
|
bwplot(cer,main=title,ylab="Cloud Effective Radius (microns)")
|
|
175 |
#bwplot(cer,main=title,ylab="Cloud Effective Radius (microns)")
|
132 |
176 |
|
133 |
177 |
# CER maps
|
134 |
178 |
title="Cloud Effective Radius (microns)"
|
135 |
179 |
at=quantile(as.matrix(cer),seq(0,1,len=100),na.rm=T)
|
136 |
180 |
p=levelplot(cer,xlab.top=title,at=at,col.regions=bgyr(length(at)))+layer(sp.lines(roil, lwd=1.2, col='black'))
|
137 |
181 |
print(p)
|
138 |
|
bwplot(cer,main=title,ylab="Cloud Effective Radius (microns)")
|
|
182 |
#bwplot(cer,main=title,ylab="Cloud Effective Radius (microns)")
|
139 |
183 |
|
140 |
184 |
# COT maps
|
141 |
185 |
title="Cloud Optical Thickness (%)"
|
142 |
186 |
at=quantile(as.matrix(cot),seq(0,1,len=100),na.rm=T)
|
143 |
187 |
p=levelplot(cot,xlab.top=title,at=at,col.regions=bgyr(length(at)))+layer(sp.lines(roil, lwd=0.8, col='black'))
|
144 |
188 |
print(p)
|
145 |
|
bwplot(cot,xlab.top=title,ylab="Cloud Optical Thickness (%)")
|
|
189 |
#bwplot(cot,xlab.top=title,ylab="Cloud Optical Thickness (%)")
|
|
190 |
|
|
191 |
###########################################
|
|
192 |
#### compare with PRISM data
|
|
193 |
|
|
194 |
at=quantile(as.matrix(subset(m01,subset=1)),seq(0,1,len=100),na.rm=T)
|
|
195 |
p1=levelplot(subset(m01,subset=1),xlab.top="Effective Radius (um)",at=at,col.regions=bgyr(length(at)),margin=F,
|
|
196 |
)+layer(sp.lines(roi_geo, lwd=1.2, col='black'))
|
|
197 |
at=quantile(as.matrix(subset(m01,subset=2)),seq(0,1,len=100),na.rm=T)
|
|
198 |
p2=levelplot(subset(m01,subset=2),xlab.top="Cloudy days (%)",at=at,col.regions=bgyr(length(at)),margin=F,
|
|
199 |
)+layer(sp.lines(roi_geo, lwd=1.2, col='black'))
|
|
200 |
at=quantile(as.matrix(subset(m01,subset=3)),seq(0,1,len=100),na.rm=T)
|
|
201 |
p3=levelplot(subset(m01,subset=3),xlab.top="Optical Thickness (%)",at=at,col.regions=bgyr(length(at)),margin=F,
|
|
202 |
)+layer(sp.lines(roi_geo, lwd=1.2, col='black'))
|
|
203 |
at=quantile(as.matrix(subset(m01,subset=4)),seq(0,1,len=100),na.rm=T)
|
|
204 |
p4=levelplot(subset(m01,subset=4),xlab.top="PRISM MAP",at=at,col.regions=bgyr(length(at)),margin=F,
|
|
205 |
)+layer(sp.lines(roi_geo, lwd=1.2, col='black'))
|
|
206 |
|
|
207 |
print(p1,split=c(1,1,2,2))
|
|
208 |
print(p2,split=c(1,2,2,2),new=F)
|
|
209 |
print(p3,split=c(2,1,2,2),new=F)
|
|
210 |
print(p4,split=c(2,2,2,2),new=F)
|
|
211 |
|
|
212 |
### compare COT and PRISM
|
|
213 |
print(p3,split=c(1,1,2,1))
|
|
214 |
print(p4,split=c(2,1,2,1),new=F)
|
|
215 |
|
|
216 |
|
|
217 |
### sample to speed up processing
|
|
218 |
s=sample(1:nrow(bd),10000)
|
|
219 |
|
|
220 |
## melt it to ease comparisons
|
|
221 |
bdl=melt(bd[s,],measure.vars=c("cer","cld","cot"))
|
|
222 |
|
|
223 |
combineLimits(useOuterStrips(xyplot(prism~value|variable+month,data=bdl,pch=16,cex=.2,scales=list(y=list(log=T),x=list(relation="free")),
|
|
224 |
ylab="PRISM Monthly mean precipitation (mm)",xlab="MOD06 metric",main="PRISM vs. MOD06 (mean monthly ppt)")))+
|
|
225 |
layer(panel.abline(lm(y~x),col="red"))+
|
|
226 |
layer(panel.text(0,2.5,paste("R2=",round(summary(lm(y~x))$r.squared,2))))
|
146 |
227 |
|
147 |
228 |
|
148 |
229 |
### Comparison at station values
|
149 |
230 |
at=quantile(as.matrix(cotm),seq(0,1,len=100),na.rm=T)
|
150 |
231 |
p=levelplot(cotm, layers=1,at=at,col.regions=bgyr(length(at)),main="Mean Annual Cloud Optical Thickness",FUN.margin=function(x) 0)+
|
151 |
|
layer(sp.lines(roil, lwd=1.2, col='black'))+layer(sp.points(st2, pch=16, col='black'))
|
|
232 |
layer(sp.lines(roil, lwd=1.2, col='black'))+layer(sp.points(st2_sin, pch=16, col='black'))
|
152 |
233 |
print(p)
|
153 |
234 |
|
154 |
235 |
### monthly comparisons of variables
|
155 |
236 |
mod06sl=melt(mod06s,measure.vars=c("value","COT_mean","CER_mean"))
|
156 |
237 |
bwplot(value~month|variable,data=mod06sl,cex=.5,pch=16,col="black",scales=list(y=list(relation="free")),layout=c(1,3))
|
157 |
|
splom(mod06s[grep("CER|COT|CLD",colnames(mod06s))],cex=.2,pch=16)
|
|
238 |
splom(mod06s[grep("CER|COT|CLD",colnames(mod06s))],cex=.2,pch=16,main="Scatterplot matrix of MOD06 products")
|
158 |
239 |
|
159 |
240 |
### run some regressions
|
160 |
|
summary(lm(log(ppt)~CER_mean*month,data=mod06s))
|
161 |
|
|
162 |
|
xyplot(ppt~CLD_mean,data=mod06s,cex=.5,pch=16,col="black",scales=list(y=list(log=F)),main="Comparison of monthly mean CLD and precipitation",ylab="Precipitation (log axis)",xlab="% Days Cloudy")
|
163 |
|
xyplot(ppt~CER_mean,data=mod06s,cex=.5,pch=16,col="black",scales=list(y=list(log=T)),main="Comparison of monthly mean CER and precipitation",ylab="Precipitation (log axis)")
|
164 |
|
xyplot(ppt~COT_mean,data=mod06s,cex=.5,pch=16,col="black",scales=list(y=list(log=T)),main="Comparison of monthly mean COT and precipitation",ylab="Precipitation (log axis)")
|
|
241 |
#plot(log(ppt)~COT_mean,data=mod06s)
|
|
242 |
#summary(lm(log(ppt)~COT_mean*month,data=mod06s))
|
|
243 |
|
|
244 |
## ppt~metric with longitude bins
|
|
245 |
xyplot(ppt~value|variable,groups=glon,data=mod06sl,
|
|
246 |
scales=list(y=list(log=T),x=list(relation="free")),
|
|
247 |
par.settings = list(superpose.symbol = list(col=bgyr(5),pch=16,cex=.5)),auto.key=list(space="right",title="Station Longitude"),
|
|
248 |
main="Comparison of MOD06_L2 and Precipitation Monthly Climatologies",ylab="Precipitation",xlab="MOD06_L2 Product",layout=c(3,1))+
|
|
249 |
layer(panel.text(9,2.5,label="Coastal stations",srt=30,cex=1.3,col="blue"),columns=1)+
|
|
250 |
layer(panel.text(13,.9,label="Inland stations",srt=10,cex=1.3,col="red"),columns=1)
|
|
251 |
|
|
252 |
## with elevation
|
|
253 |
# xyplot(ppt~value|variable,groups=gbin,data=mod06sl,
|
|
254 |
# scales=list(y=list(log=T),x=list(relation="free")),
|
|
255 |
# par.settings = list(superpose.symbol = list(col=c(rep("blue",3),rep("red",3)),pch=rep(c(3,4,8),2),cex=.5)),auto.key=list(space="right",title="Station Longitude"),
|
|
256 |
# main="Comparison of MOD06_L2 and Precipitation Monthly Climatologies",ylab="Precipitation",xlab="MOD06_L2 Product",layout=c(3,1))+
|
|
257 |
# layer(panel.text(9,2.5,label="Coastal stations",srt=30,cex=1.3,col="blue"),columns=1)+
|
|
258 |
# layer(panel.text(13,.9,label="Inland stations",srt=10,cex=1.3,col="red"),columns=1)
|
|
259 |
|
|
260 |
## with elevation and longitude bins
|
|
261 |
combineLimits(useOuterStrips(xyplot(ppt~value|variable+gbin,data=mod06sl,
|
|
262 |
scales=list(y=list(log=T),x=list(relation="free")),col="black",pch=16,cex=.5,type=c("p","r"),
|
|
263 |
main="Comparison of MOD06_L2 and Precipitation Monthly Climatologies",ylab="Precipitation",xlab="MOD06_L2 Product")))+
|
|
264 |
layer(panel.xyplot(x,y,type="r",col="red"))
|
|
265 |
|
|
266 |
## *** MOD06 vars vs precipitation by month, colored by longitude
|
|
267 |
combineLimits(useOuterStrips(xyplot(ppt~value|month+variable,groups=glon,data=mod06sl,cex=.5,pch=16,
|
|
268 |
scales=list(y=list(log=T),x=list(relation="free")),
|
|
269 |
par.settings = list(superpose.symbol = list(pch =16, col=bgyr(5),cex=1)),auto.key=list(space="top",title="Station Longitude"),
|
|
270 |
main="Comparison of MOD06_L2 and Precipitation Monthly Climatologies",ylab="Precipitation",xlab="MOD06_L2 Product")),
|
|
271 |
margin.x=1,adjust.labels=F)+
|
|
272 |
layer(panel.abline(lm(y~x),col="red"))+
|
|
273 |
layer(panel.text(0,0,paste("R2=",round(summary(lm(y~x))$r.squared,2)),pos=4,cex=.5,col="grey"))
|
|
274 |
|
|
275 |
|
|
276 |
xyplot(ppt~CLD_mean|id,data=mod06s,panel=function(x,y,group){
|
|
277 |
panel.xyplot(x,y,type=c("r"),cex=.5,pch=16,col="red")
|
|
278 |
panel.xyplot(x,y,type=c("p"),cex=.5,pch=16,col="black")
|
|
279 |
} ,scales=list(y=list(log=T)),strip=F,main="Monthly Mean Precipitation and % Cloudy by station",
|
|
280 |
sub="Each panel is a station, each point is a monthly mean",
|
|
281 |
ylab="Precipitation (mm, log axis)",xlab="% of Cloudy Days")+
|
|
282 |
layer(panel.text(.5,.5,round(summary(lm(y~x))$r.squared,2),pos=4,cex=.75,col="grey"))
|
165 |
283 |
|
166 |
|
xyplot(ppt~CER_mean|month,data=mod06s,cex=.5,pch=16,col="black",scales=list(log=T,relation="free"))
|
167 |
|
xyplot(ppt~COT_mean|month,data=mod06s,cex=.5,pch=16,col="black",scales=list(log=T,relation="free"))
|
|
284 |
xyplot(ppt~CER_mean|id,data=mod06s,panel=function(x,y,group){
|
|
285 |
panel.xyplot(x,y,type=c("r"),cex=.5,pch=16,col="red")
|
|
286 |
panel.xyplot(x,y,type=c("p"),cex=.5,pch=16,col="black")
|
|
287 |
} ,scales=list(y=list(log=T)),strip=F,main="Monthly Mean Precipitation and Cloud Effective Radius by station",sub="Each panel is a station, each point is a monthly mean",ylab="Precipitation (mm, log axis)",xlab="Mean Monthly Cloud Effective Radius (mm)")+
|
|
288 |
layer(panel.text(10,.5,round(summary(lm(y~x))$r.squared,2),pos=4,cex=.75,col="grey"))
|
168 |
289 |
|
169 |
290 |
xyplot(ppt~COT_mean|id,data=mod06s,panel=function(x,y,group){
|
170 |
291 |
panel.xyplot(x,y,type=c("r"),cex=.5,pch=16,col="red")
|
171 |
292 |
panel.xyplot(x,y,type=c("p"),cex=.5,pch=16,col="black")
|
172 |
|
} ,scales=list(y=list(log=T)),strip=F,main="Monthly Mean Precipitation and Cloud Optical Thickness by station",sub="Each panel is a station, each point is a monthly mean",ylab="Precipitation (mm, log axis)",xlab="Mean Monthly Cloud Optical Thickness")
|
|
293 |
} ,scales=list(y=list(log=T)),strip=F,main="Monthly Mean Precipitation and Cloud Optical Thickness by station",
|
|
294 |
sub="Each panel is a station, each point is a monthly mean \n Number in lower right of each panel is R^2",
|
|
295 |
ylab="Precipitation (mm, log axis)",xlab="Mean Monthly Cloud Optical Thickness (%)")+
|
|
296 |
layer(panel.text(10,.5,round(summary(lm(y~x))$r.squared,2),pos=4,cex=.75,col="grey"))
|
173 |
297 |
|
174 |
|
### Calculate the slope of each line and plot it on a map
|
|
298 |
|
|
299 |
### Calculate the slope of each line
|
175 |
300 |
mod06s.sl=dapply(mod06s,list(id=mod06s$id),function(x){
|
176 |
301 |
lm1=lm(log(x$ppt)~x$CER_mean,)
|
177 |
|
data.frame(lat=x$lat[1],lon=x$lon[1],intcpt=coefficients(lm1)[1],cer=coefficients(lm1)[2],r2=summary(lm1)$r.squared)
|
|
302 |
data.frame(lat=x$lat[1],lon=x$lon[1],elev=x$elev[1],intcpt=coefficients(lm1)[1],cer=coefficients(lm1)[2],r2=summary(lm1)$r.squared)
|
178 |
303 |
})
|
179 |
304 |
mod06s.sl$cex=gq(mod06s.sl$r2,n=5,cut=T)
|
180 |
305 |
mod06s.sl$cer.s=gq(mod06s.sl$cer,n=5,cut=T)
|
181 |
306 |
|
|
307 |
### and plot it on a map
|
182 |
308 |
xyplot(lat~lon,group=cer.s,data=mod06s.sl,par.settings = list(superpose.symbol = list(pch =16, col=bgyr(5),cex=1)),auto.key=list(space="right",title="Slope Coefficient"),asp=1,
|
183 |
309 |
main="Slopes of linear regressions {log(ppt)~CloudEffectiveRadius}")+
|
184 |
310 |
layer(sp.lines(roi_geo, lwd=1.2, col='black'))
|
185 |
311 |
|
|
312 |
### look for relationships with longitude
|
|
313 |
xyplot(cer~lon,group=cut(mod06s.sl$elev,gq(mod06s.sl$elev,n=5)),data=mod06s.sl,
|
|
314 |
par.settings = list(superpose.symbol = list(col=bgyr(5),pch=16,cex=1)),auto.key=list(space="right",title="Station Elevation"),
|
|
315 |
ylab="Slope of lm(ppt~EffectiveRadius)",xlab="Longitude",main="Precipitation~Effective Radius relationship by latitude")
|
|
316 |
|
186 |
317 |
|
187 |
318 |
############################################################
|
188 |
319 |
### simple regression to get spatial residuals
|
189 |
320 |
m="01"
|
190 |
321 |
mod06s2=mod06s#[mod06s$month==m,]
|
191 |
322 |
|
192 |
|
lm1=lm(ppt~CER_mean*month,data=mod06s2)
|
193 |
|
summary(lm1)
|
194 |
|
mod06s2$pred=predict(lm1,mod06s2)
|
|
323 |
lm1=lm(log(ppt)~CER_mean*month*lon,data=mod06s2); summary(lm1)
|
|
324 |
mod06s2$pred=exp(predict(lm1,mod06s2))
|
195 |
325 |
mod06s2$resid=mod06s2$pred-mod06s2$ppt
|
196 |
|
|
197 |
|
mod06sr=cast(mod06s2,id+lon+lat~month,value="resid",fun=function(x) mean(x,na.rm=T))
|
198 |
|
mod06sr=melt(mod06sr,id.vars=c("id","lon","lat"),value="resid")
|
199 |
|
mod06sr$residg=cut(mod06sr$value,quantile(mod06sr$value,seq(0,1,len=11),na.rm=T))
|
200 |
|
|
201 |
|
xyplot(lat~lon|month,group=residg,data=mod06sr,
|
202 |
|
par.settings = list(superpose.symbol = list(pch =16, col=terrain.colors(10),cex=.5)),
|
203 |
|
auto.key=T)
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
plot(pred~value,data=mod06s,log="xy")
|
208 |
|
|
|
326 |
mod06s2$residg=gq(mod06s2$resid,n=5,cut=T)
|
|
327 |
mod06s2$presid=mod06s2$resid/mod06s2$ppt
|
|
328 |
|
|
329 |
for(l in c(F,T)){
|
|
330 |
## all months
|
|
331 |
xyplot(pred~ppt,groups=gelev,data=mod06s2,
|
|
332 |
par.settings = list(superpose.symbol = list(col=bgyr(3),pch=16,cex=.75)),auto.key=list(space="right",title="Station Elevation"),
|
|
333 |
scales=list(log=l),
|
|
334 |
ylab="Predicted Mean Monthly Precipitation (mm)",xlab="Observed Mean Monthly Precipitation (mm)",main="Predicted vs. Observed for Simple Model",
|
|
335 |
sub="Red line is y=x")+
|
|
336 |
layer(panel.abline(0,1,col="red"))
|
|
337 |
|
|
338 |
## month by month
|
|
339 |
print(xyplot(pred~ppt|month,groups=gelev,data=mod06s2,
|
|
340 |
par.settings = list(superpose.symbol = list(col=bgyr(3),pch=16,cex=.75)),auto.key=list(space="right",title="Station Elevation"),
|
|
341 |
scales=list(log=l),
|
|
342 |
ylab="Predicted Mean Monthly Precipitation (mm)",xlab="Observed Mean Monthly Precipitation (mm)",main="Predicted vs. Observed for Simple Model",
|
|
343 |
sub="Red line is y=x")+
|
|
344 |
layer(panel.abline(0,1,col="red"))
|
|
345 |
)}
|
|
346 |
|
|
347 |
## residuals by month
|
|
348 |
xyplot(lat~lon|month,group=residg,data=mod06s2,
|
|
349 |
par.settings = list(superpose.symbol = list(pch =16, col=bgyr(5),cex=.5)),
|
|
350 |
auto.key=list(space="right",title="Residuals"),
|
|
351 |
main="Spatial plot of monthly residuals")+
|
|
352 |
layer(sp.lines(roi_geo, lwd=1.2, col='black'))
|
209 |
353 |
|
210 |
354 |
|
211 |
355 |
dev.off()
|
212 |
356 |
|
213 |
357 |
|
|
358 |
####################################
|
|
359 |
#### build table comparing various metrics
|
|
360 |
mods=data.frame(
|
|
361 |
models=c(
|
|
362 |
"log(ppt)~CER_mean",
|
|
363 |
"log(ppt)~CLD_mean",
|
|
364 |
"log(ppt)~COT_mean",
|
|
365 |
"log(ppt)~CER_mean*month",
|
|
366 |
"log(ppt)~CLD_mean*month",
|
|
367 |
"log(ppt)~COT_mean*month",
|
|
368 |
"log(ppt)~CER_mean*month*lon",
|
|
369 |
"log(ppt)~CLD_mean*month*lon",
|
|
370 |
"log(ppt)~COT_mean*month*lon",
|
|
371 |
"ppt~CER_mean*month*lon",
|
|
372 |
"ppt~CLD_mean*month*lon",
|
|
373 |
"ppt~COT_mean*month*lon"),stringsAsFactors=F)
|
|
374 |
|
|
375 |
mods$r2=
|
|
376 |
do.call(rbind,lapply(1:nrow(mods),function(i){
|
|
377 |
lm1=lm(as.formula(mods$models[i]),data=mod06s2)
|
|
378 |
summary(lm1)$r.squared}))
|
214 |
379 |
|
215 |
|
|
|
380 |
mods
|
216 |
381 |
|
217 |
382 |
|
218 |
383 |
|
... | ... | |
229 |
394 |
dsl=dsl[!is.nan(dsl$value),]
|
230 |
395 |
|
231 |
396 |
|
232 |
|
summary(lm(ppt~Cloud_Effective_Radius,data=ds))
|
233 |
|
summary(lm(ppt~Cloud_Water_Path,data=ds))
|
234 |
|
summary(lm(ppt~Cloud_Optical_Thickness,data=ds))
|
235 |
|
summary(lm(ppt~Cloud_Effective_Radius+Cloud_Water_Path+Cloud_Optical_Thickness,data=ds))
|
236 |
397 |
|
237 |
398 |
|
238 |
399 |
####
|
Added PRISM comparison to MOD06_summary and added script to calculate 'back-of-the-envelope' estimates of total daily climate layer sizes