Project

General

Profile

Download (1.29 KB) Statistics
| Branch: | Revision:
1
# Mosaics two tiles of daily average clear day coverage for the clear day
2
# MODIS layer extracted from the MODIS LST files
3
#
4
# Reads a directory of .img files and mosaics the h08 and h09 tiles together
5
#
6
# Developed by John Donoghue
7
# Created: 20 October 2010
8
# Last Updated:
9
#
10
# For NCEAS Working Group Environment and Organisms
11
#
12

    
13
#setwd("/data/project/organisms/R")
14
#source("Mosaic Clear Day Average Grids.r", echo=TRUE, print.eval=TRUE)
15

    
16
setwd("/data/project/organisms/MODIS_LST_Oregon/ClearDayGDAL")
17
library(raster)
18

    
19
for(i in 1:366){
20
# get the two tiles that comprise each day of the year
21
myPattern <- paste("Day_", toString(i), "_.*img$", sep="")
22
print(myPattern)
23
inFiles <- list.files(pattern=myPattern)
24
nFiles <- length(inFiles)
25
print (nFiles)
26

    
27
# should only be two tiles at this point
28
h08Raster <- raster()
29
h08Raster <- raster(inFiles[1])
30
print(sprintf("Reading file: %s", inFiles[1]))
31
h09Raster <- raster()
32
h09Raster <- raster(inFiles[2])
33
print(sprintf("Reading file: %s", inFiles[2]))
34

    
35
newRaster <- merge(h08Raster, h09Raster)
36

    
37
# Check if file exists
38
outFile <- paste("Day_",toString(i),"_ClearDay_Average",".img",sep="")
39
if (file.exists(outFile) == FALSE) {
40
print(sprintf("...Writing file: %s",outFile))
41
writeRaster(newRaster,filename=outFile,format="HFA",overwrite=TRUE)
42
}
43
}
44

    
45
# finished
46
print("Finished")
47

    
(13-13/17)