Project

General

Profile

Download (2.34 KB) Statistics
| Branch: | Revision:
1
library(doMC)
2
library(foreach)
3
registerDoMC(4)
4

    
5
wd="~/acrobates/adamw/projects/cloud"
6
setwd(wd)
7

    
8
### Build Tiles
9

    
10
## bin sizes in degrees
11
ybin=30
12
xbin=30
13

    
14
tiles=expand.grid(ulx=seq(-180,180-xbin,by=xbin),uly=seq(90,-90+ybin,by=-ybin))
15
tiles$h=factor(tiles$ulx,labels=paste("h",sprintf("%02d",1:length(unique(tiles$ulx))),sep=""))
16
tiles$v=factor(tiles$uly,labels=paste("v",sprintf("%02d",1:length(unique(tiles$uly))),sep=""))
17
tiles$tile=paste(tiles$h,tiles$v,sep="")
18
tiles$urx=tiles$ulx+xbin
19
tiles$ury=tiles$uly
20
tiles$lrx=tiles$ulx+xbin
21
tiles$lry=tiles$uly-ybin
22
tiles$llx=tiles$ulx
23
tiles$lly=tiles$uly-ybin
24
tiles$cy=(tiles$uly+tiles$lry)/2
25
tiles$cx=(tiles$ulx+tiles$urx)/2
26
tiles=tiles[,c("tile","h","v","ulx","uly","urx","ury","lrx","lry","llx","lly","cx","cy")]
27

    
28
jobs=expand.grid(tile=tiles$tile,year=2000:2012,month=1:12)
29
jobs[,c("ulx","uly","urx","ury","lrx","lry","llx","lly")]=tiles[match(jobs$tile,tiles$tile),c("ulx","uly","urx","ury","lrx","lry","llx","lly")]
30

    
31
## drop Janurary 2000 from list (pre-modis)
32
jobs=jobs[!(jobs$year==2000&jobs$month==1),]
33

    
34

    
35
## Run the python downloading script
36
#system("~/acrobates/adamw/projects/environmental-layers/climate/procedures/ee.MOD09.py -projwin -159 20 -154.5 18.5 -year 2001 -month 6 -region test")   
37
i=1
38
todo=1:nrow(jobs)
39

    
40
##  Get list of available files
41
df=data.frame(path=list.files("/mnt/data2/projects/cloud/mod09",pattern="*.tif$",full=T,recur=T),stringsAsFactors=F)
42
df[,c("region","year","month")]=do.call(rbind,strsplit(basename(df$path),"_|[.]"))[,c(1,2,3)]
43
df$date=as.Date(paste(df$year,"_",df$month,"_15",sep=""),"%Y_%m_%d")
44

    
45
table(df$year,df$month)
46

    
47

    
48
checkcomplete=T
49
if(checkcomplete&exists("df")){  #if desired (and "df" exists from below) drop complete date-tiles
50
todo=which(!paste(jobs$tile,jobs$year,jobs$month)%in%paste(df$region,df$year,df$month))
51
}
52

    
53

    
54
writeLines(paste("Tiling options will produce",nrow(tiles),"tiles and ",nrow(jobs),"tile-months.  Current todo list is ",length(todo)))
55

    
56
t=foreach(i=todo,.inorder=FALSE,.verbose=F) %dopar%{
57
    system(paste("python ~/acrobates/adamw/projects/environmental-layers/climate/procedures/ee.MOD09.py -projwin ",
58
                      jobs$ulx[i]," ",jobs$uly[i]," ",jobs$urx[i]," ",jobs$ury[i]," ",jobs$lrx[i]," ",jobs$lry[i]," ",jobs$llx[i]," ",jobs$lly[i]," ",
59
                      "  -year ",jobs$year[i]," -month ",jobs$month[i]," -region ",jobs$tile[i],sep=""))
60
     }
61

    
62

    
63

    
64

    
65

    
(8-8/8)