Project

General

Profile

Download (18.7 KB) Statistics
| Branch: | Revision:
1
## Figures associated with MOD35 Cloud Mask Exploration
2

    
3
setwd("~/acrobates/adamw/projects/MOD35C6")
4

    
5
library(raster)#;beginCluster(10)
6
library(rasterVis)
7
library(rgdal)
8
library(plotKML)
9
library(Cairo)
10
library(reshape)
11
library(rgeos)
12
library(splancs)
13

    
14
## mod35C6 annual
15
if(!file.exists("data/MOD35C6_2009.tif")){
16
  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 `find /home/adamw/acrobates/adamw/projects/interp/data/modis/mod35/summary/ -name '*h[0-9][0-9]v[0-9][0-9]*_mean.nc'` ")
17
#  system("gdalbuildvrt data/MOD35C6.vrt `find /home/adamw/acrobates/adamw/projects/interp/data/modis/mod35/summary/ -name '*h[1]*_mean.nc'` ")
18

    
19
  system("align.sh data/MOD35C6.vrt data/MOD09_2009.tif data/MOD35C6_2009.tif")
20
  ## add color bar
21
  system("/usr/local/bin/pkcreatect -min 0 -max 100 -g -i data/MOD35C6_2009.tif -o data/MOD35C6_2009.tif -ct none -co COMPRESS=LZW")
22
#  system("align.sh data/MOD35C6_CFday_pmiss.vrt data/MOD09_2009.tif data/MOD35C6_CFday_pmiss.tif")
23
}
24
mod35c6=raster("data/MOD35C6_2009_v1.tif")
25
names(mod35c6)="C6MOD35CF"
26
NAvalue(mod35c6)=255
27

    
28
### summary of "alltests" netcdf file
29
tests=c("CMday", "CMnight", "non_cloud_obstruction", "thin_cirrus_solar", "shadow", "thin_cirrus_ir", "cloud_adjacency_ir", "ir_threshold", "high_cloud_co2", "high_cloud_67", "high_cloud_138", "high_cloud_37_12", "cloud_ir_difference",
30
"cloud_37_11","cloud_visible","cloud_visible_ratio","cloud_ndvi","cloud_night_73_11")
31
alt=brick(lapply(tests,function(t){
32
  td=raster("data/MOD35_h12v04_mean_alltests.nc",varname=t)
33
  NAvalue(td)=255
34
  projection(td)='+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs'
35
  return(td)
36
}  ))
37
levelplot(alt,at=seq(100,0,len=100),col.regions=grey(seq(0,1,len=99)),layout=c(6,3))
38

    
39

    
40
## landcover
41
if(!file.exists("data/MCD12Q1_IGBP_2009_051_wgs84_1km.tif")){
42
  system(paste("/usr/local/gdal-1.10.0/bin/gdalwarp -tr 0.008983153 0.008983153 -r mode -ot Byte -co \"COMPRESS=LZW\"",
43
               " /mnt/data/jetzlab/Data/environ/global/MODIS/MCD12Q1/051/MCD12Q1_051_2009_wgs84.tif ",
44
               " -t_srs \"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs\" ",
45
               " -te -180.0044166 -60.0074610 180.0044166 90.0022083 ",
46
               "data/MCD12Q1_IGBP_2009_051_wgs84_1km.tif -overwrite ",sep=""))}
47
lulc=raster("data/MCD12Q1_IGBP_2009_051_wgs84_1km.tif")
48

    
49
#  lulc=ratify(lulc)
50
  data(worldgrids_pal)  #load palette
51
  IGBP=data.frame(ID=0:16,col=worldgrids_pal$IGBP[-c(18,19)],
52
    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)
53
  IGBP$class=rownames(IGBP);rownames(IGBP)=1:nrow(IGBP)
54
  levels(lulc)=list(IGBP)
55
#lulc=crop(lulc,mod09)
56
names(lulc)="MCD12Q1"
57

    
58
## make land mask
59
if(!file.exists("data/land.tif"))
60
  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)
