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