Revision 35d59dc1
Added by Adam Wilson over 11 years ago
climate/procedures/MOD35_Climatology.r | ||
---|---|---|
1 |
### Process a folder of daily MOD35 HDF files to produce a climatology |
|
2 |
|
|
3 |
## import commandline arguments |
|
4 |
library(getopt) |
|
5 |
## get options |
|
6 |
opta <- getopt(matrix(c( |
|
7 |
'tile', 't', 1, 'character', |
|
8 |
'verbose','v',1,'logical' |
|
9 |
), ncol=4, byrow=TRUE)) |
|
10 |
|
|
11 |
tile=opta$tile #tile="h11v08" |
|
12 |
verbose=opta$verbose #print out extensive information for debugging? |
|
13 |
|
|
14 |
### directory containing daily files |
|
15 |
outdir=paste("daily/",tile,"/",sep="") #directory for separate daily files |
|
16 |
|
|
17 |
### directory to hold climatology |
|
18 |
outdir2="summary" #directory for combined daily files and summarized files |
|
19 |
if(!file.exists(outdir2)) dir.create(outdir2) |
|
20 |
|
|
21 |
### path to NCO |
|
22 |
ncopath="/nasa/sles11/nco/4.0.8/gcc/mpt/bin/" |
|
23 |
|
|
24 |
### Vector of variables that must be in file or they will be deleted. |
|
25 |
### Formated as output from system(paste("cdo -s showvar ",fdly$path[i]),intern=T) |
|
26 |
#finalvars=" CER COT CLD" |
|
27 |
|
|
28 |
|
|
29 |
################################################################################ |
|
30 |
## Get list of all daily files |
|
31 |
if(verbose) print("Checking daily output in preparation for generating climatology") |
|
32 |
|
|
33 |
fdly=data.frame(path=list.files(outdir,pattern="nc$",full=T),stringsAsFactors=F) |
|
34 |
fdly$file=basename(fdly$path) |
|
35 |
fdly$dateid=substr(fdly$file,14,21) |
|
36 |
fdly$date=as.Date(substr(fdly$file,14,21),"%Y%m%d") |
|
37 |
fdly$month=format(fdly$date,"%m") |
|
38 |
fdly$year=format(fdly$date,"%Y") |
|
39 |
nrow(fdly) |
|
40 |
|
|
41 |
## check validity (via npar and ntime) of nc files |
|
42 |
#for(i in 1:nrow(fdly)){ |
|
43 |
# fdly$ntime[i]<-as.numeric(system(paste("cdo -s ntime ",fdly$path[i]),intern=T)) |
|
44 |
# fdly$npar[i]<-as.numeric(system(paste("cdo -s npar ",fdly$path[i]),intern=T)) |
|
45 |
# fdly$fyear[i]<-as.numeric(system(paste("cdo -s showyear ",fdly$path[i]),intern=T)) |
|
46 |
# fdly$fmonth[i]<-as.numeric(system(paste("cdo -s showmon ",fdly$path[i]),intern=T)) |
|
47 |
# fdly$fvar[i]<-system(paste("cdo -s showvar ",fdly$path[i]),intern=T) |
|
48 |
# print(paste(i," out of ",nrow(fdly)," for year ", fdly$fyear[i])) |
|
49 |
#} |
|
50 |
|
|
51 |
## print some summaries |
|
52 |
if(verbose) print("Summary of available daily files") |
|
53 |
print(table(fdly$year)) |
|
54 |
print(table(fdly$month)) |
|
55 |
#print(table(fdly$fvar)) |
|
56 |
|
|
57 |
## Identify which files failed test |
|
58 |
#fdly$drop=is.na(fdly$npar)|fdly$fvar!=finalvars |
|
59 |
|
|
60 |
## delete files that fail check? |
|
61 |
delete=F |
|
62 |
if(delete) { |
|
63 |
print(paste(sum(fdly$drop),"files will be deleted")) |
|
64 |
file.remove(as.character(fdly$path[fdly$drop])) |
|
65 |
} |
|
66 |
## remove dropped files from list |
|
67 |
#fdly=fdly[!fdly$drop,] |
|
68 |
|
|
69 |
################################################################################# |
|
70 |
## Combine the year-by-year files into a single daily file in the summary directory (for archiving) |
|
71 |
if(verbose) print("Merging daily files into single file output") |
|
72 |
|
|
73 |
## create temporary directory to put intermediate files (will be deleted when R quits) |
|
74 |
tsdir=paste(tempdir(),"/summary",sep="") |
|
75 |
if(!file.exists(tsdir)) dir.create(tsdir,recursive=T) |
|
76 |
|
|
77 |
## merge all daily files to create a single file with all dates |
|
78 |
system(paste(ncopath,"ncrcat -O ",outdir,"/*nc ",outdir2,"/MOD35_",tile,"_daily.nc",sep="")) |
|
79 |
|
|
80 |
## Update attributes |
|
81 |
system(paste(ncopath,"ncatted ", |
|
82 |
" -a units,time,o,c,\"days since 2000-1-1 0:0:0\" ", |
|
83 |
" -a title,global,o,c,\"MODIS Cloud Product (MOD35) Daily Timeseries\" ", |
|
84 |
" -a institution,global,o,c,\"Yale University\" ", |
|
85 |
" -a source,global,o,c,\"MODIS Cloud Mask (MOD35)\" ", |
|
86 |
" -a comment,global,o,c,\"Compiled by Adam M. Wilson (adam.wilson@yale.edu)\" ", |
|
87 |
outdir2,"/MOD35_",tile,"_daily.nc",sep="")) |
|
88 |
|
|
89 |
### produce a monthly timeseries? |
|
90 |
#system(paste("cdo -O monmean ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_monmean.nc",sep="")) |
|
91 |
|
|
92 |
############################# |
|
93 |
## Generate the Climatologies |
|
94 |
if(verbose) print("Generate monthly climatologies") |
|
95 |
|
|
96 |
myear=as.integer(max(fdly$year)) #this year will be used in all dates of monthly climatologies (and day will = 15) |
|
97 |
|
|
98 |
## Monthly means |
|
99 |
if(verbose) print("Calculating the monthly means") |
|
100 |
system(paste("cdo -O sorttimestamp -setyear,",myear," -setday,15 -ymonmean -mulc,1.0 ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymonmean.nc",sep=""),wait=T) |
|
101 |
|
|
102 |
## Monthly standard deviation |
|
103 |
if(verbose) print("Calculating the monthly SD") |
|
104 |
system(paste("cdo -O sorttimestamp -setyear,",myear," -setday,15 -ymonstd ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymonstd.nc",sep="")) |
|
105 |
system(paste(ncopath,"ncrename -v CLD,CLD_sd ",tsdir,"/MOD35_",tile,"_ymonstd.nc",sep="")) |
|
106 |
system(paste(ncopath,"ncatted ", |
|
107 |
#" -a long_name,CER_sd,o,c,\"Cloud Particle Effective Radius (standard deviation of daily observations)\" ", |
|
108 |
" -a long_name,CLD_sd,o,c,\"Cloud Mask (standard deviation of daily observations)\" ", |
|
109 |
#" -a long_name,COT_sd,o,c,\"Cloud Optical Thickness (standard deviation of daily observations)\" ", |
|
110 |
tsdir,"/MOD35_",tile,"_ymonstd.nc",sep="")) |
|
111 |
|
|
112 |
## cld == 0 |
|
113 |
if(verbose) print("Calculating the proportion of cloudy days") |
|
114 |
system(paste("cdo -O sorttimestamp -setyear,",myear," -setday,15 -nint -mulc,100 -ymonmean -mulc,1.0 -eqc,0 -setctomiss,1 -selvar,CLD2 ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymoncld0.nc",sep="")) |
|
115 |
system(paste(ncopath,"ncrename -v CLD2,CLD0 ",tsdir,"/MOD35_",tile,"_ymoncld0.nc",sep="")) |
|
116 |
system(paste(ncopath,"ncatted ", |
|
117 |
" -a long_name,CLD0,o,c,\"Proportion of Days with Cloud Mask == 0\" ", |
|
118 |
" -a units,CLD0,o,c,\"Proportion\" ", |
|
119 |
tsdir,"/MOD35_",tile,"_ymoncld0.nc",sep="")) |
|
120 |
|
|
121 |
## cld == 0|1 |
|
122 |
if(verbose) print("Calculating the proportion of cloudy days") |
|
123 |
system(paste("cdo -O sorttimestamp -setyear,",myear," -setday,15 -nint -mulc,100 -ymonmean -mulc,1.0 -lec,1 -selvar,CLD2 ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep="")) |
|
124 |
system(paste(ncopath,"ncrename -v CLD2,CLD01 ",tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep="")) |
|
125 |
system(paste(ncopath,"ncatted ", |
|
126 |
" -a long_name,CLD01,o,c,\"Proportion of Days with Cloud Mask == 0|1\" ", |
|
127 |
" -a units,CLD01,o,c,\"Proportion\" ", |
|
128 |
tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep="")) |
|
129 |
|
|
130 |
## cld == 1 |
|
131 |
if(verbose) print("Calculating the proportion of uncertain days") |
|
132 |
system(paste("cdo -O sorttimestamp -setyear,",myear," -setday,15 -nint -mulc,100 -ymonmean -mulc,1.0 -eqc,1 -selvar,CLD2 ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymoncld1.nc",sep="")) |
|
133 |
system(paste(ncopath,"ncrename -v CLD2,CLD1 ",tsdir,"/MOD35_",tile,"_ymoncld1.nc",sep="")) |
|
134 |
system(paste(ncopath,"ncatted ", |
|
135 |
" -a long_name,CLD1,o,c,\"Proportion of Days with Cloud Mask == 1 (uncertain)\" ", |
|
136 |
" -a units,CLD1,o,c,\"Proportion\" ", |
|
137 |
tsdir,"/MOD35_",tile,"_ymoncld1.nc",sep="")) |
|
138 |
|
|
139 |
|
|
140 |
## cld >= 2 (setting cld==01 to missing because 'uncertain') |
|
141 |
if(verbose) print("Calculating the proportion of clear days") |
|
142 |
system(paste("cdo -O sorttimestamp -setyear,",myear," -setday,15 -nint -mulc,100 -ymonmean -mulc,1.0 -gtc,1 -setctomiss,1 -selvar,CLD2 ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymoncld2.nc",sep="")) |
|
143 |
system(paste(ncopath,"ncrename -v CLD2,CLD23 ",tsdir,"/MOD35_",tile,"_ymoncld2.nc",sep="")) |
|
144 |
system(paste(ncopath,"ncatted ", |
|
145 |
" -a long_name,CLD23,o,c,\"Proportion of Days with Cloud Mask >= 2 (Probably Clear or Certainly Clear)\" ", |
|
146 |
" -a units,CLD23,o,c,\"Proportion\" ", |
|
147 |
tsdir,"/MOD35_",tile,"_ymoncld2.nc",sep="")) |
|
148 |
|
|
149 |
## cld >= 1 |
|
150 |
if(verbose) print("Calculating the proportion of clear days") |
|
151 |
system(paste("cdo -O sorttimestamp -setyear,",myear," -setday,15 -nint -mulc,100 -ymonmean -mulc,1.0 -gec,1 -selvar,CLD2 ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymoncld13.nc",sep="")) |
|
152 |
system(paste(ncopath,"ncrename -v CLD2,CLD13 ",tsdir,"/MOD35_",tile,"_ymoncld13.nc",sep="")) |
|
153 |
system(paste(ncopath,"ncatted ", |
|
154 |
" -a long_name,CLD13,o,c,\"Proportion of Days with Cloud Mask >= 1\" ", |
|
155 |
" -a units,CLD13,o,c,\"Proportion\" ", |
|
156 |
tsdir,"/MOD35_",tile,"_ymoncld13.nc",sep="")) |
|
157 |
|
|
158 |
## number of observations |
|
159 |
if(verbose) print("Calculating the number of missing variables") |
|
160 |
system(paste("cdo -O sorttimestamp -setyear,",myear," -setday,15 -nint -mulc,100 -ymonmean -mulc,1.0 -eqc,9999 -setmisstoc,9999 -selvar,CLD ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymonmiss.nc",sep="")) |
|
161 |
system(paste(ncopath,"ncrename -v CLD,CLD_pmiss ",tsdir,"/MOD35_",tile,"_ymonmiss.nc",sep="")) |
|
162 |
system(paste(ncopath,"ncatted ", |
|
163 |
" -a long_name,CLD_pmiss,o,c,\"Proportion of Days with missing data for CLD\" ", |
|
164 |
" -a scale_factor,CLD_pmiss,o,d,0.01 ", |
|
165 |
" -a units,CLD_pmiss,o,c,\"Proportion\" ", |
|
166 |
tsdir,"/MOD35_",tile,"_ymonmiss.nc",sep="")) |
|
167 |
|
|
168 |
## TODO: fix projection information so GDAL can read it correctly. |
|
169 |
## clean up variables? |
|
170 |
|
|
171 |
## append variables to a single file |
|
172 |
if(verbose) print("Append all monthly climatologies into a single file") |
|
173 |
system(paste(ncopath,"ncks -O ",tsdir,"/MOD35_",tile,"_ymonmean.nc ",tsdir,"/MOD35_",tile,"_ymon.nc",sep="")) |
|
174 |
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymonstd.nc ",tsdir,"/MOD35_",tile,"_ymon.nc",sep="")) |
|
175 |
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymoncld0.nc ",tsdir,"/MOD35_",tile,"_ymon.nc",sep="")) |
|
176 |
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymoncld01.nc ",tsdir,"/MOD35_",tile,"_ymon.nc",sep="")) |
|
177 |
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymoncld1.nc ",tsdir,"/MOD35_",tile,"_ymon.nc",sep="")) |
|
178 |
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymoncld2.nc ",tsdir,"/MOD35_",tile,"_ymon.nc",sep="")) |
|
179 |
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymonmiss.nc ",tsdir,"/MOD35_",tile,"_ymon.nc",sep="")) |
|
180 |
|
|
181 |
## append sinusoidal grid from one of input files as CDO doesn't transfer all attributes |
|
182 |
if(verbose) print("Clean up file (update attributes, flip latitudes, add grid description") |
|
183 |
|
|
184 |
#system(paste(ncopath,"ncea -d time,0,1 -v sinusoidal ",list.files(outdir,full=T,pattern="[.]nc$")[1]," ",tsdir,"/sinusoidal.nc",sep="")) |
|
185 |
#system(paste(ncopath,"ncks -A -d time,0,1 -v sinusoidal ",list.files(outdir,full=T,pattern="[.]nc$")[1]," ",tsdir,"/MOD35_",tile,"_ymon.nc",sep="")) |
|
186 |
|
|
187 |
## invert latitude so it plays nicely with gdal |
|
188 |
system(paste(ncopath,"ncpdq -O -a -y ",tsdir,"/MOD35_",tile,"_ymon.nc ",outdir2,"/MOD35_",tile,".nc",sep="")) |
|
189 |
|
|
190 |
## update attributes |
|
191 |
system(paste(ncopath,"ncatted ", |
|
192 |
#" -a standard_parallel,sinusoidal,o,c,\"0\" ", |
|
193 |
#" -a longitude_of_central_meridian,sinusoidal,o,c,\"0\" ", |
|
194 |
#" -a latitude_of_central_meridian,sinusoidal,o,c,\"0\" ", |
|
195 |
" -a units,time,o,c,\"days since 2000-1-1 0:0:0\" ", |
|
196 |
" -a title,global,o,c,\"MODIS Cloud Product (MOD35) Climatology\" ", |
|
197 |
" -a institution,global,o,c,\"Yale University\" ", |
|
198 |
" -a source,global,o,c,\"MODIS Cloud Product (MOD35)\" ", |
|
199 |
" -a comment,global,o,c,\"Compiled by Adam M. Wilson (adam.wilson@yale.edu)\" ", |
|
200 |
outdir2,"/MOD35_",tile,".nc",sep="")) |
|
201 |
|
|
202 |
|
|
203 |
print(paste("############################### Processed ",nrow(fdly),"days for tile:",tile," ###################################################")) |
|
204 |
print("Years:") |
|
205 |
print(table(fdly$fyear)) |
|
206 |
print("Months:") |
|
207 |
print(table(fdly$fmonth)) |
|
208 |
|
|
209 |
## quit R |
|
210 |
q("no") |
|
211 |
|
climate/procedures/MOD35_L2_process.r | ||
---|---|---|
51 | 51 |
|
52 | 52 |
if(platform=="pleiades"){ |
53 | 53 |
## location of MOD06 files |
54 |
datadir=paste("/nobackupp4/datapool/modis/MOD06_L2.005/",year,"/",doy,"/",sep="")
|
|
54 |
datadir=paste("/nobackupp4/datapool/modis/MOD35_L2.006/",year,"/",doy,"/",sep="")
|
|
55 | 55 |
## path to some executables |
56 | 56 |
ncopath="/nasa/sles11/nco/4.0.8/gcc/mpt/bin/" |
57 | 57 |
swtifpath="/nobackupp1/awilso10/software/heg/bin/swtif" |
58 | 58 |
## path to swath database |
59 | 59 |
db="/nobackupp4/pvotava/DB/export/swath_geo.sql.sqlite3.db" |
60 | 60 |
## specify working directory |
61 |
setwd("/nobackupp1/awilso10/mod06")
|
|
61 |
setwd("/nobackupp1/awilso10/mod35")
|
|
62 | 62 |
gisBase="/u/armichae/pr/grass-6.4.2/" |
63 | 63 |
## path to MOD11A1 file for this tile to align grid/extent |
64 | 64 |
gridfile=list.files("/nobackupp4/datapool/modis/MOD11A1.005/2006.01.27",pattern=paste(tile,".*[.]hdf$",sep=""),recursive=T,full=T)[1] |
... | ... | |
182 | 182 |
## Process the gridded files to align exactly with MODLAND tile and produce a daily summary of multiple swaths |
183 | 183 |
|
184 | 184 |
## Identify output file |
185 |
ncfile=paste(outdir,"/MOD06_",tile,"_",date,".nc",sep="") #this is the 'final' daily output file
|
|
185 |
ncfile=paste(outdir,"/MOD35_",tile,"_",date,".nc",sep="") #this is the 'final' daily output file
|
|
186 | 186 |
|
187 | 187 |
## function to convert binary to decimal to assist in identifying correct values |
188 | 188 |
## this is helpful when defining QA handling below, but isn't used in processing |
... | ... | |
314 | 314 |
print(paste("FILE ERROR: tile ",tile," and date ",date," was not outputted correctly, deleting... ")) |
315 | 315 |
file.remove(ncfile) |
316 | 316 |
} |
317 |
|
|
317 |
|
|
318 | 318 |
## print out some info |
319 | 319 |
print(paste(" ################################################################### Finished ",date, |
320 | 320 |
"################################################################")) |
climate/procedures/Pleiades_MOD35.R | ||
---|---|---|
1 |
#### Script to facilitate processing of MOD06 data |
|
2 |
|
|
3 |
setwd("/nobackupp1/awilso10/mod35") |
|
4 |
|
|
5 |
library(rgdal) |
|
6 |
library(raster) |
|
7 |
library(RSQLite) |
|
8 |
|
|
9 |
|
|
10 |
verbose=T |
|
11 |
|
|
12 |
## get MODLAND tile information |
|
13 |
tb=read.table("http://landweb.nascom.nasa.gov/developers/sn_tiles/sn_bound_10deg.txt",skip=6,nrows=648,header=T) |
|
14 |
tb$tile=paste("h",sprintf("%02d",tb$ih),"v",sprintf("%02d",tb$iv),sep="") |
|
15 |
save(tb,file="modlandTiles.Rdata") |
|
16 |
load("modlandTiles.Rdata") |
|
17 |
|
|
18 |
## delete temporary log file that can grow to GB |
|
19 |
system("rm /nobackupp1/awilso10/software/heg/TOOLKIT_MTD/runtime/LogStatus") |
|
20 |
|
|
21 |
|
|
22 |
tile="h11v08" # Venezuela |
|
23 |
#tile="h11v07" # Venezuela coast |
|
24 |
#tile="h09v04" # Oregon |
|
25 |
tile="h21v09" #Kenya |
|
26 |
|
|
27 |
|
|
28 |
### list of tiles to process |
|
29 |
tiles=c("h11v08","h21v09","h08v04","h09v04","h08v05","h09v05","h20v11","h31v11") |
|
30 |
tiles=tiles[c(1,4)] |
|
31 |
tile_bb=tb[tb$tile%in%tiles,] |
|
32 |
|
|
33 |
### get list of files to process |
|
34 |
datadir="/nobackupp4/datapool/modis/MOD35_L2.006/" |
|
35 |
#datadir="/nobackupp1/awilso10/mod06/data" #for data downloaded from |
|
36 |
|
|
37 |
outdir="daily/" #paste("daily/",tile,sep="") |
|
38 |
|
|
39 |
##find swaths in region from sqlite database for the specified date/tile |
|
40 |
## path to swath database |
|
41 |
db="/nobackupp4/pvotava/DB/export/swath_geo.sql.sqlite3.db" |
|
42 |
con=dbConnect("SQLite", dbname = db) |
|
43 |
fs=do.call(rbind.data.frame,lapply(1:nrow(tile_bb),function(i){ |
|
44 |
d=dbGetQuery(con,paste("SELECT * from swath_geo6 |
|
45 |
WHERE east>=",tile_bb$lon_min[i]," AND |
|
46 |
west<=",tile_bb$lon_max[i]," AND |
|
47 |
north>=",tile_bb$lat_min[i]," AND |
|
48 |
south<=",tile_bb$lat_max[i]) |
|
49 |
) |
|
50 |
d$tile=tile_bb$tile[i] |
|
51 |
print(paste("Finished tile",tile_bb$tile[i])) |
|
52 |
return(d) |
|
53 |
})) |
|
54 |
con=dbDisconnect(con) |
|
55 |
fs$id=substr(fs$id,7,19) |
|
56 |
|
|
57 |
### Identify which swaths are available in the datapool |
|
58 |
swaths=data.frame(path=list.files(datadir,pattern=paste("hdf$"),recursive=T,full=T),stringsAsFactors=F) #all swaths in data pool |
|
59 |
swaths$id=substr(basename(swaths$path),10,22) |
|
60 |
fs$exists=fs$id%in%swaths$id |
|
61 |
fs$path=swaths$path[match(fs$id,swaths$id)] |
|
62 |
|
|
63 |
if(verbose) print(paste("###############",nrow(fs)," swath IDs recieved from database")) |
|
64 |
|
|
65 |
|
|
66 |
## get all unique dates |
|
67 |
fs$dateid=format(as.Date(paste(fs$year,fs$day,sep=""),"%Y%j"),"%Y%m%d") |
|
68 |
alldates=unique(fs$dateid[fs$exists]) |
|
69 |
|
|
70 |
#### Generate submission file |
|
71 |
alldates=format(seq(as.Date("2000-03-01"),as.Date("2011-12-31"),1),"%Y%m%d") |
|
72 |
proclist=expand.grid(date=alldates,tile=tiles) |
|
73 |
proclist$year=substr(proclist$date,1,4) |
|
74 |
|
|
75 |
## identify which have been completed |
|
76 |
fdone=data.frame(path=list.files(outdir,pattern="nc$",recursive=T)) |
|
77 |
fdone$date=substr(basename(as.character(fdone$path)),14,21) |
|
78 |
fdone$tile=substr(basename(as.character(fdone$path)),7,12) |
|
79 |
|
|
80 |
## identify which date-tiles have already been run |
|
81 |
proclist$done=paste(proclist$tile,proclist$date,sep="_")%in%substr(basename(as.character(fdone$path)),7,21) |
|
82 |
|
|
83 |
### report on what has already been processed |
|
84 |
print(paste(sum(!proclist$done)," out of ",nrow(proclist)," (",round(100*sum(!proclist$done)/nrow(proclist),2),"%) remain")) |
|
85 |
table(tile=proclist$tile[proclist$done],year=proclist$year[proclist$done]) |
|
86 |
|
|
87 |
script="/u/awilso10/environmental-layers/climate/procedures/MOD35_L2_process.r" |
|
88 |
|
|
89 |
## write the table processed by mpiexec |
|
90 |
write.table(paste("--verbose ",script," --date ",proclist$date[!proclist$done]," --verbose T --tile ",proclist$tile[!proclist$done],sep=""), |
|
91 |
file=paste("notdone.txt",sep=""),row.names=F,col.names=F,quote=F) |
|
92 |
|
|
93 |
### qsub script |
|
94 |
cat(paste(" |
|
95 |
#PBS -S /bin/bash |
|
96 |
#PBS -l select=50:ncpus=8:mpiprocs=8 |
|
97 |
##PBS -l select=2:ncpus=8:mpiprocs=8 |
|
98 |
##PBS -l select=2:ncpus=4:mpiprocs=4 |
|
99 |
#PBS -l walltime=5:00:00 |
|
100 |
#PBS -j n |
|
101 |
#PBS -m be |
|
102 |
#PBS -N mod35 |
|
103 |
#PBS -q normal |
|
104 |
#PBS -V |
|
105 |
|
|
106 |
CORES=400 |
|
107 |
HDIR=/u/armichae/pr/ |
|
108 |
# source $HDIR/etc/environ.sh |
|
109 |
source /u/awilso10/environ.sh |
|
110 |
source /u/awilso10/.bashrc |
|
111 |
IDIR=/nobackupp1/awilso10/mod35/ |
|
112 |
##WORKLIST=$HDIR/var/run/pxrRgrs/work.txt |
|
113 |
WORKLIST=$IDIR/notdone.txt |
|
114 |
EXE=Rscript |
|
115 |
LOGSTDOUT=$IDIR/log/mod35_stdout |
|
116 |
LOGSTDERR=$IDIR/log/mod35_stderr |
|
117 |
### use mpiexec to parallelize across days |
|
118 |
mpiexec -np $CORES pxargs -a $WORKLIST -p $EXE -v -v -v --work-analyze 1> $LOGSTDOUT 2> $LOGSTDERR |
|
119 |
",sep=""),file=paste("mod35_qsub",sep="")) |
|
120 |
|
|
121 |
|
|
122 |
### Check the files |
|
123 |
system(paste("cat mod35_qsub",sep="")) |
|
124 |
system(paste("cat notdone.txt | head",sep="")) |
|
125 |
system(paste("cat notdone.txt | wc -l ",sep="")) |
|
126 |
|
|
127 |
## Submit it |
|
128 |
system(paste("qsub mod35_qsub",sep="")) |
|
129 |
|
|
130 |
####################################################### |
|
131 |
### Now submit the script to generate the climatologies |
|
132 |
|
|
133 |
tiles |
|
134 |
ctiles=tiles[c(2)] #subset to only some tiles (for example if some aren't finished yet)? |
|
135 |
climatescript="/u/awilso10/environmental-layers/climate/procedures/MOD35_Climatology.r" |
|
136 |
|
|
137 |
## write the table processed by mpiexec |
|
138 |
write.table(paste("--verbose ",climatescript," --verbose T --tile ",ctiles,sep=""), |
|
139 |
file=paste("notdone_climate.txt",sep=""),row.names=F,col.names=F,quote=F) |
|
140 |
|
|
141 |
## delay start until previous jobs have finished? |
|
142 |
delay=F |
|
143 |
## check running jobs to get JobID of job you want to wait for |
|
144 |
system("qstat -u awilso10") |
|
145 |
## enter JobID here: |
|
146 |
job="881394.pbspl1.nas.nasa.gov" |
|
147 |
|
|
148 |
### qsub script |
|
149 |
cat(paste(" |
|
150 |
#PBS -S /bin/bash |
|
151 |
##PBS -l select=50:ncpus=8:mpiprocs=8 |
|
152 |
#PBS -l select=4:ncpus=4:mpiprocs=4 |
|
153 |
#PBS -l walltime=2:00:00 |
|
154 |
#PBS -j n |
|
155 |
#PBS -m be |
|
156 |
#PBS -N mod35_climate |
|
157 |
#PBS -q devel |
|
158 |
#PBS -V |
|
159 |
",if(delay) paste("#PBS -W depend=afterany:",job,sep="")," |
|
160 |
|
|
161 |
CORES=16 |
|
162 |
HDIR=/u/armichae/pr/ |
|
163 |
# source $HDIR/etc/environ.sh |
|
164 |
source /u/awilso10/environ.sh |
|
165 |
source /u/awilso10/.bashrc |
|
166 |
IDIR=/nobackupp1/awilso10/mod35/ |
|
167 |
##WORKLIST=$HDIR/var/run/pxrRgrs/work.txt |
|
168 |
WORKLIST=$IDIR/notdone_climate.txt |
|
169 |
EXE=Rscript |
|
170 |
LOGSTDOUT=$IDIR/log/climatology_stdout |
|
171 |
LOGSTDERR=$IDIR/log/climatology_stderr |
|
172 |
### use mpiexec to parallelize across days |
|
173 |
mpiexec -np $CORES pxargs -a $WORKLIST -p $EXE -v -v -v --work-analyze 1> $LOGSTDOUT 2> $LOGSTDERR |
|
174 |
",sep=""),file=paste("mod35_climatology_qsub",sep="")) |
|
175 |
|
|
176 |
## check files |
|
177 |
system(paste("cat mod35_climatology_qsub",sep="")) #qsub submission script |
|
178 |
system(paste("cat notdone_climate.txt | head",sep="")) #top of job file |
|
179 |
system(paste("cat notdone_climate.txt | wc -l ",sep="")) #number of jobs to be run |
|
180 |
|
|
181 |
## Submit it |
|
182 |
system(paste("qsub mod35_climatology_qsub",sep="")) |
|
183 |
|
|
184 |
## check progress |
|
185 |
system("qstat -u awilso10") |
|
186 |
|
|
187 |
## start interactive job on compute node for debugging |
|
188 |
# system("qsub -I -l walltime=2:00:00 -lselect=2:ncpus=16:model=san -q devel") |
|
189 |
|
|
190 |
|
|
191 |
################################################################# |
|
192 |
### copy the files back to Yale |
|
193 |
summarydir="summary" |
|
194 |
|
|
195 |
sumfiles=list.files("summary",pattern="^MOD06_.*[0-9][.]nc",full=T) |
|
196 |
|
|
197 |
system(paste("scp ",paste(sumfiles,collapse=" ")," adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod06/summary",sep="")) |
|
198 |
|
|
199 |
#system(paste("scp ",tsdir,"/MOD06_",tile,"*.nc adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod06/summary",sep="")) |
|
200 |
#system(paste("scp ",paste(fs$path[40421:40422],collapse=" ")," adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod06/swaths",sep="")) |
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
Also available in: Unified diff
Simplifications to Climatology Script