61
land=raster("data/land.tif")
62

    
63
## mask cloud masks to land pixels
64
#mod09l=mask(mod09,land)
65
#mod35l=mask(mod35,land)
66

    
67
#####################################
68
### compare MOD43 and MOD17 products
69

    
70
## MOD17
71
#extent(mod17)=alignExtent(mod17,mod09)
72
if(!file.exists("data/MOD17.tif"))
73
system("align.sh ~/acrobates/adamw/projects/interp/data/modis/MOD17/MOD17A3_Science_NPP_mean_00_12.tif data/MOD09_2009.tif data/MOD17.tif")
74
mod17=raster("data/MOD17.tif",format="GTiff")
75
NAvalue(mod17)=65535
76
names(mod17)="MOD17_unscaled"
77

    
78
if(!file.exists("data/MOD17qc.tif"))
79
  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")
80
mod17qc=raster("data/MOD17qc.tif",format="GTiff")
81
NAvalue(mod17qc)=255
82
names(mod17qc)="MOD17CF"
83

    
84
## MOD11 via earth engine
85
if(!file.exists("data/MOD11_2009.tif"))
86
  system("align.sh ~/acrobates/adamw/projects/interp/data/modis/mod11/2009/MOD11_LST_2009.tif data/MOD09_2009.tif data/MOD11_2009.tif")
87
mod11=raster("data/MOD11_2009.tif",format="GTiff")
88
names(mod11)="MOD11_unscaled"
89
NAvalue(mod11)=0
90
if(!file.exists("data/MOD11qc_2009.tif"))
91
  system("align.sh ~/acrobates/adamw/projects/interp/data/modis/mod11/2009/MOD11_Pmiss_2009.tif data/MOD09_2009.tif data/MOD11qc_2009.tif")
92
mod11qc=raster("data/MOD11qc_2009.tif",format="GTiff")
93
names(mod11qc)="MOD11CF"
94

    
95
### Processing path
96
if(!file.exists("data/MOD35pp.tif"))
97
system("align.sh data/MOD35_ProcessPath.tif data/MOD09_2009.tif data/MOD35pp.tif")
98
pp=raster("data/MOD35pp.tif")
99
NAvalue(pp)=255
100
names(pp)="MOD35pp"
101

    
102

    
103
#hist(dif,maxsamp=1000000)
104
## draw lulc-stratified random sample of mod35-mod09 differences 
105
#samp=sampleStratified(lulc, 1000, exp=10)
106
#save(samp,file="LULC_StratifiedSample_10000.Rdata")
107
#mean(dif[samp],na.rm=T)
108
#Stats(dif,function(x) c(mean=mean(x),sd=sd(x)))
109

    
110

    
111
###
112

    
113
n=100
114
at=seq(0,100,len=n)
115
cols=grey(seq(0,1,len=n))
116
cols=rainbow(n)
117
bgyr=colorRampPalette(c("blue","green","yellow","red"))
118
cols=bgyr(n)
119

    
120

    
121
### Transects
122
r1=Lines(list(
123
  Line(matrix(c(
124
                -61.688,4.098,
125
                -59.251,3.430
126
                ),ncol=2,byrow=T))),"Venezuela")
127
r2=Lines(list(
128
  Line(matrix(c(
129
                133.746,-31.834,
130
                134.226,-32.143
131
                ),ncol=2,byrow=T))),"Australia")
132
r3=Lines(list(
133
  Line(matrix(c(
134
                73.943,27.419,
135
                74.369,26.877
136
                ),ncol=2,byrow=T))),"India")
137
#r4=Lines(list(
138
#  Line(matrix(c(
139
#                -5.164,42.270,
140
#                -4.948,42.162
141
#                ),ncol=2,byrow=T))),"Spain")
142

    
143
r5=Lines(list(
144
  Line(matrix(c(
145
                33.195,12.512,
146
                33.802,12.894
147
                ),ncol=2,byrow=T))),"Sudan")
