Project

General

Profile

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