Project

General

Profile

« Previous | Next » 

Revision cd26aa7c

Added by Benoit Parmentier about 10 years ago

revisions RS contribution of covar, spatial correlogram and graphical abstract

View differences:

climate/research/oregon/interpolation/contribution_of_covariates_paper_interpolation.R
4 4
#different covariates using two baselines. Accuracy methods are added in the the function script to evaluate results.
5 5
#Figures, tables and data for the contribution of covariate paper are also produced in the script.
6 6
#AUTHOR: Benoit Parmentier                                                                      
7
#MODIFIED ON: 07/18/2014            
7
#MODIFIED ON: 08/08/2014            
8 8
#Version: 5
9 9
#PROJECT: Environmental Layers project                                     
10 10
#################################################################################################
......
257 257
#Figure 14: (a) Monthly MAE averages for the three interpolation methods: GAM, GWR and Kriging.(b) Monthly MAE boxplot for GAM.
258 258
#Figure 15: Correlation between LST-tmax, elevation-tmax in relation to LST significance and monthly model accuracy 
259 259

  
260
#Figure 0: Graphical abstract: Maps of predictions and spatial correlogram for lat*lon, lat*lon + elev, lat*lon + elev +  LST
261

  
260 262
### Figure 1: Oregon study area
261 263

  
262 264
ghcn_dat <- readOGR(dsn=dirname(met_stations_obj$monthly_covar_ghcn_data),
......
267 269
interp_area <- readOGR(dsn=dirname(infile_reg_outline),sub(".shp","",basename(infile_reg_outline)))
268 270
interp_area_WGS84 <-spTransform(interp_area,CRS_locs_WGS84)         # Project from WGS84 to new coord. system
269 271

  
270
usa_map <- getData('GADM', country='USA'), level=1) #Get US map
272
usa_map <- getData('GADM', country='USA', level=1) #Get US map
271 273
usa_map_2 <- usa_map[usa_map$NAME_1!="Alaska",] #remove Alaska
272 274
usa_map_2 <- usa_map_2[usa_map_2$NAME_1!="Hawaii",] #remove Hawai 
273 275
usa_map_OR <- usa_map_2[usa_map_2$NAME_1=="Oregon",] #get OR
......
1523 1525
                )
1524 1526
grid.arrange(p_bw1,p_bw2,p_bw3,ncol=3)
1525 1527
dev.off()
1526
                      
1528
          
1529
#############################################
1530
########### Figure 0: Graphical Abstract 
1531

  
1532
y_var_name <-"dailyTmax"
1533
index<-244 #index corresponding to Sept 1
1534

  
1535
## FIGURE COMPARISON OF  MODELS COVARIATES: Figure 7...
1536

  
1537
lf2 <- raster_prediction_obj_2$method_mod_obj[[index]][[y_var_name]]
1538
lf2 #contains the models for gam
1539
list_formulas <- raster_prediction_obj_2$method_mod_obj[[244]]$formulas
1540

  
1541
pred_temp_s2 <-stack(lf2[c(1,2,5)])
1542
date_selected <- "20109101"
1543
#names_layers <-c("mod1=s(lat,long)+s(elev)","mod4=s(lat,long)+s(LST)","diff=mod1-mod4")
1544
names_layers <- c("lat*long","lat*long+ elev","lat*long + LST")
1545

  
1546
#names_layers<-names(pred_temp_s)
1547
names(pred_temp_s2)<-names_layers
1548

  
1549
s.range <- c(min(minValue(pred_temp_s2)), max(maxValue(pred_temp_s2)))
1550
#s.range <- s.range+c(5,-5)
1551
col.breaks <- pretty(s.range, n=200)
1552
lab.breaks <- pretty(s.range, n=100)
1553
temp.colors <- colorRampPalette(c('blue', 'white', 'red'))
1554
#temp.colors <- colorRampPalette(c('blue', 'khaki', 'red'))
1555

  
1556
max_val<-s.range[2]
1557
min_val <-s.range[1]
1558
#max_val<- -10
1559
#min_val <- 0
1560
layout_m<-c(1,3) #one row, three columns
1561
res_pix <- 480
1562
png(paste("Figure_0a_graphic_abstact_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
1563
    height=res_pix*layout_m[1],width=res_pix*layout_m[2])
1564

  
1565
p<- levelplot(pred_temp_s2,main="Interpolated Surfaces using GAM on September 1, 2010", ylab=NULL,xlab=NULL,
1566
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m,
1567
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
1568
          names.attr=names_layers,col.regions=temp.colors,at=seq(max_val,min_val,by=0.01))
1569
#col.regions=temp.colors(25))
1570
print(p)
1571
dev.off()
1572

  
1573

  
1574

  
1575
#p<- levelplot(pred_temp_s2,,main="Interpolated Surfaces using GAM on September 1, 2010", ylab=NULL,xlab=NULL,
1576
#          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m,
1577
#                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
1578
#          names.attr=names_layers,col.regions=temp.colors,at=seq(max_val,min_val,by=0.01))
1579

  
1580

  
1581
########################################################
1582
#### Examining spatial correlograms for each model...use spedep but can be problematic when many datapoints
1583
#The follwing method using Moran's I raster command works for now but does not provide CI/std dev...
1584

  
1585
r_stack <-pred_temp_s2
1586

  
1587
#generate filters for 10 lags: quick solution
1588

  
1589
list_filters<-lapply(1:10,FUN=autocor_filter_fun,f_type="queen") #generate 10 filters
1590
#moran_list <- lapply(list_filters,FUN=Moran,x=r)
1591

  
1592
list_param_moran <- list(list_filters=list_filters,r_stack=r_stack)
1593
#moran_r <-moran_multiple_fun(1,list_param=list_param_moran)
1594
nlayers(r_stack) 
1595
moran_I_df <-mclapply(1:nlayers(r_stack), list_param=list_param_moran, FUN=moran_multiple_fun,mc.preschedule=FALSE,mc.cores = 10) #This is the end bracket from mclapply(...) statement
1596

  
1597
moran_df <- do.call(cbind,moran_I_df) #bind Moran's I value 10*nlayers data.frame
1598
moran_df$lag <-1:nrow(moran_df)
1599

  
1600
#prepare to automate the plotting of   all columns
1601
mydata<-moran_df
1602
dd <- do.call(make.groups, mydata[,-ncol(mydata)]) 
1603
dd$lag <- mydata$lag 
1604

  
1605
layout_m<-c(1,3) #one row three columns
1606
res_pix <-  480
1607
png(paste("Figure_0b_graphic_abstract_spatial_correlogram_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
1608
    height=res_pix*layout_m[1],width=res_pix*layout_m[2])
1609

  
1610
p<-xyplot(data ~ lag | which, dd,type="b",main="Spatial content in interpolated Surfaces using GAM on September 1, 2010",
1611
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m,
1612
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
1613
          strip=strip.custom(factor.levels=names_layers),
1614
          xlab=list(label="Spatial lag neighbor", cex=2,font=2),
1615
          ylab=list(label="Moran's I", cex=2, font=2))
1616
print(p)
1617

  
1618
dev.off()
1619

  
1620

  
1527 1621
###################### END OF SCRIPT #######################

Also available in: Unified diff