1
|
#### Script to facilitate processing of MOD06 data
|
2
|
|
3
|
|
4
|
setwd("/nobackupp1/awilso10/mod06")
|
5
|
|
6
|
### get list of files to process
|
7
|
datadir="/nobackupp4/datapool/modis/MOD06_L2.005/"
|
8
|
|
9
|
fs=data.frame(
|
10
|
path=list.files(datadir,full=T,recursive=T,pattern="hdf"),
|
11
|
file=basename(list.files(datadir,full=F,recursive=T,pattern="hdf")))
|
12
|
fs$date=as.Date(substr(fs$file,11,17),"%Y%j")
|
13
|
fs$month=format(fs$date,"%m")
|
14
|
fs$year=format(fs$date,"%Y")
|
15
|
fs$time=substr(fs$file,19,22)
|
16
|
fs$datetime=as.POSIXct(strptime(paste(substr(fs$file,11,17),substr(fs$file,19,22)), '%Y%j %H%M'))
|
17
|
fs$dateid=format(fs$date,"%Y%m%d")
|
18
|
fs$path=as.character(fs$path)
|
19
|
fs$file=as.character(fs$file)
|
20
|
|
21
|
## get all unique dates
|
22
|
alldates=unique(fs$dateid)
|
23
|
|
24
|
|
25
|
## get MODLAND tile information
|
26
|
tb=read.table("http://landweb.nascom.nasa.gov/developers/sn_tiles/sn_bound_10deg.txt",skip=6,nrows=648,header=T)
|
27
|
tb$tile=paste("h",sprintf("%02d",tb$ih),"v",sprintf("%02d",tb$iv),sep="")
|
28
|
### use MODIS tile as ROI
|
29
|
#modt=readOGR("modgrid","modis_sinusoidal_grid_world",)
|
30
|
#modt@data[,colnames(tb)[3:6]]=tb[match(paste(modt$h,modt$v),paste(tb$ih,tb$iv)),3:6]
|
31
|
#write.csv(modt@data,file="modistile.csv")
|
32
|
|
33
|
|
34
|
## write it out
|
35
|
save(fs,tb,file="allfiles.Rdata")
|
36
|
#save(alldates,file="alldates.Rdata")
|
37
|
|
38
|
## identify which have been completed
|
39
|
outdir="2_daily"
|
40
|
done=alldates%in%substr(list.files(outdir),5,12)
|
41
|
table(done)
|
42
|
notdone=alldates[!done]
|
43
|
|
44
|
#notdone=alldates[1:4]
|
45
|
|
46
|
save(notdone,file="notdone.Rdata")
|
47
|
|
48
|
|
49
|
## vars
|
50
|
vars=as.data.frame(matrix(c(
|
51
|
"Cloud_Effective_Radius", "CER",
|
52
|
"Cloud_Effective_Radius_Uncertainty", "CERU",
|
53
|
"Cloud_Optical_Thickness", "COT",
|
54
|
"Cloud_Optical_Thickness_Uncertainty", "COTU",
|
55
|
"Cloud_Water_Path", "CWP",
|
56
|
"Cloud_Water_Path_Uncertainty", "CWPU",
|
57
|
"Cloud_Phase_Optical_Properties", "CPOP",
|
58
|
"Cloud_Multi_Layer_Flag", "CMLF",
|
59
|
"Cloud_Mask_1km", "CM1",
|
60
|
"Quality_Assurance_1km", "QA"),
|
61
|
byrow=T,ncol=2,dimnames=list(1:10,c("variable","varid"))),stringsAsFactors=F)
|
62
|
save(vars,file="vars.Rdata")
|
63
|
|
64
|
|
65
|
### Submission script
|
66
|
|
67
|
cat(paste("
|
68
|
#PBS -S /bin/sh
|
69
|
#PBS -J 700-899
|
70
|
###PBS -J 1-",length(notdone),"
|
71
|
#PBS -l walltime=0:10:00
|
72
|
#PBS -l ncpus=100
|
73
|
#PBS -j oe
|
74
|
#PBS -o log/log_^array_index^
|
75
|
#PBS -m e
|
76
|
#PBS -M adam.wilson@yale.edu
|
77
|
#PBS -N MOD06
|
78
|
|
79
|
## cd to working directory
|
80
|
cd /nobackupp1/awilso10/mod06
|
81
|
|
82
|
## set some memory limits
|
83
|
# ulimit -d 1500000 -m 1500000 -v 1500000 #limit memory usage
|
84
|
source /usr/local/lib/global.profile
|
85
|
## export a few important variables
|
86
|
export PATH=$PATH:/nobackupp1/awilso10/bin:/nobackupp1/awilso10/software/bin
|
87
|
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/nobackupp1/awilso10/software/lib
|
88
|
export MRTDATADIR=/nobackupp1/awilso10/software/heg/data
|
89
|
export PGSHOME=/nobackupp1/awilso10/software/heg
|
90
|
export MRTBINDIR=/nobackup1/awilso10/software/TOOLKIT_MTD
|
91
|
export R_LIBS=\"/u/awilso10/R/x86_64-unknown-linux-gnu-library/2.15/\"
|
92
|
## load modules
|
93
|
module load gcc mpi-sgi/mpt.2.06r6 hdf4 udunits R
|
94
|
## Run the script!
|
95
|
Rscript --verbose --vanilla /u/awilso10/environmental-layers/climate/procedures/MOD06_L2_data_compile_Pleiades.r i=${PBS_ARRAY_INDEX}
|
96
|
rm -r $TMPDIR
|
97
|
exit 0
|
98
|
",sep=""),file="MOD06_process")
|
99
|
|
100
|
### Check the file
|
101
|
system("cat MOD06_process")
|
102
|
#system("chmod +x MOD06_process")
|
103
|
|
104
|
## Submit it!
|
105
|
#system("qsub -q devel MOD06_process")
|
106
|
system("qsub MOD06_process")
|
107
|
|
108
|
## check progress
|
109
|
system("qstat -u awilso10")
|
110
|
system("qstat -t 391843[]")
|
111
|
system("qstat -f 391843[2]")
|
112
|
|
113
|
#system("qstat devel ")
|
114
|
#system("qstat | grep awilso10")
|
115
|
|
116
|
#print(paste(max(0,length(system("qstat",intern=T))-2)," processes running"))
|
117
|
# system("ssh c0-8.farm.caes.ucdavis.edu")
|
118
|
# system("qalter -p +1024 25964") #decrease priority of job to run extraction below.
|
119
|
system("cat log/InterpScript.o55934.2")
|
120
|
|
121
|
## check log
|
122
|
system(paste("cat",list.files("log",pattern="InterpScript",full=T)[100]))
|
123
|
#system(paste("cat",list.files("log",pattern="InterpScript",full=T)[13]," | grep \"Temporary Directory\""))
|