Project

General

Profile

Download (2.4 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
tempdir="tmp"
9
if(!file.exists(tempdir)) dir.create(tempdir)
10

    
11

    
12
### Build Tiles
13

    
14
## bin sizes in degrees
15
ybin=30
16
xbin=30
17

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

    
32
jobs=expand.grid(tile=tiles$tile,year=2000:2012,month=1:12)
33
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")]
34

    
35
## drop Janurary 2000 from list (pre-modis)
36
jobs=jobs[!(jobs$year==2000&jobs$month==1),]
37

    
38

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

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

    
49
table(df$year,df$month)
50

    
51

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

    
57

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

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

    
66

    
67

    
68

    
69

    
(48-48/51)