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 |
|
|
tile="h11v08" #can move this to submit script if needed
|
46 |
|
|
script="/u/awilso10/environmental-layers/climate/procedures/MOD06_L2_process.r"
|
47 |
|
|
#write.table(paste("--verbose ",script," date=",notdone," tile=\"",tile,"\"",sep=""),file="notdone.txt",row.names=F,col.names=F,quote=F)
|
48 |
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)
|
49 |
|
|
write.table(notdone[1:30],file="notdone.txt",row.names=F,col.names=F,quote=F)
|
50 |
2c238837
|
Adam M. Wilson @ pfe
|
|
51 |
|
|
save(fs,alldates,gridfile,td,file="allfiles.Rdata")
|
52 |
|
|
|
53 |
0bddce86
|
Adam M. Wilson @ pfe
|
## run script
|
54 |
|
|
cat(paste("
|
55 |
|
|
#! /bin/bash
|
56 |
|
|
source ~/moduleload
|
57 |
|
|
source ~/.bashrc
|
58 |
|
|
Rscript --verbose --vanilla /u/awilso10/environmental-layers/climate/procedures/MOD06_L2_process.r date=$1
|
59 |
|
|
#Rscript --verbose --vanilla rtest
|
60 |
|
|
",sep=""),file="MOD06_process2")
|
61 |
|
|
system("chmod +x MOD06_process2")
|
62 |
|
|
|
63 |
|
|
cat(paste("
|
64 |
|
|
library(rgdal)
|
65 |
|
|
GDALinfo
|
66 |
|
|
",sep=""),file="rtest")
|
67 |
|
|
|
68 |
|
|
|
69 |
2c238837
|
Adam M. Wilson @ pfe
|
## Submission script
|
70 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
71 |
|
|
cat(paste("
|
72 |
807fa48c
|
Adam M. Wilson @ pfe
|
#PBS -S /bin/bash
|
73 |
2c238837
|
Adam M. Wilson @ pfe
|
#PBS -l select=2:ncpus=16:model=san
|
74 |
92fd8a10
|
Adam M. Wilson @ pfe
|
###PBS -l select=4:ncpus=8:model=neh
|
75 |
827b4b87
|
Adam M. Wilson @ pfe
|
##PBS -l select=1:ncpus=12:model=wes
|
76 |
807fa48c
|
Adam M. Wilson @ pfe
|
####### old: select=48:ncpus=8:mpiprocs=8:model=neh
|
77 |
827b4b87
|
Adam M. Wilson @ pfe
|
#PBS -l walltime=2:00:00
|
78 |
3682f238
|
Adam M. Wilson @ pfe
|
#PBS -j oe
|
79 |
|
|
#PBS -m e
|
80 |
807fa48c
|
Adam M. Wilson @ pfe
|
#PBS -V
|
81 |
827b4b87
|
Adam M. Wilson @ pfe
|
#PBS -q devel
|
82 |
3959e686
|
Adam M. Wilson @ pfe
|
#PBS -o log/log_^array_index^
|
83 |
2c238837
|
Adam M. Wilson @ pfe
|
#PBS -o log/log_DataCompile.log
|
84 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
#PBS -M adam.wilson@yale.edu
|
85 |
|
|
#PBS -N MOD06
|
86 |
|
|
|
87 |
|
|
## cd to working directory
|
88 |
|
|
cd /nobackupp1/awilso10/mod06
|
89 |
|
|
|
90 |
|
|
## set some memory limits
|
91 |
|
|
# ulimit -d 1500000 -m 1500000 -v 1500000 #limit memory usage
|
92 |
2c238837
|
Adam M. Wilson @ pfe
|
source /usr/local/lib/global.profile
|
93 |
807fa48c
|
Adam M. Wilson @ pfe
|
source /u/awilso10/.bashrc
|
94 |
827b4b87
|
Adam M. Wilson @ pfe
|
source /u/awilso10/moduleload
|
95 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
## export a few important variables
|
96 |
2c238837
|
Adam M. Wilson @ pfe
|
export NNODES=32
|
97 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
export R_LIBS=\"/u/awilso10/R/x86_64-unknown-linux-gnu-library/2.15/\"
|
98 |
|
|
## Run the script!
|
99 |
92fd8a10
|
Adam M. Wilson @ pfe
|
## current version not parallelizing across nodes!
|
100 |
0bddce86
|
Adam M. Wilson @ pfe
|
# TMPDIR=$TMPDIR Rscript --verbose --vanilla /u/awilso10/environmental-layers/climate/procedures/MOD06_L2_process.r date=20000403
|
101 |
2c238837
|
Adam M. Wilson @ pfe
|
|
102 |
|
|
WORKLIST=notdone.txt
|
103 |
0bddce86
|
Adam M. Wilson @ pfe
|
#EXE=\"Rscript\"
|
104 |
|
|
EXE="./MOD06_process2"
|
105 |
2c238837
|
Adam M. Wilson @ pfe
|
LOG=log/log_DataCompile.log
|
106 |
0bddce86
|
Adam M. Wilson @ pfe
|
MQUEUE=/nobackupp4/pvotava/software/share/mqueue-eg/mqueue/mqueue
|
107 |
827b4b87
|
Adam M. Wilson @ pfe
|
|
108 |
0bddce86
|
Adam M. Wilson @ pfe
|
TMPDIR=$TMPDIR mpiexec -np $NNODES $MQUEUE -l $WORKLIST -p $EXE -v -v -v --random-starts 2-4 --work-analyze #> $LOG
|
109 |
2c238837
|
Adam M. Wilson @ pfe
|
exit 0
|
110 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
",sep=""),file="MOD06_process")
|
111 |
|
|
|
112 |
|
|
### Check the file
|
113 |
|
|
system("cat MOD06_process")
|
114 |
807fa48c
|
Adam M. Wilson @ pfe
|
#system("cat ~/environmental-layers/climate/procedures/MOD06_L2_process.r")
|
115 |
|
|
|
116 |
92fd8a10
|
Adam M. Wilson @ pfe
|
## check queue status
|
117 |
|
|
system("/u/scicon/tools/bin/node_stats.sh")
|
118 |
0bddce86
|
Adam M. Wilson @ pfe
|
system("/u/scicon/tools/bin/qtop.pl 492352")
|
119 |
92fd8a10
|
Adam M. Wilson @ pfe
|
|
120 |
807fa48c
|
Adam M. Wilson @ pfe
|
## Submit it (and keep the pid)!
|
121 |
827b4b87
|
Adam M. Wilson @ pfe
|
system("qsub MOD06_process")
|
122 |
0bddce86
|
Adam M. Wilson @ pfe
|
system("/u/scicon/tools/bin/pdsh_gdb -j 493281 -d tmp -s -u awilso10")
|
123 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
124 |
807fa48c
|
Adam M. Wilson @ pfe
|
## work in interactive mode
|
125 |
827b4b87
|
Adam M. Wilson @ pfe
|
# system("qsub -I -l walltime=2:00:00 -lselect=2:ncpus=16:model=san -q devel")
|
126 |
|
|
# mpirun -np 1 -r ssh R --no-save
|
127 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
128 |
|
|
## check progress
|
129 |
|
|
system("qstat -u awilso10")
|
130 |
92fd8a10
|
Adam M. Wilson @ pfe
|
system(paste("/u/scicon/tools/bin/qps ",pid))
|
131 |
807fa48c
|
Adam M. Wilson @ pfe
|
system(paste("qstat -t -x",pid))
|
132 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
133 |
807fa48c
|
Adam M. Wilson @ pfe
|
system("qstat devel ")
|
134 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
#system("qstat | grep awilso10")
|
135 |
|
|
|
136 |
2c238837
|
Adam M. Wilson @ pfe
|
####################################
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
################################################################################
|
140 |
|
|
## now generate the climatologies
|
141 |
|
|
fdly=data.frame(
|
142 |
|
|
path=list.files(outdir,pattern="nc$",full=T),
|
143 |
|
|
file=list.files(outdir,pattern="nc$"))
|
144 |
|
|
fdly$date=as.Date(substr(fdly$file,7,14),"%Y%m%d")
|
145 |
|
|
fdly$month=format(fdly$date,"%m")
|
146 |
|
|
fdly$year=format(fdly$date,"%Y")
|
147 |
|
|
|
148 |
|
|
## check validity (via npar and ntime) of nc files
|
149 |
|
|
for(i in 1:nrow(fdly)){
|
150 |
|
|
fdly$ntime[i]=as.numeric(system(paste("cdo sinfo ",fdly$path[i]),intern=T))
|
151 |
|
|
fdly$npar[i]=as.numeric(system(paste("cdo -s npar ",fdly$path[i]),intern=T))
|
152 |
|
|
print(i)
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
## Combine all days within years into a single file (can't mergetime all days at once because this opens too many files)
|
156 |
|
|
tsdir=paste(tempdir(),"/summary",sep="")
|
157 |
|
|
dir.create(tsdir)
|
158 |
|
|
lapply(unique(fdly$year),function(y){
|
159 |
|
|
system(paste("cdo -O mergetime ",paste(fdly$path[fdly$year==y],collapse=" ")," ",tsdir,"/MOD09_",tile,"_",y,"_daily.nc",sep=""))
|
160 |
|
|
print(paste("Finished merging daily files for year",y))
|
161 |
|
|
})
|
162 |
|
|
## Combine the year-by-year files into a single daily file
|
163 |
|
|
system(paste("cdo -O mergetime ",paste(list.files(tsdir,full=T,pattern="daily[.]nc$"),collapse=" ")," ",outdir2,"/MOD09_",tile,"_daily.nc",sep=""))
|
164 |
|
|
|
165 |
|
|
system(paste("cdo -O monmean ",outdir2,"/MOD09_",tile,"_daily.nc ",outdir2,"/",tile,"_monmean.nc",sep=""))
|
166 |
|
|
system(paste("cdo -O ymonmean ",outdir2,"/MOD09_",tile,"_daily.nc ",outdir2,"/",tile,"_ymonmean.nc",sep=""))
|
167 |
|
|
system(paste("cdo -O ymonstd ",outdir2,"/MOD09_",tile,"_daily.nc ",outdir2,"/",tile,"_ymonstd.nc",sep=""))
|
168 |
|
|
|
169 |
|
|
print("Finished! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
|
170 |
|
|
## quit R
|
171 |
|
|
q("no")
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
#################################################################
|
175 |
9d52d7e0
|
Adam M. Wilson @ pfe
|
|
176 |
807fa48c
|
Adam M. Wilson @ pfe
|
### copy the files back to Yale
|
177 |
3959e686
|
Adam M. Wilson @ pfe
|
list.files("2_daily")
|
178 |
|
|
system("scp 2_daily/* adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/Venezuela")
|
179 |
|
|
|
180 |
|
|
system("scp /tmp/Rtmp6I6tFn/MOD06_L2.A2000061.1615.051.2010273184629.hdf adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/Venezuela")
|
181 |
|
|
system("scp 2_daily/MOD06_20000410.nc adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/Venezuela")
|
182 |
cf724805
|
Adam M. Wilson @ pfe
|
|
183 |
|
|
|
184 |
|
|
list.files(" /tmp/Rtmp6I6tFn")
|
185 |
2c238837
|
Adam M. Wilson @ pfe
|
|
186 |
|
|
|
187 |
|
|
|