148

    
149
#r6=Lines(list(
150
#  Line(matrix(c(
151
#                -63.353,-10.746,
152
#                -63.376,-9.310
153
#                ),ncol=2,byrow=T))),"Brazil")
154

    
155

    
156
trans=SpatialLines(list(r1,r2,r3,r5),CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs "))
157
### write out shapefiles of transects
158
writeOGR(SpatialLinesDataFrame(trans,data=data.frame(ID=names(trans)),match.ID=F),"output",layer="transects",driver="ESRI Shapefile",overwrite=T)
159

    
160
## buffer transects to get regional values 
161
transb=gBuffer(trans,byid=T,width=0.4)
162

    
163
## make polygons of bounding boxes
164
bb0 <- lapply(slot(transb, "polygons"), bbox)
165
bb1 <- lapply(bb0, bboxx)
166
# turn these into matrices using a helper function in splancs
167
bb2 <- lapply(bb1, function(x) rbind(x, x[1,]))
168
# close the matrix rings by appending the first coordinate
169
rn <- row.names(transb)
170
# get the IDs
171
bb3 <- vector(mode="list", length=length(bb2))
172
# make somewhere to keep the output
173
for (i in seq(along=bb3)) bb3[[i]] <- Polygons(list(Polygon(bb2[[i]])),
174
                   ID=rn[i])
175
# loop over the closed matrix rings, adding the IDs
176
bbs <- SpatialPolygons(bb3, proj4string=CRS(proj4string(transb)))
177

    
178
trd1=lapply(1:length(transb),function(x) {
179
  td=crop(mod11,transb[x])
180
  tdd=lapply(list(mod35c5,mod35c6,mod09,mod17,mod17qc,mod11,mod11qc,lulc,pp),function(l) resample(crop(l,transb[x]),td,method="ngb"))
181
  ## normalize MOD11 and MOD17
182
  for(j in which(do.call(c,lapply(tdd,function(i) names(i)))%in%c("MOD11_unscaled","MOD17_unscaled"))){
183
    trange=cellStats(tdd[[j]],range)
184
    tscaled=100*(tdd[[j]]-trange[1])/(trange[2]-trange[1])
185
    tscaled@history=list(range=trange)
186
    names(tscaled)=sub("_unscaled","",names(tdd[[j]]))
187
    tdd=c(tdd,tscaled)
188
  }
189
  return(brick(tdd))
190
})
191

    
192
## bind all subregions into single dataframe for plotting
193
trd=do.call(rbind.data.frame,lapply(1:length(trd1),function(i){
194
  d=as.data.frame(as.matrix(trd1[[i]]))
195
  d[,c("x","y")]=coordinates(trd1[[i]])
196
  d$trans=names(trans)[i]
197
  d=melt(d,id.vars=c("trans","x","y"))
198
  return(d)
199
}))
200

    
201
transd=do.call(rbind.data.frame,lapply(1:length(trans),function(l) {
202
  td=as.data.frame(extract(trd1[[l]],trans[l],along=T,cellnumbers=F)[[1]])
203
  td$loc=extract(trd1[[l]],trans[l],along=T,cellnumbers=T)[[1]][,1]
204
  td[,c("x","y")]=xyFromCell(trd1[[l]],td$loc)
205
  td$dist=spDistsN1(as.matrix(td[,c("x","y")]), as.matrix(td[1,c("x","y")]),longlat=T)
206
  td$transect=names(trans[l])
207
  td2=melt(td,id.vars=c("loc","x","y","dist","transect"))
208
  td2=td2[order(td2$variable,td2$dist),]
209
  # get per variable ranges to normalize
210
  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)
211
  td2$min=tr$min[match(td2$variable,tr$L1)]
212
  td2$max=tr$max[match(td2$variable,tr$L1)]
213
  print(paste("Finished ",names(trans[l])))
214
  return(td2)}
215
  ))
216

    
217
transd$type=ifelse(grepl("MOD35|MOD09|CF",transd$variable),"CF","Data")
218

    
219

    
220
## comparison of % cloudy days
221
if(!file.exists("data/dif_c5_09.tif"))
222
  overlay(mod35c5,mod09,fun=function(x,y) {return(x-y)},file="data/dif_c5_09.tif",format="GTiff",options=c("COMPRESS=LZW","ZLEVEL=9"),overwrite=T)
