1 |
f5ef0596
|
Adam M. Wilson
|
### Figures and tables for MOD09 Cloud Manuscript
|
2 |
|
|
|
3 |
|
|
setwd("~/acrobates/adamw/projects/cloud/")
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
## libraries
|
7 |
|
|
library(rasterVis)
|
8 |
|
|
library(latticeExtra)
|
9 |
|
|
library(xtable)
|
10 |
|
|
library(reshape)
|
11 |
|
|
library(caTools)
|
12 |
|
|
|
13 |
|
|
## read in data
|
14 |
|
|
cld=read.csv("data/NDP026D/cld.csv")
|
15 |
|
|
cldm=read.csv("data/NDP026D/cldm.csv")
|
16 |
|
|
cldy=read.csv("data/NDP026D/cldy.csv")
|
17 |
|
|
clda=read.csv("data/NDP026D/clda.csv")
|
18 |
|
|
st=read.csv("data/NDP026D/stations.csv")
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
## add lulc factor information
|
22 |
|
|
require(plotKML); data(worldgrids_pal) #load IGBP palette
|
23 |
|
|
IGBP=data.frame(ID=0:16,col=worldgrids_pal$IGBP[-c(18,19)],stringsAsFactors=F)
|
24 |
|
|
IGBP$class=rownames(IGBP);rownames(IGBP)=1:nrow(IGBP)
|
25 |
|
|
|
26 |
|
|
## month factors
|
27 |
|
|
cld$month2=factor(cld$month,labels=month.name)
|
28 |
|
|
cldm$month2=factor(cldm$month,labels=month.name)
|
29 |
|
|
|
30 |
|
|
coordinates(st)=c("lon","lat")
|
31 |
|
|
projection(st)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
|
32 |
|
|
|
33 |
|
|
##make spatial object
|
34 |
|
|
cldms=cldm
|
35 |
|
|
coordinates(cldms)=c("lon","lat")
|
36 |
|
|
projection(cldms)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
|
37 |
|
|
|
38 |
|
|
##make spatial object
|
39 |
|
|
cldys=cldy
|
40 |
|
|
coordinates(cldys)=c("lon","lat")
|
41 |
|
|
projection(cldys)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
|
42 |
|
|
|
43 |
|
|
#### Evaluate MOD35 Cloud data
|
44 |
|
|
mod09=brick("data/mod09.nc")
|
45 |
|
|
mod09c=brick("data/mod09_clim_mean.nc",varname="CF");names(mod09c)=month.name
|
46 |
|
|
mod09a=brick("data/mod09_clim_mac.nc",varname="CF_annual")#;names(mod09c)=month.name
|
47 |
|
|
|
48 |
|
|
mod09min=raster("data/mod09_metrics.nc",varname="CFmin")
|
49 |
|
|
mod09max=raster("data/mod09_metrics.nc",varname="CFmax")
|
50 |
|
|
mod09sd=raster("data/mod09_metrics.nc",varname="CFsd")
|
51 |
|
|
mod09mean=raster("data/mod09_clim_mac.nc")
|
52 |
|
|
|
53 |
|
|
names(mod09d)=c("Mean","Minimum","Maximum","Standard Deviation")
|
54 |
|
|
|
55 |
ba7057c4
|
Adam M. Wilson
|
#plot(mod09a,layers=1,margin=F,maxpixels=100)
|
56 |
f5ef0596
|
Adam M. Wilson
|
|
57 |
|
|
## calculated differences
|
58 |
|
|
cldm$dif=cldm$mod09-cldm$cld
|
59 |
|
|
clda$dif=clda$mod09-clda$cld
|
60 |
|
|
|
61 |
|
|
## read in global coasts for nice plotting
|
62 |
|
|
library(maptools)
|
63 |
|
|
|
64 |
|
|
data(wrld_simpl)
|
65 |
|
|
coast <- unionSpatialPolygons(wrld_simpl, rep("land",nrow(wrld_simpl)), threshold=5)
|
66 |
|
|
coast=as(coast,"SpatialLines")
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
## Figures
|
70 |
|
|
n=100
|
71 |
|
|
at=seq(0,100,length=n)
|
72 |
|
|
colr=colorRampPalette(c("black","green","red"))
|
73 |
|
|
cols=colr(n)
|
74 |
|
|
|
75 |
|
|
|
76 |
ba7057c4
|
Adam M. Wilson
|
pdf("output/Figures.pdf",width=11,height=8.5)
|
77 |
f5ef0596
|
Adam M. Wilson
|
|
78 |
ba7057c4
|
Adam M. Wilson
|
## Figure 1: 4-panel summaries
|
79 |
f5ef0596
|
Adam M. Wilson
|
#- Annual average
|
80 |
|
|
levelplot(mod09a,col.regions=colr(100),cuts=100,at=seq(0,100,len=100),colorkey=list(space="bottom",adj=1),
|
81 |
|
|
margin=F,maxpixels=1e6,ylab="Latitude",xlab="Longitude",useRaster=T)+
|
82 |
|
|
layer(sp.lines(coast,col="black"),under=F)
|
83 |
|
|
#- Monthly minimum
|
84 |
|
|
#- Monthly maximum
|
85 |
|
|
#- STDEV or Min-Max
|
86 |
ba7057c4
|
Adam M. Wilson
|
p_mac=levelplot(mac,col.regions=grey(seq(0,1,len=100)),cuts=99,margin=F,maxpixels=1e5,colorkey=list(space="bottom",height=.75),xlab="",ylab="",main=names(regs)[r],useRaster=T)
|
87 |
|
|
p_min=levelplot(mod09min,col.regions=grey(seq(0,1,len=100)),cuts=99,margin=F,maxpixels=1e5,colorkey=list(space="bottom",height=.75),useRaster=T)
|
88 |
|
|
p_max=levelplot(mod09max,col.regions=grey(seq(0,1,len=100)),cuts=99,margin=F,maxpixels=1e5,colorkey=list(space="bottom",height=.75),useRaster=T)
|
89 |
|
|
p_sd=levelplot(mod09sd,col.regions=grey(seq(0,1,len=100)),cuts=99,margin=F,maxpixels=1e5,colorkey=list(space="bottom",height=.75),useRaster=T)
|
90 |
|
|
p3=c("Mean Cloud Frequency (%)"=p_mac,"Max Cloud Frequency (%)"=p_max,"Min Cloud Frequency (%)"=p_min,"Cloud Frequency Variability (SD)"=p_sd,x.same=T,y.same=T,merge.legends=T,layout=c(2,2))
|
91 |
|
|
print(p3)
|
92 |
f5ef0596
|
Adam M. Wilson
|
|
93 |
|
|
|
94 |
|
|
### maps of mod09 and NDP
|
95 |
|
|
## map of stations
|
96 |
|
|
p_mac=levelplot(mod09a,col.regions=colr(100),cuts=100,at=seq(0,100,len=100),colorkey=list(space="bottom",adj=1),
|
97 |
|
|
margin=F,maxpixels=1e6,ylab="Latitude",xlab="Longitude",useRaster=T)+
|
98 |
|
|
layer(panel.xyplot(lon,lat,pch=16,cex=.3,col="black"),data=data.frame(coordinates(st)))+
|
99 |
|
|
layer(sp.lines(coast,col="black"),under=F)
|
100 |
|
|
|
101 |
|
|
p_mace=xyplot(lat~dif,data=cldm[cldm$lat>-60,],panel=function(x,y,subscripts=T){
|
102 |
|
|
x2=x[order(y)]
|
103 |
|
|
y2=y[order(y)]
|
104 |
|
|
win=8000
|
105 |
|
|
Q50=runquantile(x2,win,probs=c(.25,.5,.75))
|
106 |
|
|
## polygon
|
107 |
|
|
panel.polygon(c(Q50[,1],rev(Q50[,3])),c(y2,rev(y2)),type="l",col=grey(.8))
|
108 |
|
|
### hist
|
109 |
|
|
n=150
|
110 |
|
|
xbins=seq(-70,50,len=n)
|
111 |
|
|
ybins=seq(-60,90,len=n)
|
112 |
|
|
tb=melt(as.matrix(table(
|
113 |
|
|
x=cut(x,xbins,labels=xbins[-1]),
|
114 |
|
|
y=cut(y,ybins,labels=ybins[-1]))))
|
115 |
|
|
qat=unique(tb$value)
|
116 |
|
|
print(qat)
|
117 |
|
|
panel.levelplot(tb$x,tb$y,tb$value,at=qat,col.regions=c("transparent",hmcols(length(qat))),subscripts=1:nrow(tb))
|
118 |
|
|
###
|
119 |
|
|
# panel.xyplot(x,y,pch=16,cex=.1,col=)
|
120 |
|
|
# cuts=cut(y,lats,labels=lats[-10])
|
121 |
|
|
# qs=do.call(rbind,tapply(x,cuts,quantile,c(.25,.50,.75),na.rm=T))
|
122 |
|
|
colnames(qs)=c("Q25","Q50","Q75")
|
123 |
|
|
panel.lines(Q50[,1],y2,type="l",col=grey(.5))
|
124 |
|
|
panel.lines(Q50[,2],y2,type="l",col="black")
|
125 |
|
|
panel.lines(Q50[,3],y2,type="l",col=grey(.5))
|
126 |
|
|
},asp=1,xlab="Difference (MOD09-Observed)")+layer(panel.abline(v=0,lty="dashed",col="red"))
|
127 |
|
|
|
128 |
|
|
print(p_mac,position=c(0,0,.75,1),more=T)
|
129 |
|
|
print(p_mace,position=c(0.75,0,1,1))
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
p1=c("MODIS Cloud Frequency and NDP-026D Validation Stations"=p_mac,"Difference (MOD09-NDP026D)"=p_mace,x.same=F,y.same=T,layout=c(2,1))
|
133 |
|
|
resizePanels(p1,w=c(.75,.25))
|
134 |
|
|
|
135 |
|
|
quantile(cldm$dif,seq(0,1,len=6),na.rm=T)
|
136 |
|
|
at=c(-70,-50,-25,-10,-5,0,5,10,25,50,70)
|
137 |
|
|
bwr=colorRampPalette(c("blue","grey","red"))
|
138 |
|
|
xyplot(lat~lon|month2,data=cldm,groups=cut(cldm$dif,at),
|
139 |
|
|
par.settings=list(superpose.symbol=list(col=bwr(length(at)-1))),pch=16,cex=.25,
|
140 |
|
|
auto.key=list(space="right",title="Difference\n(MOD09-NDP026D)",cex.title=1),asp=1,
|
141 |
|
|
main="NDP-026D Cloud Climatology Stations",ylab="Latitude",xlab="Longitude")+
|
142 |
|
|
layer(sp.lines(coast,col="black",lwd=.1),under=F)
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
### heatmap of mod09 vs. NDP for all months
|
147 |
|
|
hmcols=colorRampPalette(c("grey","blue","red"))
|
148 |
|
|
#hmcols=colorRampPalette(c(grey(.8),grey(.3),grey(.2)))
|
149 |
|
|
tr=c(0,120)
|
150 |
|
|
colkey <- draw.colorkey(list(col = hmcols(tr[2]), at = tr[1]:tr[2],height=.25))
|
151 |
|
|
|
152 |
|
|
xyplot(cld~mod09,data=cld[cld$Nobs>10,],panel=function(x,y,subscripts){
|
153 |
|
|
n=150
|
154 |
|
|
bins=seq(0,100,len=n)
|
155 |
|
|
tb=melt(as.matrix(table(
|
156 |
|
|
x=cut(x,bins,labels=bins[-1]),
|
157 |
|
|
y=cut(y,bins,labels=bins[-1]))))
|
158 |
|
|
qat=tr[1]:tr[2]#unique(tb$value)
|
159 |
|
|
print(qat)
|
160 |
|
|
panel.levelplot(tb$x,tb$y,tb$value,at=qat,col.regions=c("transparent",hmcols(length(qat))),subscripts=subscripts)
|
161 |
|
|
},asp=1,scales=list(at=seq(0,100,len=6)),ylab="NDP Mean Cloud Amount (%)",xlab="MOD09 Cloud Frequency (%)",
|
162 |
|
|
legend= list(right = list(fun = colkey,title="Station Count")))+
|
163 |
|
|
layer(panel.abline(0,1,col="black",lwd=2))
|
164 |
|
|
# layer(panel.ablineq(lm(y ~ x), r.sq = TRUE,at = 0.6,pos=1, offset=22,digits=2,col="blue"), style = 1)
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
xyplot(cld~mod09|month2,data=cld[cld$Nobs>50,],panel=function(x,y,subscripts){
|
168 |
|
|
n=50
|
169 |
|
|
bins=seq(0,100,len=n)
|
170 |
|
|
tb=melt(as.matrix(table(
|
171 |
|
|
x=cut(x,bins,labels=bins[-1]),
|
172 |
|
|
y=cut(y,bins,labels=bins[-1]))))
|
173 |
|
|
qat=unique(tb$value)
|
174 |
|
|
qat=0:78
|
175 |
|
|
qat=tr[1]:tr[2]#unique(tb$value)
|
176 |
|
|
panel.levelplot(tb$x,tb$y,tb$value,at=qat,col.regions=c("transparent",hmcols(length(qat))),subscripts=1:nrow(tb))
|
177 |
|
|
panel.abline(0,1,col="black",lwd=2)
|
178 |
|
|
# panel.ablineq(lm(y ~ x), r.sq = TRUE,at = 0.6,pos=1, offset=0,digits=2,col="blue")
|
179 |
|
|
panel.text(70,10,bquote(paste(R^2,"=",.(round(summary(lm(y ~ x))$r.squared,2)))),cex=1.2)
|
180 |
|
|
},asp=1,scales=list(at=seq(0,100,len=6),useRaster=T,colorkey=list(width=.5,title="Number of Stations")),
|
181 |
|
|
ylab="NDP Mean Cloud Amount (%)",xlab="MOD09 Cloud Frequency (%)",
|
182 |
|
|
legend= list(right = list(fun = colkey)))+ layer(panel.abline(0,1,col="black",lwd=2))
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
## Monthly Climatologies
|
186 |
|
|
for(i in 1:2){
|
187 |
|
|
p1=xyplot(cld~mod09|month2,data=cldm,cex=.2,pch=16,subscripts=T,ylab="NDP Mean Cloud Amount",xlab="MOD09 Cloud Frequency (%)")+
|
188 |
|
|
layer(panel.lines(1:100,predict(lm(y~x),newdata=data.frame(x=1:100)),col="green"))+
|
189 |
|
|
layer(panel.lines(1:100,predict(lm(y~x+I(x^2)),newdata=data.frame(x=1:100)),col="blue"))+
|
190 |
|
|
layer(panel.abline(0,1,col="red"))
|
191 |
|
|
if(i==2){
|
192 |
|
|
p1=p1+layer(panel.segments(mod09[subscripts],cld[subscripts]-cldsd[subscripts],mod09[subscripts],cld[subscripts]+cldsd[subscripts],subscripts=subscripts,col="grey"),data=cldm,under=T,magicdots=T)
|
193 |
|
|
p1=p1+layer(panel.segments(mod09[subscripts]-mod09sd[subscripts],cld[subscripts],mod09[subscripts]+mod09sd[subscripts],cld[subscripts],subscripts=subscripts,col="grey"),data=cldm,under=T,magicdots=T)
|
194 |
|
|
}
|
195 |
|
|
print(p1)
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
bwplot(lulcc~dif,data=cldm,horiz=T,xlab="Difference (MOD09-Observed)",varwidth=T,notch=T)+layer(panel.abline(v=0))
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
dev.off()
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
summary(lm(cld~mod09,data=cld))
|
205 |
|
|
|
206 |
|
|
## explore validation error
|
207 |
|
|
cldm$lulcc=as.factor(IGBP$class[match(cldm$lulc,IGBP$ID)])
|
208 |
|
|
|
209 |
|
|
## Table of RMSE's by lulc by month
|
210 |
|
|
lulcrmsel=ddply(cldm,c("month","lulc"),function(x) c(count=nrow(x),rmse=sqrt(mean((x$mod09-x$cld)^2,na.rm=T))))
|
211 |
|
|
lulcrmsel=lulcrmsel[!is.na(lulcrmsel$lulc),]
|
212 |
|
|
lulcrmsel$lulcc=as.factor(IGBP$class[match(lulcrmsel$lulc,IGBP$ID)])
|
213 |
|
|
|
214 |
|
|
lulcrmse=cast(lulcrmsel,lulcc~month,value="rmse")
|
215 |
|
|
lulcrmse
|
216 |
|
|
print(xtable(lulcrmse,digits=1),"html")
|
217 |
|
|
|
218 |
|
|
levelplot(rmse~lulc*month,data=lulcrmsel,col.regions=heat.colors(20))
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
### Linear models
|
222 |
|
|
summary(lm(dif~as.factor(lulc)+lat+month2,data=cldm))
|