Project

General

Profile

« Previous | Next » 

Revision f5ef0596

Added by Adam Wilson almost 11 years ago

Updated EE script to run in parallel and minor edits to post-processing

View differences:

climate/procedures/ee_compile.R
10 10
tempdir="tmp"
11 11
if(!file.exists(tempdir)) dir.create(tempdir)
12 12

  
13

  
14
## Load list of tiles
15
tiles=read.table("tile_lat_long_10d.txt",header=T)
16

  
17
jobs=expand.grid(tile=tiles$Tile,year=2000:2012,month=1:12)
18
jobs[,c("ULX","ULY","LRX","LRY")]=tiles[match(jobs$tile,tiles$Tile),c("ULX","ULY","LRX","LRY")]
19

  
20
## Run the python downloading script
21
#system("~/acrobates/adamw/projects/environmental-layers/climate/procedures/ee.MOD09.py -projwin -159 20 -154.5 18.5 -year 2001 -month 6 -region test")   
22
i=6715
23
testtiles=c("h02v07","h02v06","h02v08","h03v07","h03v06")
24
todo=which(jobs$tile%in%testtiles)
25
#todo=todo[1:3]
26
#todo=1:nrow(jobs)
27
lapply(todo,function(i)
28
         system(paste("~/acrobates/adamw/projects/environmental-layers/climate/procedures/ee.MOD09.py -projwin ",jobs$ULX[i]," ",jobs$ULY[i]," ",jobs$LRX[i]," ",jobs$LRY[i],
29
       "  -year ",jobs$year[i]," -month ",jobs$month[i]," -region ",jobs$tile[i],sep="")))
30

  
31

  
13 32
##  Get list of available files
14 33
df=data.frame(path=list.files("/mnt/data2/projects/cloud/mod09",pattern="*.tif$",full=T),stringsAsFactors=F)
15
df[,c("region","year","month")]=do.call(rbind,strsplit(basename(df$path),"_|[.]"))[,c(2,3,4)]
34
df[,c("region","year","month")]=do.call(rbind,strsplit(basename(df$path),"_|[.]"))[,c(1,2,3)]
16 35
df$date=as.Date(paste(df$year,"_",df$month,"_15",sep=""),"%Y_%m_%d")
17 36

  
18
table(df$year,df$month)#,df$region)
37
## subset to testtiles?
38
df=df[df$region%in%testtiles,]
39

  
40
table(df$year,df$month)
19 41

  
20 42
## drop some if not complete
21 43
#df=df[df$year<=2009,]
......
29 51
  ncfile=paste(tempdir,"/mod09_",date,".nc",sep="")
30 52
  if(!rerun&file.exists(ncfile)) next
31 53
  ## merge regions to a new netcdf file
32
  system(paste("gdal_merge.py -o ",ncfile," -of netCDF -ot Byte ",paste(df$path[df$date==date],collapse=" ")))
54
  system(paste("gdal_merge.py -o ",ncfile," -n -32768 -of netCDF -ot Int16 ",paste(df$path[df$date==date],collapse=" ")))
33 55
  system(paste("ncecat -O -u time ",ncfile," ",ncfile,sep=""))
34 56
## create temporary nc file with time information to append to MOD06 data
35 57
  cat(paste("
......
49 71
## add other attributes
50 72
  system(paste("ncrename -v Band1,CF ",ncfile,sep=""))
51 73
  system(paste("ncatted ",
52
" -a units,CF,o,c,\"Proportion Days Cloudy\" ",
53
" -a valid_range,CF,o,b,\"0,100\" ",
54
" -a long_name,CF,o,c,\"Proportion cloudy days (%)\" ",
55
ncfile,sep=""))
56
#" -a missing_value,CF,o,b,0 ",
57
#" -a _FillValue,CF,o,b,0 ", 
58
## add the fillvalue attribute back (without changing the actual values)
59
#system(paste("ncatted -a _FillValue,CF,o,b,255 ",ncfile,sep=""))
74
               " -a units,CF,o,c,\"Proportion Days Cloudy\" ",
75
#               " -a valid_range,CF,o,b,\"0,100\" ",
76
               " -a scale_factor,CF,o,f,\"0.1\" ",
77
               " -a long_name,CF,o,c,\"Proportion cloudy days (%)\" ",
78
               ncfile,sep=""))
79

  
80
               ## add the fillvalue attribute back (without changing the actual values)
81
#system(paste("ncatted -a _FillValue,CF,o,b,-32768 ",ncfile,sep=""))
60 82

  
61 83
if(as.numeric(system(paste("cdo -s ntime ",ncfile),intern=T))<1) {
62 84
  print(paste(ncfile," has no time, deleting"))

Also available in: Unified diff