1 |
ddd9a810
|
Adam M. Wilson
|
## Figures associated with MOD35 Cloud Mask Exploration
|
2 |
|
|
|
3 |
|
|
setwd("~/acrobates/adamw/projects/MOD35C5")
|
4 |
|
|
|
5 |
|
|
library(raster);beginCluster(10)
|
6 |
|
|
library(rasterVis)
|
7 |
|
|
library(rgdal)
|
8 |
|
|
library(plotKML)
|
9 |
|
|
library(Cairo)
|
10 |
|
|
library(reshape)
|
11 |
be7b1081
|
Adam M. Wilson
|
library(rgeos)
|
12 |
ddd9a810
|
Adam M. Wilson
|
|
13 |
be7b1081
|
Adam M. Wilson
|
## get % cloudy
|
14 |
|
|
mod09=raster("data/MOD09_2009.tif")
|
15 |
|
|
names(mod09)="MOD09CF"
|
16 |
|
|
NAvalue(mod09)=0
|
17 |
|
|
|
18 |
|
|
mod35c5=raster("data/MOD35_2009.tif")
|
19 |
|
|
names(mod35c5)="C5MOD35CF"
|
20 |
|
|
NAvalue(mod35c5)=0
|
21 |
|
|
|
22 |
|
|
## mod35C6 annual
|
23 |
a57c4e3d
|
Adam M. Wilson
|
if(!file.exists("data/MOD35C6_2009.tif")){
|
24 |
|
|
system("/usr/local/gdal-1.10.0/bin/gdalbuildvrt -a_srs '+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs' -sd 1 -b 1 data/MOD35C6.vrt /home/adamw/acrobates/adamw/projects/interp/data/modis/mod35/summary/*2009mean.nc ")
|
25 |
|
|
system("align.sh data/MOD35C6.vrt data/MOD09_2009.tif data/MOD35C6_2009.tif")
|
26 |
|
|
}
|
27 |
be7b1081
|
Adam M. Wilson
|
mod35c6=raster("data/MOD35C6_2009.tif")
|
28 |
|
|
mod35c6=crop(mod35c6,mod09)
|
29 |
|
|
names(mod35c6)="C6MOD35CF"
|
30 |
|
|
NAvalue(mod35c6)=255
|
31 |
|
|
|
32 |
|
|
|
33 |
a57c4e3d
|
Adam M. Wilson
|
## landcover
|
34 |
|
|
if(!file.exists("data/MCD12Q1_IGBP_2009_v5_wgs84_1km.tif")){
|
35 |
|
|
system(paste("/usr/local/gdal-1.10.0/bin/gdalwarp -tr 0.008983153 0.008983153 -r mode -ot Byte -co \"COMPRESS=LZW\"",
|
36 |
|
|
" ~/acrobatesroot/jetzlab/Data/environ/global/landcover/MODIS/MCD12Q1_IGBP_2009_v5_wgs84.tif ",
|
37 |
|
|
" -t_srs \"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs\" ",
|
38 |
|
|
"data/MCD12Q1_IGBP_2009_v5_wgs84_1km.tif -overwrite ",sep=""))}
|
39 |
|
|
lulc=raster("data/MCD12Q1_IGBP_2009_v5_wgs84_1km.tif")
|
40 |
|
|
|
41 |
|
|
## read it in
|
42 |
|
|
lulc=raster("data/MCD12Q1_IGBP_2005_v51_1km_wgs84.tif")
|
43 |
|
|
# lulc=ratify(lulc)
|
44 |
|
|
data(worldgrids_pal) #load palette
|
45 |
|
|
IGBP=data.frame(ID=0:16,col=worldgrids_pal$IGBP[-c(18,19)],
|
46 |
|
|
lulc_levels2=c("Water","Forest","Forest","Forest","Forest","Forest","Shrublands","Shrublands","Savannas","Savannas","Grasslands","Permanent wetlands","Croplands","Urban and built-up","Cropland/Natural vegetation mosaic","Snow and ice","Barren or sparsely vegetated"),stringsAsFactors=F)
|
47 |
|
|
IGBP$class=rownames(IGBP);rownames(IGBP)=1:nrow(IGBP)
|
48 |
|
|
levels(lulc)=list(IGBP)
|
49 |
|
|
lulc=crop(lulc,mod09)
|
50 |
|
|
names(lulc)="MCD12Q1"
|
51 |
|
|
|
52 |
|
|
## make land mask
|
53 |
|
|
if(!file.exists("data/land.tif"))
|
54 |
|
|
land=calc(lulc,function(x) ifelse(x==0,NA,1),file="data/land.tif",options=c("COMPRESS=LZW","ZLEVEL=9","PREDICTOR=2"),datatype="INT1U",overwrite=T)
|
55 |
|
|
land=raster("data/land.tif")
|
56 |
|
|
|
57 |
be7b1081
|
Adam M. Wilson
|
|
58 |
|
|
## mask cloud masks to land pixels
|
59 |
|
|
#mod09l=mask(mod09,land)
|
60 |
|
|
#mod35l=mask(mod35,land)
|
61 |
|
|
|
62 |
ddd9a810
|
Adam M. Wilson
|
#####################################
|
63 |
|
|
### compare MOD43 and MOD17 products
|
64 |
|
|
|
65 |
|
|
## MOD17
|
66 |
|
|
#extent(mod17)=alignExtent(mod17,mod09)
|
67 |
a57c4e3d
|
Adam M. Wilson
|
if(!file.exists("data/MOD17.tif"))
|
68 |
|
|
system("align.sh ~/acrobates/adamw/projects/interp/data/modis/MOD17/MOD17A3_Science_NPP_mean_00_12.tif data/MOD09_2009.tif data/MOD17.tif")
|
69 |
|
|
mod17=raster("data/MOD17.tif",format="GTiff")
|
70 |
|
|
NAvalue(mod17)=65535
|
71 |
ddd9a810
|
Adam M. Wilson
|
mod17=crop(mod17,mod09)
|
72 |
|
|
names(mod17)="MOD17"
|
73 |
|
|
|
74 |
a57c4e3d
|
Adam M. Wilson
|
if(!file.exists("data/MOD17qc.tif"))
|
75 |
|
|
system("align.sh ~/acrobates/adamw/projects/interp/data/modis/MOD17/MOD17A3_Science_NPP_Qc_mean_00_12.tif data/MOD09_2009.tif data/MOD17qc.tif")
|
76 |
|
|
mod17qc=raster("data/MOD17qc.tif",format="GTiff")
|
77 |
ddd9a810
|
Adam M. Wilson
|
NAvalue(mod17qc)=255
|
78 |
|
|
mod17qc=crop(mod17qc,mod09)
|
79 |
be7b1081
|
Adam M. Wilson
|
names(mod17qc)="MOD17CF"
|
80 |
ddd9a810
|
Adam M. Wilson
|
|
81 |
|
|
## MOD11 via earth engine
|
82 |
a57c4e3d
|
Adam M. Wilson
|
if(!file.exists("data/MOD11_2009.tif"))
|
83 |
|
|
system("align.sh ~/acrobates/adamw/projects/interp/data/modis/mod11/2009/MOD11_LST_2009.tif data/MOD09_2009.tif data/MOD11_2009.tif")
|
84 |
|
|
mod11=raster("data/MOD11_2009.tif",format="GTiff")
|
85 |
ddd9a810
|
Adam M. Wilson
|
names(mod11)="MOD11"
|
86 |
be7b1081
|
Adam M. Wilson
|
NAvalue(mod11)=0
|
87 |
a57c4e3d
|
Adam M. Wilson
|
if(!file.exists("data/MOD11qc_2009.tif"))
|
88 |
|
|
system("align.sh ~/acrobates/adamw/projects/interp/data/modis/mod11/2009/MOD11_Pmiss_2009.tif data/MOD09_2009.tif data/MOD11qc_2009.tif")
|
89 |
|
|
mod11qc=raster("data/MOD11qc_2009.tif",format="GTiff")
|
90 |
|
|
mod11qc=crop(mod11qc,mod09)
|
91 |
be7b1081
|
Adam M. Wilson
|
names(mod11qc)="MOD11CF"
|
92 |
ddd9a810
|
Adam M. Wilson
|
|
93 |
|
|
|
94 |
|
|
### Create some summary objects for plotting
|
95 |
|
|
#difm=v6m-v5m
|
96 |
|
|
#v5v6compare=stack(v5m,v6m,difm)
|
97 |
|
|
#names(v5v6compare)=c("Collection 5","Collection 6","Difference (C6-C5)")
|
98 |
|
|
|
99 |
|
|
### Processing path
|
100 |
a57c4e3d
|
Adam M. Wilson
|
if(!file.exists("data/MOD35pp.tif"))
|
101 |
|
|
system("align.sh data/MOD35_ProcessPath.tif data/MOD09_2009.tif data/MOD35pp.tif")
|
102 |
|
|
pp=raster("data/MOD35pp.tif")
|
103 |
be7b1081
|
Adam M. Wilson
|
NAvalue(pp)=255
|
104 |
|
|
names(pp)="MOD35pp"
|
105 |
a57c4e3d
|
Adam M. Wilson
|
pp=crop(pp,mod09)
|
106 |
ddd9a810
|
Adam M. Wilson
|
|
107 |
|
|
## comparison of % cloudy days
|
108 |
be7b1081
|
Adam M. Wilson
|
dif_c5_09=mod35c5-mod09
|
109 |
|
|
dif_c6_09=mod35c6-mod09
|
110 |
|
|
dif_c5_c6=mod35c5-mod35c6
|
111 |
ddd9a810
|
Adam M. Wilson
|
|
112 |
be7b1081
|
Adam M. Wilson
|
#hist(dif,maxsamp=1000000)
|
113 |
|
|
## draw lulc-stratified random sample of mod35-mod09 differences
|
114 |
|
|
#samp=sampleStratified(lulc, 1000, exp=10)
|
115 |
|
|
#save(samp,file="LULC_StratifiedSample_10000.Rdata")
|
116 |
|
|
#mean(dif[samp],na.rm=T)
|
117 |
|
|
#Stats(dif,function(x) c(mean=mean(x),sd=sd(x)))
|
118 |
ddd9a810
|
Adam M. Wilson
|
|
119 |
|
|
|
120 |
|
|
###
|
121 |
|
|
|
122 |
|
|
n=100
|
123 |
|
|
at=seq(0,100,len=n)
|
124 |
|
|
cols=grey(seq(0,1,len=n))
|
125 |
|
|
cols=rainbow(n)
|
126 |
|
|
bgyr=colorRampPalette(c("blue","green","yellow","red"))
|
127 |
|
|
cols=bgyr(n)
|
128 |
|
|
|
129 |
|
|
#levelplot(lulcf,margin=F,layers="LULC")
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
### Transects
|
133 |
|
|
r1=Lines(list(
|
134 |
|
|
Line(matrix(c(
|
135 |
be7b1081
|
Adam M. Wilson
|
-61.688,4.098,
|
136 |
|
|
-59.251,3.430
|
137 |
ddd9a810
|
Adam M. Wilson
|
),ncol=2,byrow=T))),"Venezuela")
|
138 |
|
|
r2=Lines(list(
|
139 |
|
|
Line(matrix(c(
|
140 |
|
|
133.746,-31.834,
|
141 |
|
|
134.226,-32.143
|
142 |
|
|
),ncol=2,byrow=T))),"Australia")
|
143 |
|
|
r3=Lines(list(
|
144 |
|
|
Line(matrix(c(
|
145 |
|
|
73.943,27.419,
|
146 |
|
|
74.369,26.877
|
147 |
|
|
),ncol=2,byrow=T))),"India")
|
148 |
|
|
r4=Lines(list(
|
149 |
|
|
Line(matrix(c(
|
150 |
|
|
-5.164,42.270,
|
151 |
|
|
-4.948,42.162
|
152 |
|
|
),ncol=2,byrow=T))),"Spain")
|
153 |
|
|
|
154 |
|
|
r5=Lines(list(
|
155 |
|
|
Line(matrix(c(
|
156 |
be7b1081
|
Adam M. Wilson
|
33.195,12.512,
|
157 |
|
|
33.802,12.894
|
158 |
|
|
),ncol=2,byrow=T))),"Sudan")
|
159 |
|
|
|
160 |
|
|
r6=Lines(list(
|
161 |
|
|
Line(matrix(c(
|
162 |
|
|
-63.353,-10.746,
|
163 |
|
|
-63.376,-9.310
|
164 |
|
|
),ncol=2,byrow=T))),"Brazil")
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
trans=SpatialLines(list(r1,r2,r3,r5),CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs "))
|
168 |
|
|
### write out shapefiles of transects
|
169 |
|
|
writeOGR(SpatialLinesDataFrame(trans,data=data.frame(ID=names(trans)),match.ID=F),"output",layer="transects",driver="ESRI Shapefile",overwrite=T)
|
170 |
|
|
|
171 |
|
|
## buffer transects to get regional values
|
172 |
|
|
transb=gBuffer(trans,0.4)
|
173 |
|
|
|
174 |
|
|
## make polygons of bounding boxes
|
175 |
|
|
bb0 <- lapply(slot(transb, "polygons"), bbox)
|
176 |
|
|
library(splancs)
|
177 |
|
|
bb1 <- lapply(bb0, bboxx)
|
178 |
|
|
# turn these into matrices using a helper function in splancs
|
179 |
|
|
bb2 <- lapply(bb1, function(x) rbind(x, x[1,]))
|
180 |
|
|
# close the matrix rings by appending the first coordinate
|
181 |
|
|
rn <- row.names(transb)
|
182 |
|
|
# get the IDs
|
183 |
|
|
bb3 <- vector(mode="list", length=length(bb2))
|
184 |
|
|
# make somewhere to keep the output
|
185 |
|
|
for (i in seq(along=bb3)) bb3[[i]] <- Polygons(list(Polygon(bb2[[i]])),
|
186 |
|
|
ID=rn[i])
|
187 |
|
|
# loop over the closed matrix rings, adding the IDs
|
188 |
|
|
bbs <- SpatialPolygons(bb3, proj4string=CRS(proj4string(transb)))
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
trd1=lapply(1:length(transb),function(x) {
|
192 |
|
|
td=crop(mod11,transb[x])
|
193 |
|
|
tdd=lapply(list(mod35c5,mod35c6,mod09,mod17,mod17qc,mod11,mod11qc,lulc,pp),function(l) resample(crop(l,transb[x]),td,method="ngb"))
|
194 |
|
|
## normalize MOD11 and MOD17
|
195 |
|
|
for(j in which(do.call(c,lapply(tdd,function(i) names(i)))%in%c("MOD11","MOD17"))){
|
196 |
|
|
trange=cellStats(tdd[[j]],range)
|
197 |
|
|
tdd[[j]]=100*(tdd[[j]]-trange[1])/(trange[2]-trange[1])
|
198 |
|
|
tdd[[j]]@history=list(range=trange)
|
199 |
|
|
}
|
200 |
|
|
return(brick(tdd))
|
201 |
|
|
})
|
202 |
|
|
|
203 |
|
|
## bind all subregions into single dataframe for plotting
|
204 |
|
|
trd=do.call(rbind.data.frame,lapply(1:length(trd1),function(i){
|
205 |
|
|
d=as.data.frame(as.matrix(trd1[[i]]))
|
206 |
|
|
d[,c("x","y")]=coordinates(trd1[[i]])
|
207 |
|
|
d$trans=names(trans)[i]
|
208 |
|
|
d=melt(d,id.vars=c("trans","x","y"))
|
209 |
|
|
return(d)
|
210 |
|
|
}))
|
211 |
|
|
|
212 |
|
|
transd=do.call(rbind.data.frame,lapply(1:length(trans),function(l) {
|
213 |
|
|
td=as.data.frame(extract(trd1[[l]],trans[l],along=T,cellnumbers=F)[[1]])
|
214 |
|
|
td$loc=extract(trd1[[l]],trans[l],along=T,cellnumbers=T)[[1]][,1]
|
215 |
|
|
td[,c("x","y")]=xyFromCell(trd1[[l]],td$loc)
|
216 |
|
|
td$dist=spDistsN1(as.matrix(td[,c("x","y")]), as.matrix(td[1,c("x","y")]),longlat=T)
|
217 |
|
|
td$transect=names(trans[l])
|
218 |
|
|
td2=melt(td,id.vars=c("loc","x","y","dist","transect"))
|
219 |
|
|
td2=td2[order(td2$variable,td2$dist),]
|
220 |
|
|
# get per variable ranges to normalize
|
221 |
|
|
tr=cast(melt.list(tapply(td2$value,td2$variable,function(x) data.frame(min=min(x,na.rm=T),max=max(x,na.rm=T)))),L1~variable)
|
222 |
|
|
td2$min=tr$min[match(td2$variable,tr$L1)]
|
223 |
|
|
td2$max=tr$max[match(td2$variable,tr$L1)]
|
224 |
|
|
print(paste("Finished ",names(trans[l])))
|
225 |
ddd9a810
|
Adam M. Wilson
|
return(td2)}
|
226 |
be7b1081
|
Adam M. Wilson
|
))
|
227 |
|
|
|
228 |
|
|
transd$type=ifelse(grepl("MOD35|MOD09|CF",transd$variable),"CF","Data")
|
229 |
|
|
|
230 |
|
|
#rondonia=trd[trd$trans=="Brazil",]
|
231 |
|
|
#trd=trd[trd$trans!="Brazil",]
|
232 |
|
|
|
233 |
|
|
at=seq(0,100,leng=100)
|
234 |
|
|
bgyr=colorRampPalette(c("purple","blue","green","yellow","orange","red","red"))
|
235 |
|
|
bgrayr=colorRampPalette(c("purple","blue","grey","red","red"))
|
236 |
|
|
cols=bgyr(100)
|
237 |
|
|
|
238 |
|
|
## global map
|
239 |
|
|
library(maptools)
|
240 |
|
|
coast=map2SpatialLines(map("world", interior=FALSE, plot=FALSE),proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
|
241 |
|
|
|
242 |
|
|
g1=levelplot(stack(mod35c5,mod35c6,mod09),xlab=" ",scales=list(x=list(draw=F),y=list(alternating=1)),col.regions=cols,at=at)+layer(sp.polygons(bbs[1:4],lwd=2))+layer(sp.lines(coast,lwd=.5))
|
243 |
|
|
#g2=levelplot(dif,col.regions=bgrayr(100),at=seq(-70,70,len=100),margin=F,ylab=" ",colorkey=list("right"))+layer(sp.polygons(bbs[1:4],lwd=2))+layer(sp.lines(coast,lwd=.5))
|
244 |
|
|
#trellis.par.set(background=list(fill="white"),panel.background=list(fill="white"))
|
245 |
|
|
#g3=histogram(dif,bg="white",col="black",border=NA,scales=list(x=list(at=c(-50,0,50)),y=list(draw=F),cex=1))+layer(panel.abline(v=0,col="red",lwd=2))
|
246 |
|
|
|
247 |
|
|
### regional plots
|
248 |
|
|
p1=useOuterStrips(levelplot(value~x*y|variable+trans,data=trd[!trd$variable%in%c("MCD12Q1","MOD35pp"),],asp=1,scales=list(draw=F,rot=0,relation="free"),
|
249 |
|
|
at=at,col.regions=cols,maxpixels=7e6,
|
250 |
|
|
ylab="Latitude",xlab="Longitude"),strip = strip.custom(par.strip.text=list(cex=.75)))+layer(sp.lines(trans,lwd=2))
|
251 |
|
|
|
252 |
|
|
p2=useOuterStrips(
|
253 |
|
|
levelplot(value~x*y|variable+trans,data=trd[trd$variable%in%c("MCD12Q1"),],
|
254 |
|
|
asp=1,scales=list(draw=F,rot=0,relation="free"),colorkey=F,
|
255 |
|
|
at=c(-1,IGBP$ID),col.regions=IGBP$col,maxpixels=7e7,
|
256 |
|
|
legend=list(
|
257 |
|
|
right=list(fun=draw.key(list(columns=1,#title="MCD12Q1 \n IGBP Land \n Cover",
|
258 |
|
|
rectangles=list(col=IGBP$col,size=1),
|
259 |
|
|
text=list(as.character(IGBP$ID),at=IGBP$ID-.5))))),
|
260 |
|
|
ylab="",xlab=" "),strip = strip.custom(par.strip.text=list(cex=.75)),strip.left=F)+layer(sp.lines(trans,lwd=2))
|
261 |
|
|
p3=useOuterStrips(
|
262 |
|
|
levelplot(value~x*y|variable+trans,data=trd[trd$variable%in%c("MOD35pp"),],
|
263 |
|
|
asp=1,scales=list(draw=F,rot=0,relation="free"),colorkey=F,
|
264 |
|
|
at=c(-1:4),col.regions=c("blue","cyan","tan","darkgreen"),maxpixels=7e7,
|
265 |
|
|
legend=list(
|
266 |
|
|
right=list(fun=draw.key(list(columns=1,#title="MOD35 \n Processing \n Path",
|
267 |
|
|
rectangles=list(col=c("blue","cyan","tan","darkgreen"),size=1),
|
268 |
|
|
text=list(c("Water","Coast","Desert","Land")))))),
|
269 |
|
|
ylab="",xlab=" "),strip = strip.custom(par.strip.text=list(cex=.75)),strip.left=F)+layer(sp.lines(trans,lwd=2))
|
270 |
|
|
|
271 |
|
|
## transects
|
272 |
|
|
p4=xyplot(value~dist|transect,groups=variable,type=c("smooth","p"),
|
273 |
|
|
data=transd,panel=function(...,subscripts=subscripts) {
|
274 |
|
|
td=transd[subscripts,]
|
275 |
ddd9a810
|
Adam M. Wilson
|
## mod09
|
276 |
be7b1081
|
Adam M. Wilson
|
imod09=td$variable=="MOD09CF"
|
277 |
|
|
panel.xyplot(td$dist[imod09],td$value[imod09],type=c("p","smooth"),span=0.2,subscripts=1:sum(imod09),col="red",pch=16,cex=.25)
|
278 |
ddd9a810
|
Adam M. Wilson
|
## mod35C5
|
279 |
be7b1081
|
Adam M. Wilson
|
imod35=td$variable=="C5MOD35CF"
|
280 |
|
|
panel.xyplot(td$dist[imod35],td$value[imod35],type=c("p","smooth"),span=0.09,subscripts=1:sum(imod35),col="blue",pch=16,cex=.25)
|
281 |
|
|
## mod35C6
|
282 |
|
|
imod35c6=td$variable=="C6MOD35CF"
|
283 |
|
|
panel.xyplot(td$dist[imod35c6],td$value[imod35c6],type=c("p","smooth"),span=0.09,subscripts=1:sum(imod35c6),col="black",pch=16,cex=.25)
|
284 |
ddd9a810
|
Adam M. Wilson
|
## mod17
|
285 |
be7b1081
|
Adam M. Wilson
|
imod17=td$variable=="MOD17"
|
286 |
|
|
panel.xyplot(td$dist[imod17],100*((td$value[imod17]-td$min[imod17][1])/(td$max[imod17][1]-td$min[imod17][1])),
|
287 |
|
|
type=c("smooth"),span=0.09,subscripts=1:sum(imod17),col="darkgreen",lty=5,pch=1,cex=.25)
|
288 |
|
|
imod17qc=td$variable=="MOD17CF"
|
289 |
|
|
panel.xyplot(td$dist[imod17qc],td$value[imod17qc],type=c("p","smooth"),span=0.09,subscripts=1:sum(imod17qc),col="darkgreen",pch=16,cex=.25)
|
290 |
ddd9a810
|
Adam M. Wilson
|
## mod11
|
291 |
be7b1081
|
Adam M. Wilson
|
imod11=td$variable=="MOD11"
|
292 |
|
|
panel.xyplot(td$dist[imod11],100*((td$value[imod11]-td$min[imod11][1])/(td$max[imod11][1]-td$min[imod11][1])),
|
293 |
|
|
type=c("smooth"),span=0.09,subscripts=1:sum(imod17),col="orange",lty="dashed",pch=1,cex=.25)
|
294 |
|
|
imod11qc=td$variable=="MOD11CF"
|
295 |
|
|
qcspan=ifelse(td$transect[1]=="Australia",0.2,0.05)
|
296 |
|
|
panel.xyplot(td$dist[imod11qc],td$value[imod11qc],type=c("p","smooth"),npoints=100,span=qcspan,subscripts=1:sum(imod11qc),col="orange",pch=16,cex=.25)
|
297 |
ddd9a810
|
Adam M. Wilson
|
## land
|
298 |
be7b1081
|
Adam M. Wilson
|
path=td[td$variable=="MOD35pp",]
|
299 |
|
|
panel.segments(path$dist,-5,c(path$dist[-1],max(path$dist,na.rm=T)),-5,col=c("blue","cyan","tan","darkgreen")[path$value+1],subscripts=1:nrow(path),lwd=15,type="l")
|
300 |
|
|
land=td[td$variable=="MCD12Q1",]
|
301 |
|
|
panel.segments(land$dist,-10,c(land$dist[-1],max(land$dist,na.rm=T)),-10,col=IGBP$col[land$value+1],subscripts=1:nrow(land),lwd=15,type="l")
|
302 |
|
|
},subscripts=T,par.settings = list(grid.pars = list(lineend = "butt")),
|
303 |
ddd9a810
|
Adam M. Wilson
|
scales=list(
|
304 |
be7b1081
|
Adam M. Wilson
|
x=list(alternating=1,relation="free"),#, lim=c(0,70)),
|
305 |
|
|
y=list(at=c(-10,-5,seq(0,100,len=5)),
|
306 |
|
|
labels=c("IGBP","MOD35",seq(0,100,len=5)),
|
307 |
|
|
lim=c(-15,100))),
|
308 |
|
|
xlab="Distance Along Transect (km)", ylab="% Missing Data / % of Maximum Value",
|
309 |
|
|
legend=list(
|
310 |
a57c4e3d
|
Adam M. Wilson
|
bottom=list(fun=draw.key(list( rep=FALSE,columns=1,title=" ",
|
311 |
|
|
## text=list(c("MOD09 % Cloudy","C5 MOD35 % Cloudy","C6 MOD35 % Cloudy","MOD17 % Missing","MOD17 (scaled)","MOD11 % Missing","MOD11 (scaled)")),
|
312 |
|
|
lines=list(type=c("b","b","b","b","l","b","l"),pch=16,cex=.5,lty=c(1,1,1,1,5,1,5),col=c("red","blue","black","darkgreen","darkgreen","orange","orange")),
|
313 |
|
|
text=list(c("MOD09 % Cloudy","C5 MOD35 % Cloudy","C6 MOD35 % Cloudy","MOD17 % Missing","MOD17 (scaled)","MOD11 % Missing","MOD11 (scaled)")),
|
314 |
|
|
rectangles=list(border=NA,col=c(NA,"tan","darkgreen")),
|
315 |
|
|
text=list(c("C5 MOD35 Processing Path","Desert","Land")),
|
316 |
|
|
rectangles=list(border=NA,col=c(NA,IGBP$col[sort(unique(transd$value[transd$variable=="MCD12Q1"]+1))])),
|
317 |
|
|
text=list(c("MCD12Q1 IGBP Land Cover",IGBP$class[sort(unique(transd$value[transd$variable=="MCD12Q1"]+1))])))))),
|
318 |
|
|
strip = strip.custom(par.strip.text=list(cex=.75)))
|
319 |
be7b1081
|
Adam M. Wilson
|
print(p4)
|
320 |
|
|
|
321 |
a57c4e3d
|
Adam M. Wilson
|
trdw=cast(trd,trans+x+y~variable,value="value")
|
322 |
|
|
transdw=cast(transd,transect+dist~variable,value="value")
|
323 |
|
|
|
324 |
|
|
xyplot(MOD11CF~C5MOD35CF|transect,groups=MCD12Q1,data=transdw,pch=16,cex=1,scales=list(relation="free"))
|
325 |
|
|
xyplot(MOD17~C5MOD35CF|trans,groups=MCD12Q1,data=trdw,pch=16,cex=1,scales=list(relation="free"))
|
326 |
|
|
|
327 |
be7b1081
|
Adam M. Wilson
|
#p5=levelplot(value~x*y|variable,data=rondonia,asp=1,scales=list(draw=F,rot=0,relation="free"),colorkey=T)#,
|
328 |
|
|
#print(p5)
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
CairoPDF("output/mod35compare.pdf",width=11,height=7)
|
332 |
|
|
#CairoPNG("output/mod35compare_%d.png",units="in", width=11,height=8.5,pointsize=4000,dpi=1200,antialias="subpixel")
|
333 |
|
|
### Global Comparison
|
334 |
|
|
print(g1)
|
335 |
|
|
#print(g1,position=c(0,.33,1,1),more=T)
|
336 |
|
|
#print(g2,position=c(0,0,1,0.394),more=T)
|
337 |
|
|
#print(g3,position=c(0.31,0.06,.42,0.27),more=F)
|
338 |
|
|
### MOD35 Desert Processing path
|
339 |
|
|
levelplot(pp,asp=1,scales=list(draw=T,rot=0),maxpixels=1e6,
|
340 |
|
|
at=c(-1:3),col.regions=c("blue","cyan","tan","darkgreen"),margin=F,
|
341 |
|
|
colorkey=list(space="bottom",title="MOD35 Processing Path",labels=list(labels=c("Water","Coast","Desert","Land"),at=0:4-.5)))+layer(sp.polygons(bbs,lwd=2))+layer(sp.lines(coast,lwd=.5))
|
342 |
ddd9a810
|
Adam M. Wilson
|
### levelplot of regions
|
343 |
be7b1081
|
Adam M. Wilson
|
print(p1,position=c(0,0,.62,1),more=T)
|
344 |
|
|
print(p2,position=c(0.6,0.21,0.78,0.79),more=T)
|
345 |
|
|
print(p3,position=c(0.76,0.21,1,0.79))
|
346 |
|
|
### profile plots
|
347 |
|
|
print(p4)
|
348 |
|
|
dev.off()
|
349 |
ddd9a810
|
Adam M. Wilson
|
|
350 |
be7b1081
|
Adam M. Wilson
|
### summary stats for paper
|
351 |
|
|
td=cast(transect+loc+dist~variable,value="value",data=transd)
|
352 |
|
|
td2=melt.data.frame(td,id.vars=c("transect","dist","loc","MOD35pp","MCD12Q1"))
|
353 |
ddd9a810
|
Adam M. Wilson
|
|
354 |
be7b1081
|
Adam M. Wilson
|
## function to prettyprint mean/sd's
|
355 |
|
|
msd= function(x) paste(round(mean(x,na.rm=T),1),"% ±",round(sd(x,na.rm=T),1),sep="")
|
356 |
ddd9a810
|
Adam M. Wilson
|
|
357 |
be7b1081
|
Adam M. Wilson
|
cast(td2,transect+variable~MOD35pp,value="value",fun=msd)
|
358 |
|
|
cast(td2,transect+variable~MOD35pp+MCD12Q1,value="value",fun=msd)
|
359 |
|
|
cast(td2,transect+variable~.,value="value",fun=msd)
|
360 |
|
|
|
361 |
|
|
cast(td2,transect+variable~.,value="value",fun=msd)
|
362 |
|
|
|
363 |
|
|
cast(td2,variable~MOD35pp,value="value",fun=msd)
|
364 |
|
|
cast(td2,variable~.,value="value",fun=msd)
|
365 |
|
|
|
366 |
|
|
td[td$transect=="Venezuela",]
|
367 |
ddd9a810
|
Adam M. Wilson
|
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
be7b1081
|
Adam M. Wilson
|
## scatterplot of MOD35 vs MOD09
|
372 |
|
|
trdl=cast(trans+x+y~variable,value="value",data=trd)
|
373 |
|
|
xyplot(MOD35C5qc~MOD09qc|trans+as.factor(MOD35pp),pch=16,cex=.2,data=trdl,auto.key=T)+layer(panel.abline(0,1))
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
### LANDCOVER
|
377 |
|
|
levelplot(lulc,col.regions=IGBP$col,scales=list(cex=2),colorkey=list(space="right",at=0:17,labels=list(at=seq(0.5,16.5,by=1),labels=levels(lulc)[[1]]$class,cex=2)),margin=F)
|
378 |
ddd9a810
|
Adam M. Wilson
|
|
379 |
|
|
levelplot(mcompare,col.regions=cols,at=at,margin=F,sub="Frequency of MOD35 Clouds in March")
|
380 |
|
|
#levelplot(dif,col.regions=bgyr(20),margin=F)
|
381 |
|
|
levelplot(mdiff,col.regions=bgyr(100),at=seq(mdiff@data@min,mdiff@data@max,len=100),margin=F)
|
382 |
|
|
|
383 |
|
|
|
384 |
|
|
boxplot(as.matrix(subset(dif,subset=1))~forest,varwidth=T,notch=T);abline(h=0)
|
385 |
|
|
|
386 |
|
|
|
387 |
|
|
levelplot(modprod,main="Missing Data (%) in MOD17 (NPP) and MOD43 (BRDF Reflectance)",
|
388 |
|
|
sub="Tile H11v08 (Venezuela)",col.regions=cols,at=at)
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
levelplot(modprod,main="Missing Data (%) in MOD17 (NPP) and MOD43 (BRDF Reflectance)",
|
394 |
|
|
sub="Tile H11v08 (Venezuela)",col.regions=cols,at=at,
|
395 |
|
|
xlim=c(-7300000,-6670000),ylim=c(0,600000))
|
396 |
|
|
|
397 |
|
|
levelplot(v5m,main="Missing Data (%) in MOD17 (NPP) and MOD43 (BRDF Reflectance)",
|
398 |
|
|
sub="Tile H11v08 (Venezuela)",col.regions=cols,at=at,
|
399 |
|
|
xlim=c(-7200000,-6670000),ylim=c(0,400000),margin=F)
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
levelplot(subset(v5v6compare,1:2),main="Proportion Cloudy Days (%) in Collection 5 and 6 MOD35",
|
403 |
|
|
sub="Tile H11v08 (Venezuela)",col.regions=cols,at=at,
|
404 |
|
|
margin=F)
|
405 |
|
|
|
406 |
|
|
levelplot(subset(v5v6compare,1:2),main="Proportion Cloudy Days (%) in Collection 5 and 6 MOD35",
|
407 |
|
|
sub="Tile H11v08 (Venezuela)",col.regions=cols,at=at,
|
408 |
|
|
xlim=c(-7200000,-6670000),ylim=c(0,400000),margin=F)
|
409 |
|
|
|
410 |
|
|
levelplot(subset(v5v6compare,1:2),main="Proportion Cloudy Days (%) in Collection 5 and 6 MOD35",
|
411 |
|
|
sub="Tile H11v08 (Venezuela)",col.regions=cols,at=at,
|
412 |
|
|
xlim=c(-7500000,-7200000),ylim=c(700000,1000000),margin=F)
|
413 |
|
|
|
414 |
|
|
|
415 |
|
|
dev.off()
|
416 |
|
|
|
417 |
|
|
### smoothing plots
|
418 |
|
|
## explore smoothed version
|
419 |
|
|
td=subset(v6,m)
|
420 |
|
|
## build weight matrix
|
421 |
|
|
s=3
|
422 |
|
|
w=matrix(1/(s*s),nrow=s,ncol=s)
|
423 |
|
|
#w[s-1,s-1]=4/12; w
|
424 |
|
|
td2=focal(td,w=w)
|
425 |
|
|
td3=stack(td,td2)
|
426 |
|
|
|
427 |
|
|
levelplot(td3,col.regions=cols,at=at,margin=F)
|
428 |
|
|
|
429 |
|
|
dev.off()
|
430 |
|
|
plot(stack(difm,lulc))
|
431 |
|
|
|
432 |
|
|
### ROI
|
433 |
|
|
tile_ll=projectExtent(v6, "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
|
434 |
|
|
|
435 |
|
|
62,59
|
436 |
|
|
0,3
|
437 |
|
|
|
438 |
|
|
|
439 |
|
|
|
440 |
|
|
#### export KML timeseries
|
441 |
|
|
library(plotKML)
|
442 |
|
|
tile="h11v08"
|
443 |
|
|
file=paste("summary/MOD35_",tile,".nc",sep="")
|
444 |
|
|
system(paste("gdalwarp -overwrite -multi -ot INT16 -r cubicspline -srcnodata 255 -dstnodata 255 -s_srs '+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs' -t_srs 'EPSG:4326' NETCDF:",file,":PCloud MOD35_",tile,".tif",sep=""))
|
445 |
|
|
|
446 |
|
|
v6sp=brick(paste("MOD35_",tile,".tif",sep=""))
|
447 |
|
|
v6sp=readAll(v6sp)
|
448 |
|
|
|
449 |
|
|
## wasn't working with line below, perhaps Z should just be text? not date?
|
450 |
|
|
v6sp=setZ(v6sp,as.Date(paste("2011-",1:12,"-15",sep="")))
|
451 |
|
|
names(v6sp)=month.name
|
452 |
|
|
|
453 |
|
|
kml_open("output/mod35.kml")
|
454 |
|
|
|
455 |
|
|
|
456 |
|
|
kml_layer.RasterBrick(v6sp,
|
457 |
|
|
plot.legend = TRUE, dtime = "", tz = "GMT",
|
458 |
|
|
z.lim = c(0,100),colour_scale = get("colour_scale_numeric", envir = plotKML.opts))
|
459 |
|
|
# home_url = get("home_url", envir = plotKML.opts),
|
460 |
|
|
# metadata = NULL, html.table = NULL,
|
461 |
|
|
# altitudeMode = "clampToGround", balloon = FALSE,
|
462 |
|
|
)
|
463 |
|
|
|
464 |
|
|
logo = "http://static.tumblr.com/t0afs9f/KWTm94tpm/yale_logo.png"
|
465 |
|
|
kml_screen(image.file = logo, position = "UL", sname = "YALE logo",size=c(.1,.1))
|
466 |
|
|
kml_close("mod35.kml")
|
467 |
|
|
kml_compress("mod35.kml",files=c(paste(month.name,".png",sep=""),"obj_legend.png"),zip="/usr/bin/zip")
|