Project

General

Profile

Download (4.57 KB) Statistics
| Branch: | Revision:
1 3682f238 Adam M. Wilson @ pfe
#### Script to facilitate processing of MOD06 data
2
3
setwd("/nobackupp1/awilso10/mod06")
4 b6e392da Adam M. Wilson @ pfe
5 0bddce86 Adam M. Wilson @ pfe
library(rgdal)
6
library(raster)
7 3682f238 Adam M. Wilson @ pfe
8 9d52d7e0 Adam M. Wilson @ pfe
## get MODLAND tile information
9
tb=read.table("http://landweb.nascom.nasa.gov/developers/sn_tiles/sn_bound_10deg.txt",skip=6,nrows=648,header=T)
10
tb$tile=paste("h",sprintf("%02d",tb$ih),"v",sprintf("%02d",tb$iv),sep="")
11 807fa48c Adam M. Wilson @ pfe
save(tb,file="modlandTiles.Rdata")
12 3682f238 Adam M. Wilson @ pfe
13 b6e392da Adam M. Wilson @ pfe
## delete temporary log file that can grow to GB
14
system("rm /nobackupp1/awilso10/software/heg/TOOLKIT_MTD/runtime/LogStatus")
15
16
tile="h11v08"  # Venezuela
17 f9d40a14 Adam M. Wilson @ pfe
#tile="h11v07"  # Venezuela coast
18
#tile="h09v04"  # Oregon
19
tile="h21v09"  #Kenya
20 2c238837 Adam M. Wilson @ pfe
21
### get list of files to process
22
datadir="/nobackupp4/datapool/modis/MOD06_L2.005/"
23 f9d40a14 Adam M. Wilson @ pfe
#datadir="/nobackupp1/awilso10/mod06/data"   #for data downloaded from 
24
25
outdir=paste("daily/",tile,sep="")
26
27
##find swaths in region from sqlite database for the specified date/tile
28
## path to swath database
29
db="/nobackupp4/pvotava/DB/export/swath_geo.sql.sqlite3.db"
30
con=dbConnect("SQLite", dbname = db)
31
fs=dbGetQuery(con,paste("SELECT * from swath_geo
32
            WHERE east>=",tile_bb$lon_min," AND
33
                  west<=",tile_bb$lon_max," AND
34
                  north>=",tile_bb$lat_min," AND
35
                  south<=",tile_bb$lat_max)
36
    )
37
  con=dbDisconnect(con)
38
  fs$id=substr(fs$id,7,19)
39
40
### Identify which swaths are available in the datapool
41
swaths=data.frame(path=list.files(datadir,pattern=paste("hdf$"),recursive=T,full=T),stringsAsFactors=F)  #all swaths in data pool
42
swaths$id=substr(basename(swaths$path),10,22)
43
fs$exists=fs$id%in%swaths$id 
44
fs$path=swaths$path[match(fs$id,swaths$id)]
45
  
46
if(verbose) print(paste("###############",nrow(fs)," swath IDs recieved from database"))
47 2c238837 Adam M. Wilson @ pfe
48
49 f9d40a14 Adam M. Wilson @ pfe
## get all unique dates
50
fs$dateid=format(as.Date(paste(fs$year,fs$day,sep=""),"%Y%j"),"%Y%m%d")
51
alldates=unique(fs$dateid[fs$exists])
52 2c238837 Adam M. Wilson @ pfe
53
#### Generate submission file
54
## identify which have been completed
55 b6e392da Adam M. Wilson @ pfe
fdone=list.files(outdir,pattern="nc$")
56
done=alldates%in%substr(fdone,14,21)
57 2c238837 Adam M. Wilson @ pfe
58 f9d40a14 Adam M. Wilson @ pfe
### report on what has already been processed
59
print(paste(table(done)[2]," out of",length(alldates),
60
      "(",round(100*table(done)[2]/length(alldates),1),
61
      "%) dates for tile",tile,
62
      "have been processed.  Breakdown by year of completed days:"))
63
print(table(substr(alldates[done],1,4)))
64
65
#updatedone=F #update the "done" list using the 
66
#if(updatedone&exists("fdly")){  #update using table from below
67
#  done[alldates%in%fdly$dateid[fdly$drop]]=F
68
#}
69 07f76f37 Adam M. Wilson @ pfe
70 f9d40a14 Adam M. Wilson @ pfe
## Identify which dates still need to be processed
71
## This vector will be used to tell mpiexec which days to include
72
notdone=alldates[!done]  
73 07f76f37 Adam M. Wilson @ pfe
74 2c238837 Adam M. Wilson @ pfe
script="/u/awilso10/environmental-layers/climate/procedures/MOD06_L2_process.r"
75 f9d40a14 Adam M. Wilson @ pfe
climatescript="/u/awilso10/environmental-layers/climate/procedures/MOD06_Climatology.r"
76 b6e392da Adam M. Wilson @ pfe
77 f9d40a14 Adam M. Wilson @ pfe
## write the table processed by mpiexec
78 b6e392da Adam M. Wilson @ pfe
write.table(paste("--verbose ",script," --date ",notdone," --verbose T --tile \"",tile,"\"",sep=""),file=paste(tile,"_notdone.txt",sep=""),row.names=F,col.names=F,quote=F)
79 2c238837 Adam M. Wilson @ pfe
80 b6e392da Adam M. Wilson @ pfe
### qsub script
81 07f76f37 Adam M. Wilson @ pfe
cat(paste("
82
#PBS -S /bin/bash
83 f9d40a14 Adam M. Wilson @ pfe
#PBS -l select=50:ncpus=8:mpiprocs=8
84 07f76f37 Adam M. Wilson @ pfe
##PBS -l select=2:ncpus=4:mpiprocs=4
85 b6e392da Adam M. Wilson @ pfe
#PBS -l walltime=2:00:00
86 07f76f37 Adam M. Wilson @ pfe
#PBS -j n
87
#PBS -m be
88
#PBS -N mod06
89
#PBS -q devel
90
#PBS -V
91
92 f9d40a14 Adam M. Wilson @ pfe
CORES=400
93 07f76f37 Adam M. Wilson @ pfe
HDIR=/u/armichae/pr/
94
  source $HDIR/etc/environ.sh
95
  source /u/awilso10/.bashrc
96
IDIR=/nobackupp1/awilso10/mod06/
97
##WORKLIST=$HDIR/var/run/pxrRgrs/work.txt
98 b6e392da Adam M. Wilson @ pfe
WORKLIST=$IDIR/",tile,"_notdone.txt
99 07f76f37 Adam M. Wilson @ pfe
EXE=Rscript
100 f9d40a14 Adam M. Wilson @ pfe
LOGSTDOUT=$IDIR/log/",tile,"_stdout
101
LOGSTDERR=$IDIR/log/",tile,"_stderr
102
### use mpiexec to parallelize across days
103 07f76f37 Adam M. Wilson @ pfe
mpiexec -np $CORES pxargs -a $WORKLIST -p $EXE -v -v -v --work-analyze 1> $LOGSTDOUT 2> $LOGSTDERR
104 f9d40a14 Adam M. Wilson @ pfe
### Now process the climatologies
105
Rscript --verbose ",climatescript," --verbose T --tile \"",tile,"\"
106 b6e392da Adam M. Wilson @ pfe
",sep=""),file=paste(tile,"_mod06_qsub",sep=""))
107 827b4b87 Adam M. Wilson @ pfe
108 9d52d7e0 Adam M. Wilson @ pfe
109
### Check the file
110 b6e392da Adam M. Wilson @ pfe
system(paste("cat ",tile,"_mod06_qsub",sep=""))
111 92fd8a10 Adam M. Wilson @ pfe
112 807fa48c Adam M. Wilson @ pfe
## Submit it (and keep the pid)!
113 b6e392da Adam M. Wilson @ pfe
system(paste("qsub ",tile,"_mod06_qsub",sep=""))
114 9d52d7e0 Adam M. Wilson @ pfe
115 807fa48c Adam M. Wilson @ pfe
## work in interactive mode
116 827b4b87 Adam M. Wilson @ pfe
# system("qsub -I -l walltime=2:00:00 -lselect=2:ncpus=16:model=san -q devel")
117
# mpirun -np 1 -r ssh R --no-save
118 9d52d7e0 Adam M. Wilson @ pfe
119
## check progress
120
system("qstat -u awilso10")
121 2c238837 Adam M. Wilson @ pfe
122 9d52d7e0 Adam M. Wilson @ pfe
123 f9d40a14 Adam M. Wilson @ pfe
#################################################################
124 807fa48c Adam M. Wilson @ pfe
### copy the files back to Yale
125 f9d40a14 Adam M. Wilson @ pfe
summarydir="summary"
126
127
128 3959e686 Adam M. Wilson @ pfe
129 f9d40a14 Adam M. Wilson @ pfe
system(paste("scp ",summarydir,"/MOD06_",tile,".nc adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod06/summary",sep=""))
130 cf724805 Adam M. Wilson @ pfe
131 f9d40a14 Adam M. Wilson @ pfe
system(paste("scp ",tsdir,"/MOD06_",tile,"*.nc adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod06/summary",sep=""))
132
system(paste("scp ",paste(fs$path[40421:40422],collapse=" ")," adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod06/swaths",sep=""))
133 cf724805 Adam M. Wilson @ pfe
134 2c238837 Adam M. Wilson @ pfe
135
136