Revision f27b378d
Added by Adam Wilson over 11 years ago
climate/procedures/MOD06_L2_process.r | ||
---|---|---|
34 | 34 |
} |
35 | 35 |
|
36 | 36 |
|
37 |
## default date and tile to play with |
|
37 |
## default date and tile to play with (will be overwritten below when running in batch)
|
|
38 | 38 |
date="20030102" |
39 | 39 |
tile="h11v08" |
40 | 40 |
platform="pleiades" |
... | ... | |
47 | 47 |
outdir=paste("daily/",tile,"/",sep="") #directory for separate daily files |
48 | 48 |
|
49 | 49 |
|
50 |
if(platform="pleiades"){ |
|
50 |
## get year and doy from date |
|
51 |
year=format(as.Date(date,"%Y%m%d"),"%Y") |
|
52 |
doy=format(as.Date(date,"%Y%m%d"),"%j") |
|
53 |
|
|
54 |
if(platform=="pleiades"){ |
|
51 | 55 |
## location of MOD06 files |
52 |
datadir="/nobackupp4/datapool/modis/MOD06_L2.005/"
|
|
56 |
datadir=paste("/nobackupp4/datapool/modis/MOD06_L2.005/",year,"/",doy,"/",sep="")
|
|
53 | 57 |
## path to some executables |
54 | 58 |
ncopath="/nasa/sles11/nco/4.0.8/gcc/mpt/bin/" |
55 | 59 |
swtifpath="/nobackupp1/awilso10/software/heg/bin/swtif" |
... | ... | |
64 | 68 |
projection(td)="+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs +datum=WGS84 +ellps=WGS84 " |
65 | 69 |
} |
66 | 70 |
|
67 |
if(platform="litoria"){ #if running on local server, use different paths |
|
71 |
if(platform=="litoria"){ #if running on local server, use different paths
|
|
68 | 72 |
## specify working directory |
69 | 73 |
setwd("~/acrobates/projects/interp") |
70 | 74 |
gisBase="/usr/lib/grass64" |
... | ... | |
97 | 101 |
"Cloud_Effective_Radius_Uncertainty", "CERU", |
98 | 102 |
"Cloud_Optical_Thickness", "COT", |
99 | 103 |
"Cloud_Optical_Thickness_Uncertainty", "COTU", |
100 |
"Cloud_Water_Path", "CWP", |
|
101 |
"Cloud_Water_Path_Uncertainty", "CWPU", |
|
102 |
"Cloud_Phase_Optical_Properties", "CPOP", |
|
103 |
"Cloud_Multi_Layer_Flag", "CMLF", |
|
104 |
# "Cloud_Water_Path", "CWP",
|
|
105 |
# "Cloud_Water_Path_Uncertainty", "CWPU",
|
|
106 |
# "Cloud_Phase_Optical_Properties", "CPOP",
|
|
107 |
# "Cloud_Multi_Layer_Flag", "CMLF",
|
|
104 | 108 |
"Cloud_Mask_1km", "CM1", |
105 | 109 |
"Quality_Assurance_1km", "QA"), |
106 |
byrow=T,ncol=2,dimnames=list(1:10,c("variable","varid"))),stringsAsFactors=F)
|
|
110 |
byrow=T,ncol=2,dimnames=list(1:6,c("variable","varid"))),stringsAsFactors=F)
|
|
107 | 111 |
|
108 | 112 |
## vector of variables expected to be in final netcdf file. If these are not present, the file will be deleted at the end. |
109 | 113 |
finalvars=c("CER","COT","CLD") |
... | ... | |
241 | 245 |
CM_clear_",i," = ((CM1_",i," / 2^0) % 2) == 1 && ((CM1_",i," / 2^1) % 2^2) > 2 |
242 | 246 |
CM_path_",i," = ((CM1_",i," / 2^6) % 2^2) |
243 | 247 |
CM_cloud2_",i," = ((CM1_",i," / 2^1) % 2^2) |
244 |
|
|
245 | 248 |
EOF",sep="")) |
249 |
## Set CM_cloud2 to null if it is "01" (uncertain) |
|
250 |
# execGRASS("r.null",map=paste("CM_cloud2_",i,sep=""),setnull="-9999,1") |
|
246 | 251 |
|
247 | 252 |
## QA |
248 | 253 |
execGRASS("r.in.gdal",input=paste("HDF4_EOS:EOS_GRID:\"",file,"\":mod06:Quality_Assurance_1km_0",sep=""), |
... | ... | |
309 | 314 |
CER2_denom=",paste("!isnull(CER2_",1:nfs,")",sep="",collapse="+")," |
310 | 315 |
CER2_daily=int(CER2_numer/CER2_denom) |
311 | 316 |
CLD_daily=int((max(",paste("if(isnull(CM_cloud_",1:nfs,"),-9999,CM_cloud_",1:nfs,")",sep="",collapse=","),"))) |
317 |
CLD2_daily=int((min(",paste("if(isnull(CM_cloud2_",1:nfs,"),-9999,CM_cloud2_",1:nfs,")",sep="",collapse=","),"))) |
|
312 | 318 |
EOF",sep="")) |
313 |
execGRASS("r.null",map="CLD_daily",setnull="-9999") |
|
319 |
|
|
320 |
execGRASS("r.null",map="CLD_daily",setnull="-9999") |
|
321 |
execGRASS("r.null",map="CLD2_daily",setnull="-9999") |
|
314 | 322 |
|
315 | 323 |
|
316 | 324 |
### Write the files to a netcdf file |
317 | 325 |
## create image group to facilitate export as multiband netcdf |
318 |
execGRASS("i.group",group="mod06",input=c("CER_daily","CER2_daily","COT_daily","COT2_daily","CLD_daily")) ; print("") |
|
326 |
execGRASS("i.group",group="mod06",input=c("CER_daily","CER2_daily","COT_daily","COT2_daily","CLD_daily","CLD2_daily")) ; print("")
|
|
319 | 327 |
|
320 | 328 |
if(file.exists(ncfile)) file.remove(ncfile) #if it exists already, delete it |
321 | 329 |
execGRASS("r.out.gdal",input="mod06",output=ncfile,type="Int16",nodata=-32768,flags=c("quiet"), |
... | ... | |
339 | 347 |
system(paste("ncgen -o ",tempdir(),"/time.nc ",tempdir(),"/time.cdl",sep="")) |
340 | 348 |
system(paste(ncopath,"ncks -A ",tempdir(),"/time.nc ",ncfile,sep="")) |
341 | 349 |
## add other attributes |
342 |
system(paste(ncopath,"ncrename -v Band1,CER -v Band2,CER2 -v Band3,COT -v Band4,COT2 -v Band5,CLD ",ncfile,sep="")) |
|
350 |
system(paste(ncopath,"ncrename -v Band1,CER -v Band2,CER2 -v Band3,COT -v Band4,COT2 -v Band5,CLD -v Band6,CLD2 ",ncfile,sep=""))
|
|
343 | 351 |
system(paste(ncopath,"ncatted -a scale_factor,CER,o,d,0.01 -a units,CER,o,c,\"micron\" -a missing_value,CER,o,d,-32768 -a long_name,CER,o,c,\"Cloud Particle Effective Radius\" ",ncfile,sep="")) |
344 | 352 |
system(paste(ncopath,"ncatted -a scale_factor,CER2,o,d,0.01 -a units,CER2,o,c,\"micron\" -a missing_value,CER2,o,d,-32768 -a long_name,CER2,o,c,\"Cloud Particle Effective Radius with clear sky set to zero\" ",ncfile,sep="")) |
345 | 353 |
|
346 | 354 |
system(paste(ncopath,"ncatted -a scale_factor,COT,o,d,0.01 -a units,COT,o,c,\"none\" -a missing_value,COT,o,d,-32768 -a long_name,COT,o,c,\"Cloud Optical Thickness\" ",ncfile,sep="")) |
347 | 355 |
system(paste(ncopath,"ncatted -a scale_factor,COT2,o,d,0.01 -a units,COT2,o,c,\"none\" -a missing_value,COT2,o,d,-32768 -a long_name,COT2,o,c,\"Cloud Optical Thickness with clear sky set to zero\" ",ncfile,sep="")) |
348 |
system(paste(ncopath,"ncatted -a scale_factor,CLD,o,d,0.01 -a units,CLD,o,c,\"none\" -a missing_value,CLD,o,d,-32768 -a long_name,CLD,o,c,\"Cloud Mask\" ",ncfile,sep="")) |
|
349 |
# system(paste(ncopath,"ncatted -a sourcecode,global,o,c,",script," ",ncfile,sep="")) |
|
356 |
system(paste(ncopath,"ncatted -a scale_factor,CLD,o,d,1 -a units,CLD,o,c,\"none\" -a missing_value,CLD,o,d,-32768 -a long_name,CLD,o,c,\"Cloud Mask\" ",ncfile,sep="")) |
|
357 |
system(paste(ncopath,"ncatted -a scale_factor,CLD2,o,d,1 -a units,CLD2,o,c,\"none\" -a missing_value,CLD2,o,d,-32768 -a long_name,CLD2,o,c,\"Cloud Mask Flag\" ",ncfile,sep="")) |
|
358 |
|
|
359 |
# system(paste(ncopath,"ncatted -a sourcecode,global,o,c,",script," ",ncfile,sep="")) |
|
350 | 360 |
|
351 | 361 |
|
352 | 362 |
### delete the temporary files |
Also available in: Unified diff
Updates to MOD06 Climatology Script and MDO06 processing to isolate the effects of the MOD35 -landcover bias