1 |
3682f238
|
Adam M. Wilson @ pfe
|
#### Script to facilitate processing of MOD06 data
|
2 |
|
|
|
3 |
|
|
setwd("/nobackupp1/awilso10/mod06")
|
4 |
0bddce86
|
Adam M. Wilson @ pfe
|
library(rgdal)
|
5 |
|
|
library(raster)
|
6 |
3682f238
|
Adam M. Wilson @ pfe
|
|
7 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
## get MODLAND tile information
|
8 |
|
|
tb=read.table("http://landweb.nascom.nasa.gov/developers/sn_tiles/sn_bound_10deg.txt",skip=6,nrows=648,header=T)
|
9 |
|
|
tb$tile=paste("h",sprintf("%02d",tb$ih),"v",sprintf("%02d",tb$iv),sep="")
|
10 |
807fa48c
|
Adam M. Wilson @ pfe
|
save(tb,file="modlandTiles.Rdata")
|
11 |
3682f238
|
Adam M. Wilson @ pfe
|
|
12 |
2c238837
|
Adam M. Wilson @ pfe
|
outdir="2_daily" #directory for separate daily files
|
13 |
|
|
outdir2="3_summary" #directory for combined daily files and summarized files
|
14 |
|
|
|
15 |
|
|
## load a MOD11A1 file to define grid
|
16 |
|
|
gridfile=list.files("/nobackupp4/datapool/modis/MOD11A1.005/2006.01.27/",pattern=paste(tile,".*hdf$",sep=""),full=T)[1]
|
17 |
|
|
td=readGDAL(paste("HDF4_EOS:EOS_GRID:\"",gridfile,"\":MODIS_Grid_Daily_1km_LST:Night_view_angl",sep=""))
|
18 |
|
|
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 "
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
### get list of files to process
|
22 |
|
|
datadir="/nobackupp4/datapool/modis/MOD06_L2.005/"
|
23 |
|
|
|
24 |
|
|
fs=data.frame(path=list.files(datadir,full=T,recursive=T,pattern="hdf"),stringsAsFactors=F)
|
25 |
|
|
fs$file=basename(fs$path)
|
26 |
|
|
fs$date=as.Date(substr(fs$file,11,17),"%Y%j")
|
27 |
|
|
fs$month=format(fs$date,"%m")
|
28 |
|
|
fs$year=format(fs$date,"%Y")
|
29 |
|
|
fs$time=substr(fs$file,19,22)
|
30 |
|
|
fs$datetime=as.POSIXct(strptime(paste(substr(fs$file,11,17),substr(fs$file,19,22)), '%Y%j %H%M'))
|
31 |
|
|
fs$dateid=format(fs$date,"%Y%m%d")
|
32 |
|
|
fs$path=as.character(fs$path)
|
33 |
|
|
fs$file=as.character(fs$file)
|
34 |
|
|
|
35 |
|
|
## get all unique dates
|
36 |
|
|
alldates=unique(fs$dateid)
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
#### Generate submission file
|
40 |
|
|
## identify which have been completed
|
41 |
|
|
done=alldates%in%substr(list.files(outdir),7,14)
|
42 |
|
|
table(done)
|
43 |
|
|
notdone=alldates[!done] #these are the dates that still need to be processed
|
44 |
|
|
|
45 |
07f76f37
|
Adam M. Wilson @ pfe
|
if(exists("fdly")){
|
46 |
|
|
notdone=notdone[notdone%in%fdly$dateid[is.na(fdly$npar)]]
|
47 |
|
|
|
48 |
|
|
|
49 |
2c238837
|
Adam M. Wilson @ pfe
|
tile="h11v08" #can move this to submit script if needed
|
50 |
|
|
script="/u/awilso10/environmental-layers/climate/procedures/MOD06_L2_process.r"
|
51 |
07f76f37
|
Adam M. Wilson @ pfe
|
write.table(paste("--verbose ",script," --date ",notdone," --tile \"",tile,"\"",sep=""),file="notdone.txt",row.names=F,col.names=F,quote=F)
|
52 |
0bddce86
|
Adam M. Wilson @ pfe
|
#write.table(paste("--verbose ",script," date=",notdone[1:30],sep=""),file="notdone.txt",row.names=F,col.names=F,quote=F)
|
53 |
07f76f37
|
Adam M. Wilson @ pfe
|
#write.table(notdone[1:30],file="notdone.txt",row.names=F,col.names=F,quote=F)
|
54 |
2c238837
|
Adam M. Wilson @ pfe
|
|
55 |
|
|
save(fs,alldates,gridfile,td,file="allfiles.Rdata")
|
56 |
|
|
|
57 |
0bddce86
|
Adam M. Wilson @ pfe
|
## run script
|
58 |
07f76f37
|
Adam M. Wilson @ pfe
|
#cat(paste("
|
59 |
|
|
##! /bin/bash
|
60 |
|
|
#source ~/moduleload
|
61 |
|
|
#source ~/.bashrc
|
62 |
|
|
#Rscript --verbose --vanilla /u/awilso10/environmental-layers/climate/procedures/MOD06_L2_process.r date=$1
|
63 |
0bddce86
|
Adam M. Wilson @ pfe
|
#Rscript --verbose --vanilla rtest
|
64 |
07f76f37
|
Adam M. Wilson @ pfe
|
#",sep=""),file="MOD06_process2")
|
65 |
|
|
#system("chmod +x MOD06_process2")
|
66 |
0bddce86
|
Adam M. Wilson @ pfe
|
|
67 |
07f76f37
|
Adam M. Wilson @ pfe
|
#cat(paste("
|
68 |
|
|
#library(rgdal)
|
69 |
|
|
#GDALinfo
|
70 |
|
|
#",sep=""),file="rtest")
|
71 |
0bddce86
|
Adam M. Wilson @ pfe
|
|
72 |
|
|
|
73 |
2c238837
|
Adam M. Wilson @ pfe
|
## Submission script
|
74 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
75 |
07f76f37
|
Adam M. Wilson @ pfe
|
#cat(paste("
|
76 |
|
|
##PBS -S /bin/bash
|
77 |
|
|
##PBS -l select=2:ncpus=16:model=san
|
78 |
|
|
####PBS -l select=4:ncpus=8:model=neh
|
79 |
|
|
###PBS -l select=1:ncpus=12:model=wes
|
80 |
|
|
######## old: select=48:ncpus=8:mpiprocs=8:model=neh
|
81 |
|
|
##PBS -l walltime=2:00:00
|
82 |
|
|
##PBS -j oe
|
83 |
|
|
##PBS -m e
|
84 |
|
|
##PBS -V
|
85 |
|
|
##PBS -q devel
|
86 |
|
|
##PBS -o log/log_^array_index^
|
87 |
|
|
##PBS -o log/log_DataCompile.log
|
88 |
|
|
##PBS -M adam.wilson@yale.edu
|
89 |
|
|
##PBS -N MOD06
|
90 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
91 |
|
|
## cd to working directory
|
92 |
07f76f37
|
Adam M. Wilson @ pfe
|
#cd /nobackupp1/awilso10/mod06
|
93 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
94 |
|
|
## set some memory limits
|
95 |
|
|
# ulimit -d 1500000 -m 1500000 -v 1500000 #limit memory usage
|
96 |
07f76f37
|
Adam M. Wilson @ pfe
|
# source /usr/local/lib/global.profile
|
97 |
|
|
# source /u/awilso10/.bashrc
|
98 |
|
|
# source /u/awilso10/moduleload
|
99 |
|
|
### export a few important variables
|
100 |
|
|
# export NNODES=32
|
101 |
|
|
# export R_LIBS=\"/u/awilso10/R/x86_64-unknown-linux-gnu-library/2.15/\"
|
102 |
|
|
### Run the script!
|
103 |
92fd8a10
|
Adam M. Wilson @ pfe
|
## current version not parallelizing across nodes!
|
104 |
0bddce86
|
Adam M. Wilson @ pfe
|
# TMPDIR=$TMPDIR Rscript --verbose --vanilla /u/awilso10/environmental-layers/climate/procedures/MOD06_L2_process.r date=20000403
|
105 |
2c238837
|
Adam M. Wilson @ pfe
|
|
106 |
07f76f37
|
Adam M. Wilson @ pfe
|
#WORKLIST=notdone.txt
|
107 |
|
|
##EXE=\"Rscript\"
|
108 |
|
|
#EXE="./MOD06_process2"
|
109 |
|
|
#LOG=log/log_DataCompile.log
|
110 |
|
|
#MQUEUE=/nobackupp4/pvotava/software/share/mqueue-eg/mqueue/mqueue
|
111 |
|
|
|
112 |
|
|
#TMPDIR=$TMPDIR mpiexec -np $NNODES $MQUEUE -l $WORKLIST -p $EXE -v -v -v --random-starts 2-4 --work-analyze #> $LOG
|
113 |
|
|
#exit 0
|
114 |
|
|
#",sep=""),file="MOD06_process")
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
### simplified qsub script
|
118 |
|
|
cat(paste("
|
119 |
|
|
#PBS -S /bin/bash
|
120 |
|
|
#PBS -l select=48:ncpus=8:mpiprocs=8
|
121 |
|
|
##PBS -l select=2:ncpus=4:mpiprocs=4
|
122 |
|
|
#PBS -l walltime=02:00:00
|
123 |
|
|
#PBS -j n
|
124 |
|
|
#PBS -m be
|
125 |
|
|
#PBS -N mod06
|
126 |
|
|
#PBS -q devel
|
127 |
|
|
#PBS -V
|
128 |
|
|
|
129 |
|
|
CORES=384
|
130 |
|
|
HDIR=/u/armichae/pr/
|
131 |
|
|
source $HDIR/etc/environ.sh
|
132 |
|
|
source /u/awilso10/.bashrc
|
133 |
|
|
IDIR=/nobackupp1/awilso10/mod06/
|
134 |
|
|
##WORKLIST=$HDIR/var/run/pxrRgrs/work.txt
|
135 |
|
|
WORKLIST=$IDIR/notdone.txt
|
136 |
|
|
EXE=Rscript
|
137 |
|
|
LOGSTDOUT=$IDIR/log/log.stdout
|
138 |
|
|
LOGSTDERR=$IDIR/log/log.stderr
|
139 |
|
|
mpiexec -np $CORES pxargs -a $WORKLIST -p $EXE -v -v -v --work-analyze 1> $LOGSTDOUT 2> $LOGSTDERR
|
140 |
|
|
"),file="mod06_qsub")
|
141 |
827b4b87
|
Adam M. Wilson @ pfe
|
|
142 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
143 |
|
|
### Check the file
|
144 |
07f76f37
|
Adam M. Wilson @ pfe
|
system("cat mod06_qsub")
|
145 |
807fa48c
|
Adam M. Wilson @ pfe
|
#system("cat ~/environmental-layers/climate/procedures/MOD06_L2_process.r")
|
146 |
|
|
|
147 |
92fd8a10
|
Adam M. Wilson @ pfe
|
## check queue status
|
148 |
|
|
system("/u/scicon/tools/bin/node_stats.sh")
|
149 |
0bddce86
|
Adam M. Wilson @ pfe
|
system("/u/scicon/tools/bin/qtop.pl 492352")
|
150 |
92fd8a10
|
Adam M. Wilson @ pfe
|
|
151 |
807fa48c
|
Adam M. Wilson @ pfe
|
## Submit it (and keep the pid)!
|
152 |
07f76f37
|
Adam M. Wilson @ pfe
|
system("qsub mod06_qsub")
|
153 |
|
|
system("/u/scicon/tools/bin/pdsh_gdb -j 568835 -d tmp -s -u awilso10")
|
154 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
155 |
807fa48c
|
Adam M. Wilson @ pfe
|
## work in interactive mode
|
156 |
827b4b87
|
Adam M. Wilson @ pfe
|
# system("qsub -I -l walltime=2:00:00 -lselect=2:ncpus=16:model=san -q devel")
|
157 |
|
|
# mpirun -np 1 -r ssh R --no-save
|
158 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
159 |
|
|
## check progress
|
160 |
|
|
system("qstat -u awilso10")
|
161 |
07f76f37
|
Adam M. Wilson @ pfe
|
system(paste("/u/scicon/tools/bin/qps ",568835))
|
162 |
807fa48c
|
Adam M. Wilson @ pfe
|
system(paste("qstat -t -x",pid))
|
163 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
164 |
807fa48c
|
Adam M. Wilson @ pfe
|
system("qstat devel ")
|
165 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
#system("qstat | grep awilso10")
|
166 |
|
|
|
167 |
2c238837
|
Adam M. Wilson @ pfe
|
####################################
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
################################################################################
|
171 |
|
|
## now generate the climatologies
|
172 |
|
|
fdly=data.frame(
|
173 |
|
|
path=list.files(outdir,pattern="nc$",full=T),
|
174 |
|
|
file=list.files(outdir,pattern="nc$"))
|
175 |
07f76f37
|
Adam M. Wilson @ pfe
|
fdly$dateid=substr(fdly$file,7,14)
|
176 |
|
|
fdly$date=as.Date(substr(fdly$file,7,14),"%Y%m%d")
|
177 |
|
|
fdly$month=format(fdly$date,"%m")
|
178 |
|
|
fdly$year=format(fdly$date,"%Y")
|
179 |
2c238837
|
Adam M. Wilson @ pfe
|
|
180 |
|
|
## check validity (via npar and ntime) of nc files
|
181 |
|
|
for(i in 1:nrow(fdly)){
|
182 |
07f76f37
|
Adam M. Wilson @ pfe
|
# fdly$ntime[i]<-as.numeric(system(paste("cdo sinfo ",fdly$path[i]),intern=T))
|
183 |
|
|
fdly$npar[i]<-as.numeric(system(paste("cdo -s npar ",fdly$path[i]),intern=T))
|
184 |
2c238837
|
Adam M. Wilson @ pfe
|
print(i)
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
## Combine all days within years into a single file (can't mergetime all days at once because this opens too many files)
|
188 |
|
|
tsdir=paste(tempdir(),"/summary",sep="")
|
189 |
|
|
dir.create(tsdir)
|
190 |
|
|
lapply(unique(fdly$year),function(y){
|
191 |
07f76f37
|
Adam M. Wilson @ pfe
|
system(paste("cdo -O mergetime ",paste(fdly$path[!is.na(fdly$npar)&fdly$year==y],collapse=" ")," ",tsdir,"/MOD09_",tile,"_",y,"_daily.nc",sep=""))
|
192 |
2c238837
|
Adam M. Wilson @ pfe
|
print(paste("Finished merging daily files for year",y))
|
193 |
|
|
})
|
194 |
|
|
## Combine the year-by-year files into a single daily file
|
195 |
|
|
system(paste("cdo -O mergetime ",paste(list.files(tsdir,full=T,pattern="daily[.]nc$"),collapse=" ")," ",outdir2,"/MOD09_",tile,"_daily.nc",sep=""))
|
196 |
|
|
|
197 |
|
|
system(paste("cdo -O monmean ",outdir2,"/MOD09_",tile,"_daily.nc ",outdir2,"/",tile,"_monmean.nc",sep=""))
|
198 |
|
|
system(paste("cdo -O ymonmean ",outdir2,"/MOD09_",tile,"_daily.nc ",outdir2,"/",tile,"_ymonmean.nc",sep=""))
|
199 |
|
|
system(paste("cdo -O ymonstd ",outdir2,"/MOD09_",tile,"_daily.nc ",outdir2,"/",tile,"_ymonstd.nc",sep=""))
|
200 |
|
|
|
201 |
|
|
print("Finished! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
|
202 |
|
|
## quit R
|
203 |
07f76f37
|
Adam M. Wilson @ pfe
|
#q("no")
|
204 |
2c238837
|
Adam M. Wilson @ pfe
|
|
205 |
|
|
|
206 |
|
|
#################################################################
|
207 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
208 |
807fa48c
|
Adam M. Wilson @ pfe
|
### copy the files back to Yale
|
209 |
3959e686
|
Adam M. Wilson @ pfe
|
list.files("2_daily")
|
210 |
07f76f37
|
Adam M. Wilson @ pfe
|
system(paste("scp ",outdir2,"/*_ymonmean.nc adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/Venezuela/summary",sep=""))
|
211 |
3959e686
|
Adam M. Wilson @ pfe
|
|
212 |
|
|
system("scp /tmp/Rtmp6I6tFn/MOD06_L2.A2000061.1615.051.2010273184629.hdf adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/Venezuela")
|
213 |
|
|
system("scp 2_daily/MOD06_20000410.nc adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/Venezuela")
|
214 |
cf724805
|
Adam M. Wilson @ pfe
|
|
215 |
|
|
|
216 |
2c238837
|
Adam M. Wilson @ pfe
|
|
217 |
|
|
|
218 |
|
|
|