Project

General

Profile

Download (4.57 KB) Statistics
| Branch: | Revision:
1
#### Script to facilitate processing of MOD06 data
2

    
3
setwd("/nobackupp1/awilso10/mod06")
4

    
5
library(rgdal)
6
library(raster)
7

    
8
## 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
save(tb,file="modlandTiles.Rdata")
12

    
13
## 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
#tile="h11v07"  # Venezuela coast
18
#tile="h09v04"  # Oregon
19
tile="h21v09"  #Kenya
20

    
21
### get list of files to process
22
datadir="/nobackupp4/datapool/modis/MOD06_L2.005/"
23
#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

    
48

    
49
## 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

    
53
#### Generate submission file
54
## identify which have been completed
55
fdone=list.files(outdir,pattern="nc$")
56
done=alldates%in%substr(fdone,14,21)
57

    
58
### 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

    
70
## 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

    
74
script="/u/awilso10/environmental-layers/climate/procedures/MOD06_L2_process.r"
75
climatescript="/u/awilso10/environmental-layers/climate/procedures/MOD06_Climatology.r"
76

    
77
## write the table processed by mpiexec
78
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

    
80
### qsub script
81
cat(paste("
82
#PBS -S /bin/bash
83
#PBS -l select=50:ncpus=8:mpiprocs=8
84
##PBS -l select=2:ncpus=4:mpiprocs=4
85
#PBS -l walltime=2:00:00
86
#PBS -j n
87
#PBS -m be
88
#PBS -N mod06
89
#PBS -q devel
90
#PBS -V
91

    
92
CORES=400
93
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
WORKLIST=$IDIR/",tile,"_notdone.txt
99
EXE=Rscript
100
LOGSTDOUT=$IDIR/log/",tile,"_stdout
101
LOGSTDERR=$IDIR/log/",tile,"_stderr
102
### use mpiexec to parallelize across days
103
mpiexec -np $CORES pxargs -a $WORKLIST -p $EXE -v -v -v --work-analyze 1> $LOGSTDOUT 2> $LOGSTDERR
104
### Now process the climatologies
105
Rscript --verbose ",climatescript," --verbose T --tile \"",tile,"\"
106
",sep=""),file=paste(tile,"_mod06_qsub",sep=""))
107

    
108

    
109
### Check the file
110
system(paste("cat ",tile,"_mod06_qsub",sep=""))
111

    
112
## Submit it (and keep the pid)!
113
system(paste("qsub ",tile,"_mod06_qsub",sep=""))
114

    
115
## work in interactive mode
116
# 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

    
119
## check progress
120
system("qstat -u awilso10")
121

    
122

    
123
#################################################################
124
### copy the files back to Yale
125
summarydir="summary"
126

    
127

    
128

    
129
system(paste("scp ",summarydir,"/MOD06_",tile,".nc adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod06/summary",sep=""))
130

    
131
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

    
134

    
135

    
136

    
137

    
(20-20/23)