223
dif_c5_09=raster("data/dif_c5_09.tif",format="GTiff")
224

    
225
#dif_c6_09=mod35c6-mod09
226
#dif_c5_c6=mod35c5-mod35c6
227

    
228
## exploring various ways to compare cloud products along landcover or processing path edges
229
#t1=trd1[[1]]
230
#dif_p=calc(trd1[[1]], function(x) (x[1]-x[3])/(1-x[1]))
231
#edge=calc(edge(subset(t1,"MCD12Q1"),classes=T,type="inner"),function(x) ifelse(x==1,1,NA))
232
#edgeb=buffer(edge,width=5000)
233
#edgeb=calc(edgeb,function(x) ifelse(is.na(x),0,1))
234
#names(edge)="edge"
235
#names(edgeb)="edgeb"
236
#td1=as.data.frame(stack(t1,edge,edgeb))
237
#cor(td1$MOD17,td1$C6MOD35,use="complete",method="spearman")
238
#cor(td1$MOD17[td1$edgeb==1],td1$C5MOD35[td1$edgeb==1],use="complete",method="spearman")
239

    
240
### Correlations
241
#trdw=cast(trd,trans+x+y~variable,value="value")
242
#cor(trdw$MOD17,trdw$C5MOD35,use="complete",method="spearman")
243

    
244
#Across all pixels in the four regions analyzed in Figure 3 there is a much larger correlation between mean NPP and the C5 MOD35 CF (Spearman’s ρ = -0.61, n=58,756) than the C6 MOD35 CF (ρ = 0.00, n=58,756) or MOD09 (ρ = -0.07, n=58,756) products.  
245
#by(trdw,trdw$trans,function(x) cor(as.data.frame(na.omit(x[,c("C5MOD35CF","C6MOD35CF","C5MOD09CF","MOD17","MOD11")])),use="complete",method="spearman"))
246

    
247

    
248
## table of correlations
249
#trdw_cor=as.data.frame(na.omit(trdw[,c("C5MOD35CF","C6MOD35CF","C5MOD09CF","MOD17","MOD11")]))
250
#nrow(trdw_cor)
251
#round(cor(trdw_cor,method="spearman"),2)
252

    
253

    
254
## set up some graphing parameters
255
at=seq(0,100,leng=100)
256
bgyr=colorRampPalette(c("purple","blue","green","yellow","orange","red","red"))
257
bgrayr=colorRampPalette(c("purple","blue","grey","red","red"))
258
cols=bgyr(100)
259

    
260
## global map
261
library(maptools)
262
coast=map2SpatialLines(map("world", interior=FALSE, plot=FALSE),proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
263

    
264
g1=levelplot(stack(mod35c5,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))
265

    
266
g2=levelplot(dif_c5_09,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))
267
g2$strip=strip.custom(var.name="Difference (C5MOD35-C5MOD09)",style=1,strip.names=T,strip.levels=F)  #update strip text
268
#g3=histogram(dif_c5_09,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))
269

    
270
### regional plots
271
p1=useOuterStrips(levelplot(value~x*y|variable+trans,data=trd[!trd$variable%in%c("MOD17_unscaled","MOD11_unscaled","MCD12Q1","MOD35pp"),],asp=1,scales=list(draw=F,rot=0,relation="free"),
272
                                       at=at,col.regions=cols,maxpixels=7e6,
273
                                       ylab="Latitude",xlab="Longitude"),strip = strip.custom(par.strip.text=list(cex=.7)))+layer(sp.lines(trans,lwd=2))
274

    
275
p2=useOuterStrips(
276
  levelplot(value~x*y|variable+trans,data=trd[trd$variable%in%c("MCD12Q1"),],
277
            asp=1,scales=list(draw=F,rot=0,relation="free"),colorkey=F,
278
            at=c(-1,IGBP$ID),col.regions=IGBP$col,maxpixels=7e7,
279
            legend=list(
280
              right=list(fun=draw.key(list(columns=1,#title="MCD12Q1 \n IGBP Land \n Cover",
281
                           rectangles=list(col=IGBP$col,size=1),
282
                           text=list(as.character(IGBP$ID),at=IGBP$ID-.5))))),
283
            ylab="",xlab=" "),strip = strip.custom(par.strip.text=list(cex=.7)),strip.left=F)+layer(sp.lines(trans,lwd=2))
