Project

General

Profile

« Previous | Next » 

Revision e4e30b86

Added by Adam Wilson over 11 years ago

updated swtif error checking to use r.neighbor instead of r.mapcalc. Submitted job for northern block of tiles

View differences:

climate/procedures/Build_Global_MODIS_tiles.R
3 3

  
4 4
######
5 5
### proceed by raster using information at http://code.env.duke.edu/projects/mget/wiki/SinusoidalMODIS
6
maketile=function(tile){
6
maketile=function(tile,outdir="MODTILES"){
7 7
  ## check tile
8 8
  ## list of tile outside valid region
9 9
  nodata=c('h00v00','h01v00','h02v00','h03v00','h04v00','h05v00','h06v00','h07v00','h08v00','h09v00','h10v00',
......
25 25
  ##
26 26
  h=as.numeric(substr(tile,2,3))
27 27
  v=as.numeric(substr(tile,5,6))
28
  print(paste("Making a raster grid for tile",tile))
29 28
  ## Earth Width (m)
30 29
  ew=20015109.354*2
31 30
  ## Tile width or height = earth width / 36 = (20015109.354 + 20015109.354) / 36 = 1111950.5196666666 m
......
43 42
  ext=extent(llx,llx+(nc*cs),lly,lly+(nc*cs))
44 43
  grid=raster(ext,nrows=nc,ncol=nc,crs=proj)
45 44
  names(grid)=tile
45
  writeRaster(grid,paste(outdir,"/",tile,".tif",sep=""),options=c("COMPRESS=LZW"),datatype="INT1U",overwrite=T)
46 46
  return(grid)
47 47
}
48 48

  
49

  
49
## run it and save the extents as an Rdata object for easy retrieval
50 50
gs=expand.grid(h=0:35,v=0:17)
51 51
gs$tile=paste("h",sprintf("%02d",gs$h),"v",sprintf("%02d",gs$v),sep="")
52

  
53 52
modtiles=lapply(1:nrow(gs),function(i) maketile(gs$tile[i]))
54 53
names(modtiles)=gs$tile
55 54

  
56
## two tiles for testing
57
tiles=c("h22v02","h03v11")
58 55

  
59
## path to MOD11A1 file for this tile to align grid/extent
60
gridfile=list.files("/nobackupp4/datapool/modis/MOD11A2.005/2009.01.01",pattern=paste(tiles[1],".*[.]hdf$",sep=""),recursive=T,full=T)[1]
61
td=raster(paste("HDF4_EOS:EOS_GRID:\"",gridfile,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""))
56
## function to confirm that this method results in identical (e same extent, number of rows and columns, projection, resolution, and origin) rasters as MODIS LST data
57
checkgrid<-function(tile){
58
  print(tile)
59
  ## path to MOD11A1 file for this tile to align grid/extent
60
  gridfile=list.files("/nobackupp4/datapool/modis/MOD11A2.005/2009.01.01",pattern=paste(tile,".*[.]hdf$",sep=""),recursive=T,full=T)[1]
61
  if(!file.exists(gridfile)) return(NULL)
62
  td=raster(paste("HDF4_EOS:EOS_GRID:\"",gridfile,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""))
63
  td2=maketile(tile)
64
  return(compareRaster(td,td2,res=T,orig=T,rotation=T))
65
}
66

  
67
testing=F
68
if(testing){
69
  ## make the comparison for every tile
70
  dat=do.call(c,lapply(gs$tile,checkgrid))
71
  ## summarize the results
72
  table(dat)
73
}
climate/procedures/MOD35_Climatology.r
27 27
### path to NCO
28 28
ncopath="/nasa/sles11/nco/4.0.8/gcc/mpt/bin/"
29 29

  
30
### Vector of variables that must be in file or they will be deleted.
31
###  Formated as output from system(paste("cdo -s showvar ",fdly$path[i]),intern=T)
32
#finalvars=" CER COT CLD"
33

  
34

  
35 30
################################################################################
36 31
## Get list of all daily files
37 32
if(verbose) print(paste("Checking daily output in preparation for generating climatology:",tile))
......
60 55

  
61 56
## merge all daily files to create a single file with all dates
62 57
system(paste(ncopath,"ncrcat -O ",outdir,"/*nc ",outdir2,"/MOD35_",tile,"_daily.nc",sep=""))
58
system(paste("ncdump -h ",outdir2,"/MOD35_",tile,"_daily.nc",sep=""))
63 59
 
64 60
## Update attributes
65 61
system(paste(ncopath,"ncatted ",
66
" -a valid_min,PClear,o,b,0 ",
67
" -a valid_max,PClear,o,b,100 ",
68
#" -a valid_range,PClear,o,b,\"0,255\" ",
69
#" -a missing_value,PClear,o,b,255 ",
70
#" -a _FillValue,PClear,d,b,255 ",
71
" -a units,time,o,c,\"days since 2000-1-1 0:0:0\" ",
72 62
" -a title,global,o,c,\"MODIS Cloud Product (MOD35) Summaries\" ",
73 63
" -a institution,global,o,c,\"Yale University\" ",
74 64
" -a source,global,o,c,\"MODIS Collection 6 Cloud Mask (MOD35)\" ",
......
94 84

  
95 85
## Overall Means
96 86
if(verbose) print(paste("Calculating the overall mean:",tile))
97
system(paste("cdo -O -b I8 -v sorttimestamp -setyear,",myear," -setmon,1 -setday,1 -mulc,-1 -subc,100 -timmean -selyear,2009 ",outdir2,"/MOD35_",tile,"_daily.nc ",outdir2,"/MOD35_",tile,"_2009mean.nc",sep=""),wait=T)
98
system(paste(ncopath,"ncrename -v PClear,PCloud ",outdir2,"/MOD35_",tile,"_2009mean.nc",sep=""))
87
system(paste("cdo -O -b I8 -v sorttimestamp -setyear,",myear," -setmon,1 -setday,1 -mulc,100 -timmean -lec,1 ",outdir2,"/MOD35_",tile,"_daily.nc ",outdir2,"/MOD35_",tile,"_mean.nc",sep=""),wait=T)
88
system(paste(ncopath,"ncrename -v CMday,CFday -v CMnight,CFnight ",outdir2,"/MOD35_",tile,"_mean.nc",sep=""))
99 89
system(paste(ncopath,"ncatted ",
100
" -a long_name,PCloud,o,c,\"Mean Probability of Cloud\" ",
101
" -a missing_value,PCloud,o,b,255 ",
102
" -a _FillValue,PCloud,d,b,255 ",
103
outdir2,"/MOD35_",tile,"_2009mean.nc",sep=""))
90
" -a long_name,CFday,o,c,\"Daytime Cloud Frequency\" ",
91
" -a missing_value,CFday,o,b,255 ",
92
" -a _FillValue,CFday,d,b,255 ",
93
" -a long_name,CFnight,o,c,\"Nighttime Cloud Frequency\" ",
94
" -a missing_value,CFnight,o,b,255 ",
95
" -a _FillValue,CFnight,d,b,255 ",
96
outdir2,"/MOD35_",tile,"_mean.nc",sep=""))
104 97

  
105 98
## Monthly means
106 99
if(verbose) print(paste("Calculating the monthly means:",tile))
107
system(paste("cdo -O -b I8 -v sorttimestamp -setyear,",myear," -setday,15 -mulc,-1 -subc,100 -ymonmean ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymonmean.nc",sep=""),wait=T)
108
system(paste(ncopath,"ncrename -v PClear,PCloud ",tsdir,"/MOD35_",tile,"_ymonmean.nc",sep=""))
100
system(paste("cdo -O -b I8 sorttimestamp -setyear,",myear," -setday,15 -mulc,100  -ymonmean -lec,1 ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymonmean.nc",sep=""),wait=T)
101
system(paste(ncopath,"ncrename -v CMday,CFday -v CMnight,CFnight ",tsdir,"/MOD35_",tile,"_ymonmean.nc",sep=""))
109 102
system(paste(ncopath,"ncatted ",
110
" -a long_name,PCloud,o,c,\"Mean Probability of Cloud\" ",
111
" -a missing_value,PCloud,o,b,255 ",
112
" -a _FillValue,PCloud,d,b,255 ",
103
" -a long_name,CFday,o,c,\"Daytime Cloud Frequency\" ",
104
" -a units,CFday,o,c,\"Proportion (%)\" ",
105
" -a missing_value,CFday,o,b,255 ",
106
" -a _FillValue,CFday,d,b,255 ",
107
" -a long_name,CFnight,o,c,\"Nighttime Cloud Frequency\" ",
108
" -a units,CFnight,o,c,\"Proportion (%)\" ",
109
" -a missing_value,CFnight,o,b,255 ",
110
" -a _FillValue,CFnight,d,b,255 ",
113 111
tsdir,"/MOD35_",tile,"_ymonmean.nc",sep=""))
114 112

  
115 113

  
......
123 121

  
124 122
## Monthly standard deviation
125 123
if(verbose) print(paste("Calculating the monthly SD:",tile))
126
system(paste("cdo -O -b I8 sorttimestamp -setyear,",myear," -setday,15 -ymonstd -mulc,-1 -subc,100 -monmean ",
124
system(paste("cdo -O -b I8 sorttimestamp -setyear,",myear," -setday,15 -ymonstd -mulc,100 -monmean -lec,1 ",
127 125
    outdir2,"/MOD35_",tile,"_daily.nc ",
128 126
    tsdir,"/MOD35_",tile,"_ymonstd.nc",sep=""))
129
system(paste(ncopath,"ncrename -v PClear,PCloud_sd ",tsdir,"/MOD35_",tile,"_ymonstd.nc",sep=""))
127
system(paste(ncopath,"ncrename -v CMday,CFday_sd -v CMnight,CFnight_sd ",tsdir,"/MOD35_",tile,"_ymonstd.nc",sep=""))
130 128
system(paste(ncopath,"ncatted ",
131
" -a long_name,PCloud_sd,o,c,\"Standard Deviation of p(cloud)\" ",
129
" -a long_name,CFnight_sd,o,c,\"Standard Deviation of monthly nighttime cloud frequency\" ",
130
" -a long_name,CFday_sd,o,c,\"Standard Deviation of monthly daytime cloud frequency\" ",
132 131
tsdir,"/MOD35_",tile,"_ymonstd.nc",sep=""))
133 132

  
134 133
## frequency of cloud days p(clear<90%)  
135
if(verbose) print(paste("Calculating the proportion of cloudy and probably cloudy days:",tile))
136
system(paste("cdo -O -b I8 sorttimestamp -setyear,",myear," -setday,15 -ymonmean  -mulc,100 -lec,90 -selvar,PClear ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep=""))
137
system(paste(ncopath,"ncrename -v PClear,CF ",tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep=""))
138
system(paste(ncopath,"ncatted ",
139
" -a long_name,CF,o,c,\"Cloud Frequency: Proportion of Days with probability of clear < 90%\" ",
140
" -a units,CF,o,c,\"Proportion (%)\" ",
141
tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep=""))
134
#if(verbose) print(paste("Calculating the proportion of cloudy and probably cloudy days:",tile))
135
#system(paste("cdo -O -b I8 sorttimestamp -setyear,",myear," -setday,15 -ymonmean  -mulc,100 -lec,90 -selvar,PClear ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep=""))
136
#system(paste(ncopath,"ncrename -v PClear,CF ",tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep=""))
137
#system(paste(ncopath,"ncatted ",
138
#" -a long_name,CF,o,c,\"Cloud Frequency: Proportion of Days with probability of clear < 90%\" ",
139
#" -a units,CF,o,c,\"Proportion (%)\" ",
140
#tsdir,"/MOD35_",tile,"_ymoncld01.nc",sep=""))
142 141

  
143 142
## number of observations
144 143
if(verbose) print(paste("Calculating the number of missing variables:",tile))
145
system(paste("cdo -O -b I8 sorttimestamp  -setyear,",myear," -setday,15 -ymonmean -mulc,100  -eqc,9999 -setmisstoc,9999   -selvar,PClear ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymonmiss.nc",sep=""))
146
system(paste(ncopath,"ncrename -v PClear,Pmiss ",tsdir,"/MOD35_",tile,"_ymonmiss.nc",sep=""))
144
system(paste("cdo -O -b I8 sorttimestamp  -setyear,",myear," -setday,15 -ymonmean -mulc,100  -eqc,9999 -setmisstoc,9999 ",outdir2,"/MOD35_",tile,"_daily.nc ",tsdir,"/MOD35_",tile,"_ymonmiss.nc",sep=""))
145
system(paste(ncopath,"ncrename -v CMday,CFday_pmiss -v CMnight,CFnight_pmiss ",tsdir,"/MOD35_",tile,"_ymonmiss.nc",sep=""))
147 146
system(paste(ncopath,"ncatted ",
148
             " -a long_name,Pmiss,o,c,\"Proportion of Days with missing data\" ",
149
             " -a units,Pmiss,o,c,\"Proportion (%)\" ",
147
             " -a long_name,CFday_pmiss,o,c,\"Proportion of Days with missing data\" ",
148
             " -a units,CFday_pmiss,o,c,\"Proportion (%)\" ",
149
             " -a long_name,CFnight_pmiss,o,c,\"Proportion of Days with missing data\" ",
150
             " -a units,CFnight_pmiss,o,c,\"Proportion (%)\" ",
150 151
             tsdir,"/MOD35_",tile,"_ymonmiss.nc",sep=""))
151 152

  
152 153
## TODO: fix projection information so GDAL can read it correctly.
......
156 157
if(verbose) print(paste("Append all monthly climatologies into a single file:",tile))
157 158
system(paste(ncopath,"ncks -O ",tsdir,"/MOD35_",tile,"_ymonmean.nc  ",tsdir,"/MOD35_",tile,"_ymon.nc",sep=""))
158 159
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymonstd.nc  ",tsdir,"/MOD35_",tile,"_ymon.nc",sep=""))
159
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymoncld01.nc  ",tsdir,"/MOD35_",tile,"_ymon.nc",sep=""))
160
#system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymoncld01.nc  ",tsdir,"/MOD35_",tile,"_ymon.nc",sep=""))
160 161
system(paste(ncopath,"ncks -A ",tsdir,"/MOD35_",tile,"_ymonmiss.nc  ",tsdir,"/MOD35_",tile,"_ymon.nc",sep=""))
161 162

  
162 163
## append sinusoidal grid from one of input files as CDO doesn't transfer all attributes
climate/procedures/MOD35_L2_process.r
33 33
          q(status=1);
34 34
     }
35 35

  
36
testing=T
36
testing=F
37 37
platform="pleiades" 
38 38

  
39 39
## default date and tile to play with  (will be overwritten below when running in batch)
40 40
if(testing){
41 41
  date="20090129"
42
  tile="h11v08"
42 43
  tile="h17v00"
43 44
  verbose=T
44 45
}
......
69 70
  ## grass database
70 71
  gisBase="/u/armichae/pr/grass-6.4.2/"
71 72
  ## path to MOD11A1 file for this tile to align grid/extent
72
  gridfile=list.files("/nobackupp4/datapool/modis/MOD11A2.005/2009.01.01",pattern=paste(tile,".*[.]hdf$",sep=""),recursive=T,full=T)[1]
73
  td=readGDAL(paste("HDF4_EOS:EOS_GRID:\"",gridfile,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""))
73
  gridfile=list.files("/nobackupp1/awilso10/mod35/MODTILES/",pattern=tile,full=T)[1]
74
  td=raster(gridfile)
74 75
  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 "
75 76
}
76 77

  
......
232 233
  ## Define region by importing one MOD11A1 raster.
233 234
  print("Import one MOD11A1 raster to define grid")
234 235
  if(platform=="pleiades") {
235
    execGRASS("r.in.gdal",input=paste("HDF4_EOS:EOS_GRID:\"",gridfile,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""),
236
              output="modisgrid",flags=c("quiet","overwrite","o"))
236
    execGRASS("r.in.gdal",input=td@file@name,output="modisgrid",flags=c("quiet","overwrite","o"))
237 237
    system("g.region rast=modisgrid save=roi --overwrite",ignore.stdout=F,ignore.stderr=F)
238 238
  }
239 239

  
......
262 262
     ## Sensor Zenith      ## extract first bit to keep only "low angle" observations
263 263
     execGRASS("r.in.gdal",input=paste("SenZen_",bfile,sep=""),
264 264
             output=paste("SZ_",i,sep=""),flags=c("overwrite","o")) ; print("")
265
     
265
   
266 266
     ## check for interpolation artefacts
267 267
#     execGRASS("r.stats",input=paste("SZ_",i,sep=""),output=paste("SZ_",i,".txt",sep=""),flags=c("c"))
268 268
#     execGRASS("r.clump",input=paste("SZ_",i,sep=""),output=paste("SZ_",i,"_clump",sep=""))
269 269
#     execGRASS("r.stats",input=paste("SZ_",i,"_clump",sep=""),output="-",flags=c("c"))
270 270

  
271
     p=-50:50
272
     system(paste("r.mapcalc \"SZ_",i,"_clump=if(min(",paste("SZ_",i,"[0,",p,"]",sep="",collapse=","),")==max(",paste("SZ_",i,"[0,",p,"]",sep="",collapse=","),"),1,0)\"",sep=""))
273
     vals=do.call(rbind.data.frame,strsplit(execGRASS("r.stats",input=paste("SZ_",i,"_clump",sep=""),output="-",flags=c("c"),intern=T),split=" "))
274
     colnames(vals)=c("value","count")
275
     vals$count=as.numeric(as.character(vals$count))
276
     vals$value=as.numeric(as.character(vals$value))
277
     vals=na.omit(vals)
278
     vals$count[vals$value==1&vals$count>10]
271
     ## write out the table of weights for use in the neighborhood analysis to identify bad pixels from swtif
272
     p=75  #must be odd
273
     mat=matrix(rep(0,p*p),nrow=p)
274
     mat[0.5+p/2,]=1
275
     cat(mat,file="weights.txt")
276
     execGRASS("r.neighbors",input=paste("SZ_",i,sep=""),output=paste("SZ_",i,"clump",sep=""),method="range",size=p,weight="weights.txt")  # too slow!
277
     system(paste("r.mapcalc \"SZ_",i,"_clump2=SZ_",i,"clump==0\"",sep=""))
278

  
279
#     p=-50:50
280
#     system(paste("r.mapcalc \"SZ_",i,"_clump=if(min(",paste("SZ_",i,"[0,",p,"]",sep="",collapse=","),")==max(",paste("SZ_",i,"[0,",p,"]",sep="",collapse=","),"),1,0)\"",sep=""))
281
#     system(paste("r.mapcalc \"SZ_",i,"_clump=if(min(",paste("SZ_",i,"[0,",min(p,"]",sep="",collapse=","),")==max(",paste("SZ_",i,"[0,",p,"]",sep="",collapse=","),"),1,0)\"",sep=""))
282
#     vals=do.call(rbind.data.frame,strsplit(execGRASS("r.stats",input=paste("SZ_",i,"_clump",sep=""),output="-",flags=c("c"),intern=T),split=" "))
283
#     colnames(vals)=c("value","count")
284
#     vals$count=as.numeric(as.character(vals$count))
285
#     vals$value=as.numeric(as.character(vals$value))
286
#     vals=na.omit(vals)
287
#     vals$count[vals$value==1&vals$count>10]
279 288
                                            #
280 289
     #plot(p~value,data=vals)
281 290
#     print(sum(vals$p[vals$p>.1]))
282 291
     
283
     ## TODO: use this to flag problem swaths?
284 292
     ## Solar Zenith      ## extract first bit to keep only "low angle" observations
285 293
     execGRASS("r.in.gdal",input=paste("SolZen_",bfile,sep=""),
286 294
             output=paste("SoZ_",i,sep=""),flags=c("overwrite","o")) ; print("")
......
288 296
     system(paste("r.mapcalc <<EOF
289 297
                CM_fill_",i," =  if(isnull(CM1_",i,"),1,0)
290 298
                QA_useful_",i," =  if((QA_",i," / 2^0) % 2==1,1,0)
291
                SZ_low_",i," =  if(SZ_",i,"_clump==0&SZ_",i,"<6000,1,0)
299
                SZ_low_",i," =  if(SZ_",i,"_clump2==0&SZ_",i,"<6000,1,0)
292 300
                SoZ_low_",i," =  if(SoZ_",i,"<8500,1,0)
293 301
                CM_dayflag_",i," =  if((CM1_",i," / 2^3) % 2==1,1,0)
294 302
                CM_cloud_",i," =  if((CM1_",i," / 2^0) % 2==1,(CM1_",i," / 2^1) % 2^2,null())
295
                SZday_",i," = if(SZ_",i,"_clump==0&CM_dayflag_",i,"==1,SZ_",i,",null())
296
                SZnight_",i," = if(SZ_",i,"_clump==0&CM_dayflag_",i,"==0,SZ_",i,",null())
303
                SZday_",i," = if(SZ_",i,"_clump2==0&CM_dayflag_",i,"==1,SZ_",i,",null())
304
                SZnight_",i," = if(SZ_",i,"_clump2==0&CM_dayflag_",i,"==0,SZ_",i,",null())
297 305
                CMday_",i," = if(SoZ_low_",i,"==1&SZ_low_",i,"==1&QA_useful_",i,"==1&CM_dayflag_",i,"==1,CM_cloud_",i,",null())
298 306
                CMnight_",i," = if(SZ_low_",i,"==1&QA_useful_",i,"==1&CM_dayflag_",i,"==0,CM_cloud_",i,",null())
299 307
EOF",sep=""))
......
306 314
     if(drawplot){
307 315
       d2=stack(
308 316
#         raster(readRAST6(paste("QA_useful_",i,sep=""))),
309
#         raster(readRAST6(paste("CM1_",i,sep=""))),
317
         raster(readRAST6(paste("CM1_",i,sep=""))),
310 318
#         raster(readRAST6(paste("CM_cloud_",i,sep=""))),
311 319
#         raster(readRAST6(paste("CM_dayflag_",i,sep=""))),
312 320
#         raster(readRAST6(paste("CMday_",i,sep=""))),
313
         raster(readRAST6(paste("CMnight_",i,sep=""))),
321
#         raster(readRAST6(paste("CMnight_",i,sep=""))),
314 322
#         raster(readRAST6(paste("CM_fill_",i,sep=""))),
315 323
#         raster(readRAST6(paste("SoZ_",i,sep=""))),
316 324
         raster(readRAST6(paste("SZ_",i,sep=""))),
317
         raster(readRAST6(paste("SZ_",i,"_clump",sep="")))
325
         raster(readRAST6(paste("SZ_",i,"_clump",sep=""))),
326
         raster(readRAST6(paste("SZ_",i,"_clump2",sep="")))
318 327
         )
319 328
       plot(d2,add=F)
320 329
     }
......
335 344
))
336 345

  
337 346
if(plot){
338
  sz1=brick(lapply(1:nfs,function(i) raster(readRAST6(paste("SZnight_",i,sep="")))))
339
  sz_clump=brick(lapply(1:nfs,function(i) raster(readRAST6(paste("SZ_",i,"_clump",sep="")))))
340
  d=brick(lapply(1:nfs,function(i) raster(readRAST6(paste("CMnight_",i,sep="")))))
347
  ps=1:nfs
348
  ps=c(12,14,17)
349
  sz1=brick(lapply(ps,function(i) raster(readRAST6(paste("SZnight_",i,sep="")))))
350
  sz_clump=brick(lapply(ps,function(i) raster(readRAST6(paste("SZ_",i,"_clump2",sep="")))))
351
  d=brick(lapply(ps,function(i) raster(readRAST6(paste("CMnight_",i,sep="")))))
341 352
  d2=brick(list(raster(readRAST6("SZday_min")),raster(readRAST6("SZnight_min")),raster(readRAST6("CMday_daily")),raster(readRAST6("CMnight_daily"))))
342 353
  library(rasterVis)
343 354
  levelplot(sz1,col.regions=rainbow(100),at=seq(min(sz1@data@min),max(sz1@data@max),len=100))
......
350 361
  ### Write the files to a netcdf file
351 362
  ## create image group to facilitate export as multiband netcdf
352 363
    execGRASS("i.group",group="mod35",input=c("CMday_daily","CMnight_daily")) ; print("")
353
   
354
  if(file.exists(ncfile)) file.remove(ncfile)  #if it exists already, delete it
364

  
365
if(file.exists(ncfile)) file.remove(ncfile)  #if it exists already, delete it
355 366
  execGRASS("r.out.gdal",input="mod35",output=ncfile,type="Byte",nodata=255,flags=c("quiet"),
356 367
#      createopt=c("FORMAT=NC4","ZLEVEL=5","COMPRESS=DEFLATE","WRITE_GDAL_TAGS=YES","WRITE_LONLAT=NO"),format="netCDF")  #for compressed netcdf
357 368
      createopt=c("FORMAT=NC","WRITE_GDAL_TAGS=YES","WRITE_LONLAT=NO"),format="netCDF")
......
379 390
" -a missing_value,CMday,o,b,255 ",
380 391
" -a _FillValue,CMday,o,b,255 ",
381 392
" -a valid_range,CMday,o,b,\"0,3\" ",
382
" -a long_name,CMday,o,c,\"Cloud Flag from 'day' pixels\" ",
393
" -a long_name,CMday,o,c,\"Cloud Flag from day pixels\" ",
383 394
" -a units,CMnight,o,c,\"Cloud Flag (0-3)\" ",
384 395
" -a missing_value,CMnight,o,b,255 ",
385 396
" -a _FillValue,CMnight,o,b,255 ",
386 397
" -a valid_range,CMnight,o,b,\"0,3\" ",
387
" -a long_name,CMnight,o,c,\"Cloud Flag from 'night' pixels\" ",
398
" -a long_name,CMnight,o,c,\"Cloud Flag from night pixels\" ",
388 399
ncfile,sep=""))
389 400
#system(paste(ncopath,"ncatted -a sourcecode,global,o,c,",script," ",ncfile,sep=""))
390 401
   
......
398 409
      print(paste("FILE ERROR:  tile ",tile," and date ",date," was not outputted correctly, deleting... "))
399 410
      file.remove(ncfile)
400 411
    }
401

  
402 412
############  copy files to lou
403 413
#if(platform=="pleiades"){
404 414
#  archivedir=paste("MOD35/",outdir,"/",sep="")  #directory to create on lou
......
415 425

  
416 426

  
417 427
  ## print out some info
418
print(paste(" ###################################################################               Finished ",tile,"-",date,
419
"################################################################"))
428
print(paste("#######################               Finished ",tile,"-",date, "###################################"))
420 429

  
421 430
## delete old files
422 431
#system("cleartemp")
climate/procedures/Pleiades_MOD35.R
16 16
save(tb,file="modlandTiles.Rdata")
17 17
load("modlandTiles.Rdata")
18 18

  
19
## delete temporary log file that can grow to GB
20
system("rm /nobackupp1/awilso10/software/heg/TOOLKIT_MTD/runtime/LogStatus")
21

  
19
## Choose some tiles to process
22 20
### list of tiles to process
23 21
tiles=c("h10v08","h11v08","h12v08","h10v07","h11v07","h12v07")  # South America
24 22
## a northern block of tiles
25
expand.grid(paste("h",11:17,sep=""),v=c("v00","v01","v02","v03","v04"))
23
tiles=apply(expand.grid(paste("h",11:17,sep=""),v=c("v00","v01","v02","v03","v04")),1,function(x) paste(x,collapse="",sep=""))
24
## subset to MODLAND tiles
25
alltiles=system("ls -r MODTILES/ | grep tif$ | cut -c1-6 | sort | uniq - ",intern=T)
26 26

  
27
b## subset to MODLAND tiles
28
modlandtiles=system("ls -r /nobackupp4/datapool/modis/MOD11A1.005/2010* | grep hdf$ | cut -c18-23 | sort | uniq - ",intern=T)
29
 tb$land=tb$tile%in%modlandtiles
30
tiles=tb$tile[tb$land]
27
## subset to tiles in global region (not outside global boundary in sinusoidal projection)
28
tiles=tiles[tiles%in%alltiles]
31 29

  
32 30
## subset tile corner matrix to tiles selected above
33 31
tile_bb=tb[tb$tile%in%tiles,]
......
109 107
#x=x[order(rownames(x)),]
110 108

  
111 109
script="/u/awilso10/environmental-layers/climate/procedures/MOD35_L2_process.r"
112

  
110
 
113 111
## write the table processed by mpiexec
112
tp=T  # rerun everything
114 113
tp=((!proclist$done)&proclist$avail)  #date-tiles to process
115 114
table(Available=proclist$avail,Completed=proclist$done)
116 115

  
......
161 160
#######################################################
162 161
### Now submit the script to generate the climatologies
163 162

  
163
## report 'mostly' finished tiles
164
## this relyies on proclist above so be sure to update above before running
165
md=table(tile=proclist$tile[!proclist$done],year=proclist$year[!proclist$done])
166
mdt=names(md[md<10,])
167
tiles=mdt
164 168

  
165 169
tiles
166 170
ctiles=c("h10v08","h11v08","h12v08","h10v07","h11v07","h12v07")  # South America
......
191 195
### qsub script
192 196
cat(paste("
193 197
#PBS -S /bin/bash
194
#PBS -l select=40:ncpus=8:mem=94
198
#PBS -l select=10:ncpus=8:mem=94
195 199
#PBS -l walltime=2:00:00
196 200
#PBS -j n
197 201
#PBS -m be
......
202 206
#PBS -V
203 207
",if(delay) paste("#PBS -W depend=afterany:",job,sep="")," 
204 208

  
205
CORES=320
209
CORES=80
206 210
HDIR=/u/armichae/pr/
207 211
  source $HDIR/etc/environ.sh
208 212
  source /pleiades/u/awilso10/environ.sh
......
238 242

  
239 243
system("ssh lou")
240 244
#scp `find MOD35/summary -name "MOD35_h[0-9][0-9]v[0-9][0-9].nc"` adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod35/summary/
241
system("rsync -cavv `find summary -name \"MOD35_h[0-9][0-9]v[0-9][0-9]_2009mean.nc\"` adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod35/summary/")
245
system("rsync -cavv `find summary -name \"MOD35_h[0-9][0-9]v[0-9][0-9]_mean.nc\"` adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod35/summary/")
242 246
system("rsync -cavv `find summary -name \"MOD35_h[0-9][0-9]v[0-9][0-9].nc\"` adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/data/modis/mod35/summary/")
243 247

  
244 248

  

Also available in: Unified diff