Project

General

Profile

« Previous | Next » 

Revision f9695052

Added by Adam Wilson over 10 years ago

add validation report file

View differences:

climate/research/cloud/MOD09/4_ValidationAppendix.Rmd
1
Validation
2
----------------------
3

  
4
```{r,echo=F}
5

  
6
## working directory
7
setwd("/mnt/data/personal/adamw/projects/cloud/")
8
## libraries
9
library(rasterVis)
10
library(latticeExtra)
11
library(xtable)
12
library(texreg)
13
library(reshape)
14
library(caTools)
15
library(rgeos)
16
library(raster)
17

  
18
## read in global coasts for nice plotting
19
library(maptools)
20
library(rgdal)
21

  
22
```
23

  
24
```{r, loaddata,echo=F}
25
# read in data
26
cldm=read.csv("data/NDP026D/cldm.csv")
27
st=read.csv("data/NDP026D/stations.csv")
28

  
29
## month factors
30
cldm$month2=factor(cldm$month,labels=month.name,ordered=T)
31

  
32
### Drop valitation station-months with fewer than 20 years of data for full record or less than 10 years for MODIS-era record
33
cldm$cld_all[cldm$cldn_all<20]=NA
34
cldm$cldsd_all[cldm$cldn_all<20]=NA
35

  
36
cldm$cld[cldm$cldn<10]=NA
37
cldm$cldsd[cldm$cldn<10]=NA
38

  
39
coordinates(st)=c("lon","lat")
40
projection(st)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
41

  
42
#coast=getRgshhsMap("/mnt/data/jetzlab/Data/environ/global/gshhg/gshhs_h.b", xlim = NULL, ylim = NULL, level = 4) 
43
land=readShapePoly("/mnt/data/jetzlab/Data/environ/global/gshhg/GSHHS_shp/c/GSHHS_c_L1.shp",force_ring=TRUE)
44
projection(land)="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
45
CP <- as(extent(-180, 180, -60, 84), "SpatialPolygons")
46
proj4string(CP) <- CRS(proj4string(land))
47
coast=as(land[land$area>50,],"SpatialLines")
48
## Clip the map
49
land <- gIntersection(land, CP, byid=F)
50
coast <- gIntersection(coast, CP, byid=F)
51

  
52
#### Evaluate MOD35 Cloud data
53
##mod09=brick("data/cloud_monthly.nc")
54
```
55

  
56
```{r}
57
## Figures
58
n=100
59
at=seq(0,100,length=n)
60
colr=colorRampPalette(c("black","green","red"))
61
cols=colr(n)
62

  
63
## set plotting parameters
64
my.theme = trellis.par.get()
65
my.theme$strip.background=list(col="transparent")
66
trellis.par.set(my.theme)
67

  
68
#pdf("output/Figures.pdf",width=11,height=8.5)
69
png("output/CF_Figures_%03d.png",width=5000,height=4000,res=600,pointsize=42,bg="white")
70

  
71
## set plotting parameters
72
my.theme = trellis.par.get()
73
my.theme$strip.background=list(col="transparent")
74
trellis.par.set(my.theme)
75

  
76
greg=list(ylim=c(-60,84),xlim=c(-180,180))
77
    
78
bgr=function(x,n=100,br=0,c1=c("darkblue","blue","grey"),c2=c("grey","red","purple")){
79
    at=unique(c(seq(min(x,na.rm=T),max(x,na.rm=T),len=n)))
80
    bg=colorRampPalette(c1)
81
    gr=colorRampPalette(c2)
82
    return(list(at=at,col=c(bg(sum(at<br)),gr(sum(at>=br)))))
83
}
84

  
85
cldm$resid=NA
86
# get residuals of simple linear model
87
cldm$resid[!is.na(cldm$cld_all)&!is.na(cldm$mod09)]=residuals(lm(mod09~cld_all,data=cldm))
88
colat=bgr(cldm$resid)
89
phist=histogram(cldm$resid,breaks=colat$at,border=NA,col=colat$col,xlim=c(-30,30),type="count",xlab="MODCF Residuals")#,seq(0,1,len=6),na.rm=T)
90
pmap=xyplot(lat~lon|month2,data=cldm,groups=cut(cldm$resid,rev(colat$at)),
91
       par.settings=list(superpose.symbol=list(col=colat$col)),pch=16,cex=.25,
92
       auto.key=F,#list(space="right",title="Difference\n(MOD09-NDP026D)",cex.title=1),asp=1,
93
       ylab="Latitude",xlab="Longitude")+
94
  layer(sp.lines(coast,col="black",lwd=.1),under=F)
95
print(phist,position=c(0,.75,1,1),more=T)
96
print(pmap,position=c(0,0,1,.78))
97

  
98
### heatmap of mod09 vs. NDP for all months
99
hmcols=colorRampPalette(c("grey","blue","red","purple"))
100
#hmcols=colorRampPalette(c(grey(.8),grey(.3),grey(.2)))
101
tr=c(0,66)
102
colkey <- draw.colorkey(list(col = hmcols(tr[2]), at = tr[1]:tr[2],height=.25))
103

  
104
xyplot(cld_all~mod09|month2,data=cldm,panel=function(x,y,subscripts){
105
  n=50
106
  bins=seq(0,100,len=n)
107
  tb=melt(as.matrix(table(
108
    x=cut(x,bins,labels=bins[-1]),
109
    y=cut(y,bins,labels=bins[-1]))))
110
  qat=unique(tb$value)
111
  print(max(qat))
112
  qat=tr[1]:tr[2]#unique(tb$value)
113
  panel.levelplot(tb$x,tb$y,tb$value,at=qat,col.regions=c("transparent",hmcols(length(qat))),subscripts=1:nrow(tb))
114
#  panel.abline(0,1,col="black",lwd=2)
115
  panel.abline(lm(y ~ x),col="black",lwd=2)
116
#  panel.ablineq(lm(y ~ x), r.sq = TRUE,at = 0.6,pos=1, offset=0,digits=2,col="blue")
117
  panel.text(70,10,bquote(paste(R^2,"=",.(round(summary(lm(y ~ x))$r.squared,2)))),cex=1)
118
},asp=1,scales=list(at=seq(0,100,len=6),useRaster=T,colorkey=list(width=.5,title="Number of Stations")),
119
          ylab="NDP Mean Cloud Amount (%)",xlab="MODCF Cloud Frequency (%)",
120
              legend= list(right = list(fun = colkey)))#+ layer(panel.abline(0,1,col="black",lwd=2))
121

  
122

  
123
bwplot(lulcc~difm,data=cldm,horiz=T,xlab="Difference (MOD09-Observed)",varwidth=T,notch=T)+layer(panel.abline(v=0))
124

  
125
dev.off()
126

  
127
####################################################################
128
### Regional Comparisons
129
## Compare with worldclim and NPP
130
#wc=stack(as.list(paste("/mnt/data/jetzlab/Data/environ/global/worldclim/prec_",1:12,".bil",sep="")))
131
wc_map=stack(as.list(paste("/mnt/data/jetzlab/Data/environ/global/worldclim/bio_12.bil",sep="")))
132
wc_dem=stack(as.list(paste("/mnt/data/jetzlab/Data/environ/global/worldclim/alt.bil",sep="")))
133

  
134
regs=list(
135
  Cascades=extent(c(-122.8,-118,44.9,47)),
136
  Hawaii=extent(c(-156.5,-154,18.75,20.5)),
137
  Boliva=extent(c(-71,-63,-20,-15)),
138
  Venezuela=extent(c(-69,-59,0,7)),
139
  CFR=extent(c(17.75,22.5,-34.8,-32.6)),
140
  Madagascar=extent(c(46,52,-17,-12))
141
  #reg2=extent(c(-81,-70,-4,10))
142
  )
143

  
144

  
145
## read in GEWEX 1-degree data
146
gewex=mean(brick("data/gewex/CA_PATMOSX_NOAA.nc",varname="a_CA"))
147
names(gewex)="PATMOS-x GEWEX AVHRR"
148

  
149
## calculate 1-degree means of MODCF data
150
#MOD_gewex=gewex
151
#MOD_gewex@data@values=1:length(MOD_gewex@data@values)
152
#MOD_gewex2=zonal(mod09a,MOD_gewex,fun='mean')
153
png("output/Resolution_Figures_%03d.png",width=5500,height=4000,res=600,pointsize=36,bg="white")
154
trellis.par.set(my.theme)
155
#pdf("output/mod09_resolution.pdf",width=11,height=8.5)
156

  
157
r="Venezuela"
158
# ylab.right = "Cloud Frequency (%)",par.settings = list(layout.widths = list(axis.key.padding = 0.1,axis.left=0.6,ylab.right = 3,right.padding=2)),
159
pars=list(layout.heights=list(key.bottom=2,key.top=1),layout.widths = list(axis.key.padding = 3,axis.left=0.6))
160
p1=levelplot(crop(mod09a,regs[[r]]),col.regions=grey(seq(0,1,len=100)),at=seq(45,100,len=99),
161
    colorkey=list(space="top",width=1,height=.75,labels=list(labels=c(50,75,100),at=c(50,75,100))),
162
    cuts=99,margin=F,max.pixels=1e6,par.settings = pars)
163
p2=levelplot(crop(gewex,regs[[r]]),col.regions=grey(seq(0,1,len=100)),at=seq(.45,1,len=99),cuts=99,margin=F,max.pixels=1e6,
164
    colorkey=list(space="top",width=1,height=.75,labels=list(labels=c(50,75,100),at=c(.50,.75,1))),
165
    par.settings = pars)
166
tmap=crop(wc_map,regs[[r]])
167
p3=levelplot(tmap,col.regions=grey(seq(0,1,len=100)),cuts=100,at=seq(tmap@data@min,tmap@data@max,len=100),margin=F,maxpixels=1e6,
168
    colorkey=list(space="bottom",height=.75,width=1),xlab="",ylab="",main=names(regs)[r],useRaster=T,
169
    par.settings = pars)
170
p4=levelplot(crop(wc_dem,regs[[r]]),col.regions=grey(seq(0,1,len=100)),cuts=99,margin=F,max.pixels=1e6,
171
    colorkey=list(space="bottom",height=.75,width=1),
172
    par.settings = pars)#,labels=list(labels=c(1000,4000),at=c(1000,4000))))
173
print(c("MODCF (%)"=p1,"PATMOS-x GEWEX (%)"=p2,"WorldClim Precip (mm)"=p3,"Elevation (m)"=p4,x.same=T,y.same=T,merge.legends=T,layout=c(2,2)))
174

  
175

  
176
dev.off()
177

  
178

  
179
#########################################
180
### Some stats for paper
181

  
182
## number of stations retained
183
length(unique(cldm$StaID[!is.na(cldm$cld_all)]))
184
length(unique(cldm$StaID[!is.na(cldm$cld)]))
185

  
186
# approximate size of mod09ga archive - get total size for one day from the USGS website
187
size=scan("http://e4ftl01.cr.usgs.gov/MOLT/MOD09GA.005/2000.04.30/",what="char")
188
## extract all filesizes in MB (all the HDFs) and sum them and covert to TB for the length of the full record
189
sum(as.numeric(sub("M","",grep("[0-9]*M$",size,value=T))))/1024/1024*as.numeric(as.Date("2013-12-31")-as.Date("2000-02-24"))
190

  
191
## seasonal variability
192
cellStats(mod09sd,"mean")
193

  
194
## Validation table construction
195
quantile(cldm$difm,na.rm=T)
196

  
197
summary(lm(cld_all~mod09+lat,data=cldm))
198

  
199
              
200

  
201
###################################################################
202
### summary by biome
203
biomep$id=1:nrow(biomep)
204
biomepl=melt(biomep@data,id.vars=c("id","code","biome","realm"))
205
colnames(biomepl)[grep("variable",colnames(biomepl))]="month"
206
biomepl$month=factor(biomepl$month,ordered=T,levels=month.name)
207
biomepl$realm=factor(biomepl$realm,ordered=T,levels=c("Antarctic","Australasia","Oceania", "IndoMalay", "Neotropics","Palearctic","Nearctic" ))
208
biomepl$value[biomepl$value<0]=NA
209

  
210

  
211
png("output/Biome_Figures_%03d.png",width=5500,height=4000,res=600,pointsize=36,bg="white")
212
trellis.par.set(my.theme)
213

  
214
#[biomepl$id%in%sample(biomep$id,10000),]
215
p1=useOuterStrips(xyplot(value~month|realm+biome,groups=id,data=biomepl,panel=function(x,y,groups = groups, subscripts = subscripts){
216
    panel.xyplot(x,y,col=grey(0.6,0.2),type="l",lwd=.5,groups=groups,subscripts=subscripts)
217
    panel.smoother(y ~ s(x), method = "gam",lwd=2,subscripts=subscripts,n=24)
218
},scales=list(y=list(at=c(0,100),lim=c(-20,120),cex=.75,alternating=2,tck=c(0,1)),x=list(at=c(1,7),rot=45,alternating=1)),ylab="Biome",xlab.top="Geographic Realm",ylab.right="MODCF (%)", xlab="Month"),
219
    strip=strip.custom(par.strip.text = list(cex = .7)),strip.left=strip.custom(horizontal=TRUE,par.strip.text = list(cex = .75)))
220
p1$par.settings$layout.widths$strip.left[1]=13
221
p1$par.strip.text$lines=.65
222
print(p1)
223

  
224
dev.off()
225

  
226

  
227
####################################################################
228
## assess temporal stability
229

  
230
## spatialy subset data to stations at least 10km apart
231
st2=remove.duplicates(st,zero=10)
232

  
233
## Subset data
234
## drop missing observations
235
cldm.t=cldm[!is.na(cldm$cld_all)&!is.na(cldm$mod09)&!is.na(cldm$biome),]
236
cldm.t=cldm.t[cldm.t$lat>=-60,]
237
#  make sure all stations have all mod09 data
238
stdrop=names(which(tapply(cldm.t$month,cldm.t$StaID,length)!=12))
239
cldm.t=cldm.t[!cldm.t$StaID%in%stdrop,]
240
# Keep only stations at least 10km apart 
241
cldm.t=cldm.t[cldm.t$StaID%in%st2$id,]
242
## Subset to only some months, if desired
243
#cldm.t=cldm.t[cldm.t$month%in%1:3,]
244

  
245

  
246
## Select Knots
247
knots=spsample(land,500,type="regular")
248

  
249
                                        #  reshape data
250
m.cld=cast(cldm.t,StaID+lat+lon+biome~month,value="cld_all");colnames(m.cld)[-(1:4)]=paste("cld.",colnames(m.cld)[-(1:4)],sep="")
251
m.mod09=cast(cldm.t,StaID~month,value="mod09");colnames(m.mod09)[-1]=paste("mod09.",colnames(m.mod09)[-1],sep="")
252
mdata=cbind(m.cld,m.mod09)
253

  
254
## cast to 
255
coords <- as.matrix(m.cld[,c("lon","lat")])#as.matrix(ne.temp[,c("UTMX", "UTMY")]/1000)
256
max.d <- max(iDist(coords))
257

  
258
##make symbolic model formula statement for each month
259
mods <- lapply(paste(paste(paste("cld.",1:N.t,sep=''),paste("mod09.",1:N.t,sep=''),sep='~'),"",sep=""), as.formula)
260

  
261
tlm=model.matrix(lm(mods[[1]],data=mdata))
262

  
263
N.t <- ncol(m.mod09)-1 ##number of months
264
n <- nrow(m.cld) ##number of observation per months
265
p <- ncol(tlm) #number of regression parameters in each month
266

  
267
starting <- list("beta"=rep(0,N.t*p), "phi"=rep(3/(0.5*max.d), N.t),
268
                 "sigma.sq"=rep(2,N.t), "tau.sq"=rep(1, N.t),
269
                 "sigma.eta"=diag(rep(0.01, p)))
270
tuning <- list("phi"=rep(5, N.t))
271

  
272
priors <- list("beta.0.Norm"=list(rep(0,p), diag(1000,p)),
273
               "phi.Unif"=list(rep(3/(0.9*max.d), N.t), rep(3/(0.05*max.d), N.t)),
274
               "sigma.sq.IG"=list(rep(2,N.t), rep(10,N.t)),
275
               "tau.sq.IG"=list(rep(2,N.t), rep(5,N.t)),
276
               "sigma.eta.IW"=list(2, diag(0.001,p)))
277
cov.model <- "exponential"
278

  
279
## Run the model
280
n.samples <- 500
281
m.1=spDynLM(mods,data=mdata,coords=coords,knots=coordinates(knots),n.samples=n.samples,starting=starting,tuning=tuning,priors=priors,cov.model=cov.model,get.fitted=T,n.report=25)
282

  
283
save(m.1,file="output/m.1.Rdata")
284
## summarize
285
burn.in <- floor(0.75*n.samples)
286
quant <- function(x){quantile(x, prob=c(0.5, 0.025, 0.975))}
287
beta <- apply(m.1$p.beta.samples[burn.in:n.samples,], 2, quant)
288
beta.0 <- beta[,grep("Intercept", colnames(beta))]
289
beta.1 <- beta[,grep("mod09", colnames(beta))]
290

  
291

  
292

  
293

  
294
### Compare time periods
295
library(texreg)
296
 extract.lm <- function(model) {
297
     s <- summary(model)
298
     names <- rownames(s$coef)
299
     co <- s$coef[, 1]
300
     se <- s$coef[, 2]
301
     pval <- s$coef[, 4]
302
     rs <- s$r.squared
303
     n <- as.integer(nobs(model))
304
     rmse=sqrt(mean((residuals(s)^2)))
305
     gof <- c(rs, rmse, n)
306
     gof.names <- c("R-Squared","RMSE","n")
307
     tr <- createTexreg(coef.names = names, coef = co, se = se, 
308
                        pvalues = pval, gof.names = gof.names, gof = gof)
309
     return(tr)
310
 }
311
setMethod("extract", signature = className("lm", "stats"),definition = extract.lm)
312

  
313
forms=c("cld~mod09+month2+lat")
314
lm_all=lm(cld_all~mod09+lat,data=cldm[!is.na(cldm$cld),])
315

  
316

  
317
### Compare two time periods
318
lm_all1=lm(cld_all~mod09,data=cldm[!is.na(cldm$cld)&cldm$cldn_all>=10,])
319

  
320
lm_mod=lm(cld~mod09,data=cldm[cldm$cldn==10,])
321
mods=list("1970-2009"=lm_all1,"2000-2009"=lm_mod)
322

  
323
screenreg(mods,digits=2,single.row=T,custom.model.names=names(mods),custom.coef.names = c("Intercept", "MODCF"))
324

  
325
htmlreg(mods,file = "output/tempstab.doc",
326
        custom.model.names = names(mods),
327
        single.row = T, inline.css = FALSE,doctype = TRUE, html.tag = TRUE, head.tag = TRUE, body.tag = TRUE)
328

  
329

  
330
## assess latitude bias
331
cldm$abslat=abs(cldm$lat)
332
cldm$absdif=abs(cldm$difm)
333
abslm=lm(absdif~abslat*I(abslat^2),data=cldm[cldm$cldn_all>30,])
334

  
335
xyplot(absdif~abslat|month2,type=c("p","smooth"),data=cldm,cex=.25,pch=16)
336

  
337
plot(absdif~abslat,data=cldm[cldm$cldn_all>30,],cex=.25,pch=16)
338
lines(0:90,predict(abslm,newdata=data.frame(abslat=0:90),type="response"),col="red")
339

  
340
bf=anovaBF(dif~lulcc+month2,data=cldm[!is.na(cldm$dif)&!is.na(cldm$lulcc),])
341
ch=posterior(bf, iterations = 1000)
342
summary(bf)
343
plot(bf)
344

  
345
## explore validation error
346
cldm$lulcc=as.factor(IGBP$class[match(cldm$lulc,IGBP$ID)])
347

  
348
## Table of RMSE's by lulc by month
349
lulctl=ddply(cldm,c("month","lulc"),function(x) c(count=nrow(x),rmse=sqrt(mean((x$mod09-x$cld)^2,na.rm=T))))
350
lulctl=lulctl[!is.na(lulctl$lulc),]
351
lulctl$lulcc=as.factor(IGBP$class[match(lulctl$lulc,IGBP$ID)])
352

  
353
lulctl=ddply(cldm,c("lulc"),function(x) c(count=nrow(x),mean=paste(round(mean(x$difm,na.rm=T),2)," (",round(sd(x$difm,na.rm=T),2),")",sep=""),rmse=round(sqrt(mean((x$difm)^2,na.rm=T)),2)))
354
lulctl$lulcc=as.factor(IGBP$class[match(lulctl$lulc,IGBP$ID)])
355
    print(xtable(lulctl[order(lulctl$rmse),c("lulcc","count","mean","rmse")],digits=1),type="html",include.rownames=F,file="output/lulcc.doc",row.names=F)
356
    
357

  
358
lulcrmse=cast(lulcrmsel,lulcc~month,value="rmse")
359
lulcrmse
360

  
361
lulcrmse.q=round(do.call(rbind,apply(lulcrmse,1,function(x) data.frame(Min=min(x,na.rm=T),Mean=mean(x,na.rm=T),Max=max(x,na.rm=T),SD=sd(x,na.rm=T)))),1)#quantile,c(0.025,0.5,.975),na.rm=T)),1)
362
lulcrmse.q=lulcrmse.q[order(lulcrmse.q$Mean,decreasing=T),]
363
lulcrmse.q
364

  
365
print(xtable(lulcrmse,digits=1),"html")
366

  
367
bgyr=colorRampPalette(c("blue","green","yellow","red"))
368
levelplot(rmse~month*lulcc,data=lulcrmsel,col.regions=bgyr(1000),at=quantile(lulcrmsel$rmse,seq(0,1,len=100),na.rm=T))
369

  
370

  
371
### Linear models
372
summary(lm(dif~as.factor(lulc)+lat+month2,data=cldm))
373

  
climate/research/cloud/MOD09/4_validate.R
82 82

  
83 83

  
84 84
## add the EarthEnvCloud data to cld
85
mod09=stack(list.files("data/mcd09tif/",pattern="MCD09_[0-9]*[.]tif",full=T))
86
NAvalue(mod09)=255
87
#mod09std=brick("~/acrobates/adamw/projects/cloud/data/cloud_ymonstd.nc")
85
mod09_mean=stack(list.files("data/mcd09tif/",pattern="MCD09_mean_[0-9]*[.]tif",full=T))
86
NAvalue(mod09_mean)=255
87
names(mod09_mean)=month.name
88

  
89
mod09_sd=stack(list.files("data/mcd09tif/",pattern="MCD09_sd_[0-9]*[.]tif",full=T))
90
NAvalue(mod09_sd)=255
91
names(mod09_sd)=month.name
92

  
88 93

  
89 94
## overlay the data with 32km diameter (16km radius) buffer
90 95
## buffer size from Dybbroe, et al. (2005) doi:10.1175/JAM-2189.1.
......
92 97
bins=cut(st$lat,10)
93 98
rerun=F
94 99
if(rerun&file.exists("valid.csv")) file.remove("valid.csv")
100

  
101
beginCluster(12)
102

  
95 103
mod09sta=lapply(levels(bins),function(lb) {
96 104
  l=which(bins==lb)
97 105
  ## mean
98
  td=extract(mod09,st[l,],buffer=buf,fun=mean,na.rm=T,df=T)
106
  td=extract(mod09_mean,st[l,],buffer=buf,fun=mean,na.rm=T,df=T)
99 107
  td$id=st$id[l]
100 108
  td$type="mean"
101 109
  ## std
102
  td2=extract(mod09std,st[l,],buffer=buf,fun=mean,na.rm=T,df=T)
110
  td2=extract(mod09_sd,st[l,],buffer=buf,fun=mean,na.rm=T,df=T)
103 111
  td2$id=st$id[l]
104 112
  td2$type="sd"
105 113
  print(lb)#as.vector(c(l,td[,1:4])))
......
107 115
  td
108 116
})#,mc.cores=3)
109 117

  
118
endCluster()
119

  
110 120
## read it back in
111 121
mod09st=read.csv("valid.csv",header=F)[,-c(1)]
112
colnames(mod09st)=c(names(mod09),"id","type")
122
colnames(mod09st)=c(names(mod09_mean),"id","type")
113 123
mod09stl=melt(mod09st,id.vars=c("id","type"))
114
mod09stl[,c("year","month")]=do.call(rbind,strsplit(sub("X","",mod09stl$variable),"[.]"))[,1:2]
124
colnames(mod09stl)[grep("variable",colnames(mod09stl))]="month"
125
#mod09stl[,c("year","month")]=do.call(rbind,strsplit(sub("X","",mod09stl$variable),"[.]"))[,1:2]
115 126
mod09stl$value[mod09stl$value<0]=NA
116
mod09stl=cast(mod09stl,id+year+month~type,value="value")
127
mod09stl=cast(mod09stl,id+month~type,value="value")
117 128

  
118 129
## add it to cld
119
cldm$mod09=mod09stl$mean[match(paste(cldm$StaID,cldm$month),paste(mod09stl$id,as.numeric(mod09stl$month)))]
120
cldm$mod09sd=mod09stl$sd[match(paste(cldm$StaID,cldm$month),paste(mod09stl$id,as.numeric(mod09stl$month)))]
130
cldm$monthname=month.name[cldm$month]
131
cldm$mod09=mod09stl$mean[match(paste(cldm$StaID,cldm$monthname),paste(mod09stl$id,mod09stl$month))]
132
cldm$mod09sd=mod09stl$sd[match(paste(cldm$StaID,cldm$monthname),paste(mod09stl$id,mod09stl$month))]
121 133

  
122 134

  
123 135
## LULC
124 136
#system(paste("gdalwarp -r near -co \"COMPRESS=LZW\" -tr ",paste(res(mod09),collapse=" ",sep=""),
125 137
#             "-tap -multi -t_srs \"",   projection(mod09),"\" /mnt/data/jetzlab/Data/environ/global/landcover/MODIS/MCD12Q1_IGBP_2005_v51.tif ../modis/mod12/MCD12Q1_IGBP_2005_v51.tif"))
126
lulc=raster("~/acrobates/adamw/projects/interp/data/modis/mod12/MCD12Q1_IGBP_2005_v51.tif")
138
lulc=raster("/mnt/data/personal/adamw/projects/interp/data/modis/mod12/MCD12Q1_IGBP_2005_v51.tif")
127 139
require(plotKML); data(worldgrids_pal)  #load IGBP palette
128 140
IGBP=data.frame(ID=0:16,col=worldgrids_pal$IGBP[-c(18,19)],stringsAsFactors=F)
129 141
IGBP$class=rownames(IGBP);rownames(IGBP)=1:nrow(IGBP)
......
141 153

  
142 154

  
143 155
### Add biome data
144
biome=readOGR("../teow/","biomes")
156
biome=readOGR("data/teow/","biomes")
145 157
projection(biome)=projection(st)
146 158
#st$biome=over(st,biome,returnList=F)$BiomeID
147 159
dists=apply(gDistance(st,biome,byid=T),2,which.min)
......
155 167

  
156 168

  
157 169
## write out the tables
158
write.csv(cld,file="cld.csv",row.names=F)
159
write.csv(cldm,file="cldm.csv",row.names=F)
160
writeOGR(st,dsn=".",layer="stations",driver="ESRI Shapefile",overwrite_layer=T)
170
write.csv(cld,file="data/validation/cld.csv",row.names=F)
171
write.csv(cldm,file="data/validation/cldm.csv",row.names=F)
172
writeOGR(st,dsn="data/validation/",layer="stations",driver="ESRI Shapefile",overwrite_layer=T)
161 173
#########################################################################
162 174

  

Also available in: Unified diff