284
p3=useOuterStrips(
285
  levelplot(value~x*y|variable+trans,data=trd[trd$variable%in%c("MOD35pp"),],
286
            asp=1,scales=list(draw=F,rot=0,relation="free"),colorkey=F,
287
            at=c(-1:4),col.regions=c("blue","cyan","tan","darkgreen"),maxpixels=7e7,
288
            legend=list(
289
              right=list(fun=draw.key(list(columns=1,#title="MOD35 \n Processing \n Path",
290
                           rectangles=list(col=c("blue","cyan","tan","darkgreen"),size=1),
291
                           text=list(c("Water","Coast","Desert","Land")))))),
292
            ylab="",xlab=" "),strip = strip.custom(par.strip.text=list(cex=.7)),strip.left=F)+layer(sp.lines(trans,lwd=2))
293

    
294
## transects
295
p4=xyplot(value~dist|transect,groups=variable,type=c("smooth","p"),
296
       data=transd,panel=function(...,subscripts=subscripts) {
297
         td=transd[subscripts,]
298
         ## mod09
299
         imod09=td$variable=="C5MOD09CF"
300
         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)
301
         ## mod35C5
302
         imod35=td$variable=="C5MOD35CF"
303
         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)
304
         ## mod35C6
305
         imod35c6=td$variable=="C6MOD35CF"
306
         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)
307
         ## mod17
308
         imod17=td$variable=="MOD17"
309
         panel.xyplot(td$dist[imod17],100*((td$value[imod17]-td$min[imod17][1])/(td$max[imod17][1]-td$min[imod17][1])),
310
                      type=c("smooth"),span=0.09,subscripts=1:sum(imod17),col="darkgreen",lty=5,pch=1,cex=.25)
311
         imod17qc=td$variable=="MOD17CF"
312
         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)
313
         ## mod11
314
         imod11=td$variable=="MOD11"
315
         panel.xyplot(td$dist[imod11],100*((td$value[imod11]-td$min[imod11][1])/(td$max[imod11][1]-td$min[imod11][1])),
316
                      type=c("smooth"),span=0.09,subscripts=1:sum(imod17),col="orange",lty="dashed",pch=1,cex=.25)
317
         imod11qc=td$variable=="MOD11CF"
318
         qcspan=ifelse(td$transect[1]=="Australia",0.2,0.05)
319
         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)
320
         ## land
321
         path=td[td$variable=="MOD35pp",]
322
         panel.segments(path$dist,-10,c(path$dist[-1],max(path$dist,na.rm=T)),-10,col=c("blue","cyan","tan","darkgreen")[path$value+1],subscripts=1:nrow(path),lwd=10,type="l")
323
         land=td[td$variable=="MCD12Q1",]
324
         panel.segments(land$dist,-20,c(land$dist[-1],max(land$dist,na.rm=T)),-20,col=IGBP$col[land$value+1],subscripts=1:nrow(land),lwd=10,type="l")
325
        },subscripts=T,par.settings = list(grid.pars = list(lineend = "butt")),
326
       scales=list(
327
         x=list(alternating=1,relation="free"),#, lim=c(0,70)),
328
         y=list(at=c(-18,-10,seq(0,100,len=5)),
329
           labels=c("MCD12Q1 IGBP","MOD35 path",seq(0,100,len=5)),
330
           lim=c(-25,100)),
331
         alternating=F),
332
       xlab="Distance Along Transect (km)", ylab="% Missing Data / % of Maximum Value",
