Project

General

Profile

« Previous | Next » 

Revision 4f97017d

Added by Adam M. Wilson over 12 years ago

added processing for 'very cloudy days'

View differences:

.gitignore
1 1
*.Rhistory
2 2
*.Rdata
3
*[~]
3
*[~]
4
*[#]*
climate/procedures/MOD06_L2_data_compile.r
19 19
library(hdf5)
20 20
library(spgrass6)
21 21

  
22

  
23
### set options for Raster Package
24
setOptions(progress="text",timer=T)
25

  
22 26
X11.options(type="Xlib")
23 27
ncores=20  #number of threads to use
24 28

  
......
319 323

  
320 324
## process the summaries using the raster package
321 325
mclapply(1:nrow(vs),function(i){
322
  print(paste("Starting ",vs$type[i]," for month ",vs$month[i]))
326
  print(paste("Loading ",vs$type[i]," for month ",vs$month[i]))
323 327
  td=stack(fs2$path[which(fs2$month==vs$month[i]&fs2$type==vs$type[i])])
324 328
  print(paste("Processing Metric ",vs$type[i]," for month ",vs$month[i]))
325 329
  calc(td,mean,na.rm=T,
......
328 332
  calc(td,sd,na.rm=T,
329 333
       filename=paste(summarydatadir,"/",vs$type[i],"_sd_",vs$month[i],".tif",sep=""),
330 334
       format="GTiff")
331
  if(vs$type[i]%in%c("CER","COT")) {
332
    ## also produce means that first eliminate 0 values (added above to indicate clear skies)
333
    ## to capture 'when cloudy, how thick are the clouds' rather than mean thickness...
334
    td2=td
335
    td2[td2==0]=NA
336
    calc(td2,mean,na.rm=T,
337
         filename=paste(summarydatadir,"/",vs$type[i],"_meanno0_",vs$month[i],".tif",sep=""),
338
         format="GTiff")
335
  if(vs$type[i]%in%c("CER")) {
336
    ## Calculate number of days with effective radius > 20um, found to be linked to precipitating clouds
337
    ## (Kobayashi 2007)
338
    calc(td,function(x) mean(ifelse(x<20,0,1),na.rm=T),
339
      filename=paste(summarydatadir,"/",vs$type[i],"_P20um_",vs$month[i],".tif",sep=""),
340
      format="GTiff")
341
#    td2[td2<20]=0
342
#    td2[td2>=20]=1
343
#    calc(td2,mean,na.rm=T,
344
#         filename=paste(summarydatadir,"/",vs$type[i],"_P20um_",vs$month[i],".tif",sep=""),
345
#         format="GTiff")
339 346
  }  
340 347
  print(paste("Processing missing data for ",vs$type[i]," for month ",vs$month[i]))
341 348
  calc(td,function(i)
climate/procedures/MOD06_L2_data_summary.r
154 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 155
mod06s$gelev=cut(mod06s$elev,breaks=gq(mod06s$elev,n=3),labels=c("Low","Mid","High"),include.lowest=T,ordered=T)
156 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

  
157
mod06s$LWP_mean=(2/3)*mod06s$CER_mean*mod06s$COT_mean
158 158

  
159 159
## melt it
160 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 (%)")
161
levels(mod06sl$variable)=c("Effective Radius (um)","Cloudy Days (%)","Optical Thickness (%)","Liquid Water Path")
162 162

  
163 163
###################################################################
164 164
###################################################################
165 165

  
166 166
bgyr=colorRampPalette(c("blue","green","yellow","red"))
167 167

  
168
X11.options(type="cairo")
168 169
pdf("output/MOD06_summary.pdf",width=11,height=8.5)
169 170

  
170 171
# % cloudy maps
......
243 244

  
244 245
## ppt~metric with longitude bins
245 246
 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))+
247
       scales=list(y=list(log=T),x=list(relation="free",log=F)),
248
       par.settings = list(superpose.symbol = list(col=bgyr(5),pch=16,cex=.5)),auto.key=list(space="top",title="Station Longitude"),
249
       main="Comparison of MOD06_L2 and Precipitation Monthly Climatologies",ylab="Mean Monthly Station Precipitation (mm)",xlab="MOD06_L2 Product",layout=c(4,1))+
249 250
  layer(panel.text(9,2.5,label="Coastal stations",srt=30,cex=1.3,col="blue"),columns=1)+
250 251
  layer(panel.text(13,.9,label="Inland stations",srt=10,cex=1.3,col="red"),columns=1)
251 252

  
253
## ppt~metric with longitude bins
254
#CairoPNG("output/COT.png",width=10,height=5,units="in",dpi=300,pointsize=20)
255
#png("output/COT.png",width=10,height=5,units="in",res=150)
256
#trellis.par.set("fontsize",12)
257
at=quantile(as.matrix(subset(m01,subset=3)),seq(0,1,len=100),na.rm=T)
258
p1=levelplot(subset(m01,subset=3),xlab.top="Optical Thickness (%)",at=at,col.regions=bgyr(length(at)),margin=F,
259
   )+layer(sp.lines(roi_geo, lwd=1.2, col='black'))+layer(sp.points(st2, cex=.5,col='black'))
260
at=quantile(as.matrix(subset(m01,subset=4)),seq(0,1,len=100),na.rm=T)
261
p2=levelplot(subset(m01,subset=4),xlab.top="PRISM MAP",at=at,col.regions=bgyr(length(at)),margin=F,
262
    )+layer(sp.lines(roi_geo, lwd=1.2, col='black'))+layer(sp.points(st2, cex=.5, col='black'))
263

  
264
p3=xyplot(ppt~value,groups=glon,data=mod06sl[mod06sl$variable=="Optical Thickness (%)",],
265
       scales=list(y=list(log=T),x=list(relation="free",log=F)),
266
       par.settings = list(superpose.symbol = list(col=bgyr(5),pch=16,cex=.3)),auto.key=list(space="right",title="Station \n Longitude"),
267
ylab="Mean Monthly Station Precipitation (mm)",xlab="Cloud Optical Thickness from MOD06_L2 (%)",layout=c(1,1))+
268
  layer(panel.text(9,2.6,label="Coastal stations",srt=10,cex=1.3,col="blue"),columns=1)+
269
  layer(panel.text(13,.95,label="Inland stations",srt=10,cex=1.3,col="red"),columns=1)
270

  
271
save(p1,p2,p3,file="plotdata.Rdata")
272
load("plotdata.Rdata")
273

  
274
CairoPDF("output/MOD06_Summaryfig.pdf",width=11,height=8.5)
275
print(p3,position=c(0,0,1,.5),save.object=F)
276
print(p1,split=c(1,1,2,2),new=F)
277
print(p2,split=c(2,1,2,2),new=F)
278
dev.off()
279
system("convert output/MOD06_Summaryfig.pdf output/MOD06_Summaryfig.png")
280
                                        #dev.off()
281

  
252 282
## with elevation
253 283
# xyplot(ppt~value|variable,groups=gbin,data=mod06sl,
254 284
#       scales=list(y=list(log=T),x=list(relation="free")),
......
295 325
        ylab="Precipitation (mm, log axis)",xlab="Mean Monthly Cloud Optical Thickness (%)")+
296 326
  layer(panel.text(10,.5,round(summary(lm(y~x))$r.squared,2),pos=4,cex=.75,col="grey"))
297 327

  
328
 xyplot(ppt~LWP_mean|id,data=mod06s,panel=function(x,y,group){
329
  panel.xyplot(x,y,type=c("r"),cex=.5,pch=16,col="red")
330
  panel.xyplot(x,y,type=c("p"),cex=.5,pch=16,col="black")
331
} ,scales=list(y=list(log=T)),strip=F,main="Monthly Mean Precipitation and Liquid Water Path by station",
332
        sub="Each panel is a station, each point is a monthly mean \n Number in lower right of each panel is R^2",
333
        ylab="Precipitation (mm, log axis)",xlab="Mean Monthly Liquid Water Path")+
334
  layer(panel.text(10,.5,round(summary(lm(y~x))$r.squared,2),pos=4,cex=.75,col="grey"))
298 335

  
299 336
### Calculate the slope of each line
300 337
mod06s.sl=dapply(mod06s,list(id=mod06s$id),function(x){

Also available in: Unified diff