-
Notifications
You must be signed in to change notification settings - Fork 1
/
MODIS_LAI.R
58 lines (34 loc) · 1.21 KB
/
MODIS_LAI.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require(raster)
library(ncdf)
source("ModisDownload.R")
source("WRF_functions.R")
CRS.WGS84 = CRS("+proj=longlat +datum=WGS84")
Sys.setenv(MRT_HOME="/Users/guido/local/MRT/",
MRT_DATA_DIR="/Users/guido/local/MRT//data")
ls = ModisDownloadGuido(x="MCD15A2",dates=c('2015.05.1','2015.05.30'), h=10:14, v=3:5)
# Remove those files that do not exist
#
valid = as.vector(sapply(ls[,2], file.exists))
ls = ls[valid,]
ModisMosaicGuido(ls,mosaic=T,
MRTpath="~/local/MRT/bin",pixel_size=.01, proj=T, proj_type="GEO")
# Read the MODIS grid
#
WRF = open.ncdf("~/geolab_storage/data/Marcellus/Reprojection/geo_em.d01.nc",write=T)
WRF.grid.polygons = WRF.grid2polygons(WRF)
WRF.grid.sp = SpatialPolygons(WRF.grid.polygons, proj4string = CRS.WGS84)
# Read the data
#
filename = "merged.tif"
dat = raster( filename )
dat.crop = crop(dat, WRF.grid.sp)
# Values from http://cybele.bu.edu/modismisr/products/modis/userguide.pdf
#
offset = 0
gain = 0.10
valid = c(0,100)
values = values(dat.crop)
values[ values<valid[1] | values>valid[2] ] = NA
values = values*gain + offset
values(dat.crop) = values
writeRaster(dat.crop, file="MODIS_LAI.tif",format="GTiff",overwrite=T)