333
       legend=list(
334
         bottom=list(fun=draw.key(list( rep=FALSE,columns=1,title=" ",
335
                      lines=list(type=c("b","b","b","b","b","l","b","l"),pch=16,cex=.5,
336
                        lty=c(0,1,1,1,1,5,1,5),
337
                        col=c("transparent","red","blue","black","darkgreen","darkgreen","orange","orange")),
338
                       text=list(
339
                         c("MODIS Products","C5 MOD09 % Cloudy","C5 MOD35 % Cloudy","C6 MOD35 % Cloudy","MOD17 % Missing","MOD17 (scaled)","MOD11 % Missing","MOD11 (scaled)")),
340
                       rectangles=list(border=NA,col=c(NA,"tan","darkgreen")),
341
                       text=list(c("C5 MOD35 Processing Path","Desert","Land")),
342
                       rectangles=list(border=NA,col=c(NA,IGBP$col[sort(unique(transd$value[transd$variable=="MCD12Q1"]+1))])),
343
                       text=list(c("MCD12Q1 IGBP Land Cover",IGBP$class[sort(unique(transd$value[transd$variable=="MCD12Q1"]+1))])))))),
344
  strip = strip.custom(par.strip.text=list(cex=.75)))
345
print(p4)
346

    
347

    
348

    
349
CairoPDF("output/mod35compare.pdf",width=11,height=7)
350
#CairoPNG("output/mod35compare_%d.png",units="in", width=11,height=8.5,pointsize=4000,dpi=1200,antialias="subpixel")
351
### Global Comparison
352
print(g1,position=c(0,.35,1,1),more=T)
353
print(g2,position=c(0,0,1,0.415),more=F)
354
#print(g3,position=c(0.31,0.06,.42,0.27),more=F)
355
         
356
### MOD35 Desert Processing path
357
levelplot(pp,asp=1,scales=list(draw=T,rot=0),maxpixels=1e6,
358
          at=c(-1:3),col.regions=c("blue","cyan","tan","darkgreen"),margin=F,
359
          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))
360
### levelplot of regions
361
print(p1,position=c(0,0,.62,1),more=T)
362
print(p2,position=c(0.6,0.21,0.78,0.79),more=T)
363
print(p3,position=c(0.76,0.21,1,0.79))
364
### profile plots
365
print(p4)
366
dev.off()
367

    
368
### summary stats for paper
369
td=cast(transect+loc+dist~variable,value="value",data=transd)
370
td2=melt.data.frame(td,id.vars=c("transect","dist","loc","MOD35pp","MCD12Q1"))
371

    
372
## function to prettyprint mean/sd's
373
msd= function(x) paste(round(mean(x,na.rm=T),1),"% ±",round(sd(x,na.rm=T),1),sep="")
374

    
375
cast(td2,transect+variable~MOD35pp,value="value",fun=msd)
376
cast(td2,transect+variable~MOD35pp+MCD12Q1,value="value",fun=msd)
377
cast(td2,transect+variable~.,value="value",fun=msd)
378

    
379
cast(td2,transect+variable~.,value="value",fun=msd)
380

    
381
cast(td2,variable~MOD35pp,value="value",fun=msd)
382
cast(td2,variable~.,value="value",fun=msd)
383

    
384
td[td$transect=="Venezuela",]
385

    
386

    
387
#### export KML
388
library(plotKML)
389

    
390
kml_open("output/modiscloud.kml")
391

    
392
readAll(mod35c5)
393

    
394
kml_layer.Raster(mod35c5,
395
     plot.legend = TRUE,raster_name="Collection 5 MOD35 Cloud Frequency",
396
    z.lim = c(0,100),colour_scale = get("colour_scale_numeric", envir = plotKML.opts),
397
#    home_url = get("home_url", envir = plotKML.opts),
398
#    metadata = NULL, html.table = NULL,
399
    altitudeMode = "clampToGround", balloon = FALSE
400
)
401

    
402
system(paste("gdal_translate -of KMLSUPEROVERLAY ",mod35c5@file@name," output/mod35c5.kmz -co FORMAT=JPEG"))
403

    
404
logo = "http://static.tumblr.com/t0afs9f/KWTm94tpm/yale_logo.png"
405
kml_screen(image.file = logo, position = "UL", sname = "YALE logo",size=c(.1,.1))
406
kml_close("modiscloud.kml")
407
kml_compress("modiscloud.kml",files=c(paste(month.name,".png",sep=""),"obj_legend.png"),zip="/usr/bin/zip")
(22-22/43)