Project

General

Profile

« Previous | Next » 

Revision d3dd2b2e

Added by Adam Wilson over 11 years ago

Add first version of script to develop global modis MODLAND grid

View differences:

climate/procedures/Build_Global_MODIS_tiles.R
1
### this script generates empty tifs that align with the MODIS land tiles, but are available globally
2

  
3

  
4
## get MODIS gring coordingates
5
tb=read.table("http://modis-land.gsfc.nasa.gov/pdf/sn_gring_10deg.txt",skip=7,nrows=648,header=F,sep="")
6
colnames(tb)=c("iv","ih","ll_lon","ll_lat","ul_lon","ul_lat","ur_lon","ur_lat","lr_lon","lr_lat")
7
tb$tile=paste("h",sprintf("%02d",tb$ih),"v",sprintf("%02d",tb$iv),sep="")
8
## drop null tiles
9
tb=tb[!is.na(tb$ll_lon)&tb$ll_lon!=-999,]
10
## transform to polygons
11
getgrid=function(i){
12
  print(i)
13
  x=tb[i,]
14
  gcols=matrix(as.numeric(c(x[3:10],x[3:4])),ncol=2,byrow=T)
15
  gpol= Polygons(list(Polygon(gcols)),tb[i,"tile"])
16
return(gpol)
17
}
18

  
19
modgrid=SpatialPolygons(lapply(1:nrow(tb),getgrid))
20
proj4string(modgrid)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
21

  
22
## transform to sinusoidal
23
modgrids=spTransform(modgrid,CRS("+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs "))
24

  
25
## two tiles for testing
26
tiles=c("h22v02","h03v11")
27

  
28
## path to MOD11A1 file for this tile to align grid/extent
29
gridfile=list.files("/nobackupp4/datapool/modis/MOD11A2.005/2009.01.01",pattern=paste(tiles[1],".*[.]hdf$",sep=""),recursive=T,full=T)[1]
30
td=raster(paste("HDF4_EOS:EOS_GRID:\"",gridfile,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""))
31
#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 "
32

  
33
gridfile2=list.files("/nobackupp4/datapool/modis/MOD11A2.005/2009.01.01",pattern=paste(tiles[2],".*[.]hdf$",sep=""),recursive=T,full=T)[1]
34
td2=raster(paste("HDF4_EOS:EOS_GRID:\"",gridfile2,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""))
35

  
36
  
climate/procedures/Pleiades_MOD35.R
21 21

  
22 22
### list of tiles to process
23 23
tiles=c("h10v08","h11v08","h12v08","h10v07","h11v07","h12v07")  # South America
24
## a northern block of tiles
25
expand.grid(paste("h",11:17,sep=""),v=c("v00","v01","v02","v03","v04"))
24 26

  
25
## subset to MODLAND tiles
26
 modlandtiles=system("ls -r /nobackupp4/datapool/modis/MOD11A1.005/2010* | grep hdf$ | cut -c18-23 | sort | uniq - ",intern=T)
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)
27 29
 tb$land=tb$tile%in%modlandtiles
28 30
tiles=tb$tile[tb$land]
29 31

  

Also available in: Unified diff