Revision 230a2c93
Added by Benoit Parmentier over 10 years ago
climate/research/oregon/interpolation/multi_timescale_paper_interpolation.R | ||
---|---|---|
7 | 7 |
#Analyses, figures, tables and data for the paper are also produced in the script. |
8 | 8 |
#AUTHOR: Benoit Parmentier |
9 | 9 |
#CREATED ON: 10/31/2013 |
10 |
#MODIFIED ON: 12/25/2013
|
|
10 |
#MODIFIED ON: 03/06/2014
|
|
11 | 11 |
#Version: 3 |
12 | 12 |
#PROJECT: Environmental Layers project |
13 | 13 |
################################################################################################# |
... | ... | |
110 | 110 |
"gam_fss","kriging_fss","gwr_fss") |
111 | 111 |
|
112 | 112 |
y_var_name <- "dailyTmax" |
113 |
out_prefix<-"analyses_12232013"
|
|
113 |
out_prefix<-"analyses_03062013"
|
|
114 | 114 |
out_dir<-"/home/parmentier/Data/IPLANT_project/paper_multitime_scale__analyses_tables" |
115 | 115 |
out_dir <-paste(out_dir,"_",out_prefix,sep="") |
116 | 116 |
|
... | ... | |
251 | 251 |
####################################################### |
252 | 252 |
####### PART 2: generate figures for paper ############# |
253 | 253 |
|
254 |
#Figure annex: LST climatology production: daily mean compared to monthly mean: moved to appendix |
|
255 |
|
|
254 | 256 |
#figure 1: Study area OR |
255 |
#Figure 2: LST climatology production: daily mean compared to monthly mean |
|
256 |
#figure 3: Prediction procedures: direct, CAI and FSS (figure created outside R) |
|
257 |
#Figure 4. Accuracy and monthly hold out for FSS and CAI procedures and GWR, Kriging and GAM methods. |
|
258 |
#Figure 5. Overtraining tendency, difference between training and testing |
|
259 |
#Figure 6: Spatial pattern of prediction for one day (3 maps) |
|
260 |
#Figure 7: Transect location (transect map) |
|
261 |
#Figure 8: Transect profiles for one day |
|
262 |
#Figure 9: Image differencing and land cover: spatial patterns |
|
263 |
#Figure 10: LST and Tmax at stations, elevation and land cover. |
|
264 |
#Figure 11: Spatial lag profiles for predicted surfaces |
|
265 |
#Figure 12: Daily deviation |
|
266 |
#Figure 13: Spatial correlogram at stations, LST and elevation every 5 lags |
|
257 |
#Figure 2. Accuracy and monthly hold out for FSS and CAI procedures and GWR, Kriging and GAM methods. |
|
258 |
#Figure 3. Overtraining tendency, difference between training and testing |
|
259 |
#Figure 4: Spatial pattern of prediction for one day (3 maps) |
|
260 |
#Figure 5: Transect location (transect map) |
|
261 |
#Figure 6: Transect profiles for one day |
|
262 |
#Figure 7: Image differencing and land cover: spatial patterns |
|
263 |
#Figure 8: LST and Tmax at stations, elevation and land cover. |
|
264 |
#Figure 9: Spatial lag profiles for predicted surfaces |
|
265 |
#Figure 10: Daily deviation |
|
266 |
#Figure 11: Spatial correlogram at stations, LST and elevation every 5 lags |
|
267 | 267 |
|
268 | 268 |
################################################ |
269 | 269 |
######### Figure 1: Oregon study area, add labeling names to Willamette Valley an Mountain Ranges? |
... | ... | |
317 | 317 |
dev.off() |
318 | 318 |
|
319 | 319 |
################################################ |
320 |
######### Figure 2: LST averaging: daily mean compared to monthly mean |
|
320 |
######### Figure Annex: LST averaging: daily mean compared to monthly mean |
|
321 |
|
|
322 |
#This is now moved in Annex |
|
321 | 323 |
|
322 | 324 |
lst_md <- raster(ref_rast_name) |
323 | 325 |
projection(lst_md)<-projection(s_raster) |
... | ... | |
327 | 329 |
lst_md<- lst_md - 273.16 |
328 | 330 |
lst_mm_01<-subset(s_raster,"mm_01") |
329 | 331 |
|
330 |
png(filename=paste("Figure2_paper_Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=960,height=480)
|
|
332 |
png(filename=paste("Figure_annex1_paper_Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=960,height=480)
|
|
331 | 333 |
par(mfrow=c(1,2)) |
332 | 334 |
plot(lst_md) |
333 | 335 |
plot(interp_area,add=TRUE) |
... | ... | |
338 | 340 |
dev.off() |
339 | 341 |
|
340 | 342 |
################################################ |
341 |
######### Figure 3: Prediction procedures: direct, CAI and FSS |
|
342 |
|
|
343 |
|
|
344 |
#(figure created outside R) |
|
345 |
|
|
346 |
|
|
347 |
################################################ |
|
348 |
######### Figure 4. RMSE multi-timescale mulitple hold out for FSS and CAI |
|
343 |
######### Figure 3. RMSE multi-timescale mulitple hold out for FSS and CAI |
|
349 | 344 |
|
350 | 345 |
raster_prediction_obj_9 <-load_obj(file.path(in_dir9,raster_obj_file_9)) #comb5 gwr_fss |
351 | 346 |
|
... | ... | |
378 | 373 |
plot_names <- names(list_tb) #this is the default names for the plots |
379 | 374 |
#now replace names for relevant figure used later on. |
380 | 375 |
plot_names[7:12] <- c("RMSE for gam_FSS","RMSE for kriging_FSS","RMSE for gwr_FSS", |
381 |
"RMSE for gam_CAI","RMSE for kriging_CAI","RMSE for gwr_CAI") |
|
376 |
o "RMSE for gam_CAI","RMSE for kriging_CAI","RMSE for gwr_CAI")
|
|
382 | 377 |
#Quick function to explore accuracy make this a function to create solo figure...and run only a subset... |
383 | 378 |
|
384 |
list_plots <- plot_accuracy_by_holdout_fun(list_tb,ac_metric,plot_names,names_mod) |
|
379 |
#list_plots <- plot_accuracy_by_holdout_fun(list_tb,ac_metric,plot_names,names_mod) |
|
380 |
tb_obj <- plot_accuracy_by_holdout_fun(list_tb,ac_metric,plot_names,names_mod) |
|
385 | 381 |
|
386 |
##For paper...combine figures... tb_v for GWR, Kriging and GAM for both FSS and CAI |
|
382 |
selected_df <- 7:12 |
|
383 |
names(tb_obj$list_avg_tb[selected_df]) #names of method and validation set selected |
|
384 |
avg_tb_ac <- do.call(rbind.fill,tb_obj$list_avg_tb[selected_df]) |
|
387 | 385 |
|
388 |
layout_m<-c(2,3) #one row two columns |
|
389 |
#par(mfrow=layout_m) |
|
390 |
|
|
391 |
##add option for plot title? |
|
392 |
png(paste("Figure4_paper_accuracy_",ac_metric,"_prop_month","_",out_prefix,".png", sep=""), |
|
386 |
layout_m<-c(1,1.5) #one row two columns |
|
387 |
|
|
388 |
png(paste("Figure2_paper_accuracy_",ac_metric,"_prop_month","_",out_prefix,".png", sep=""), |
|
393 | 389 |
height=480*layout_m[1],width=480*layout_m[2]) |
394 |
p1<-list_plots[[7]] |
|
395 |
p2<-list_plots[[8]] |
|
396 |
p3<-list_plots[[9]] |
|
397 |
p4<-list_plots[[10]] |
|
398 |
p5<-list_plots[[11]] |
|
399 |
p6<-list_plots[[12]] |
|
400 |
|
|
401 |
grid.arrange(p1,p2,p3,p4,p5,p6,ncol=3) |
|
390 |
|
|
391 |
p <- xyplot(rmse~prop_month|method_interp, # |set up pannels using method_interp |
|
392 |
group=pred_mod,data=avg_tb_ac, #group by model (covariates) |
|
393 |
main="RME by monthly hold-out proportions and interpolation methods", |
|
394 |
type="b",as.table=TRUE, |
|
395 |
index.cond=list(c(1,5,3,2,6,4)), #this provides the order of the panels) |
|
396 |
pch=1:length(avg_tb$pred_mod), |
|
397 |
par.settings=list(superpose.symbol = list( |
|
398 |
pch=1:length(avg_tb$pred_mod))), |
|
399 |
auto.key=list(columns=1,space="right",title="Model",cex=1), |
|
400 |
#auto.key=list(columns=5), |
|
401 |
xlab="Monthly Hold out proportion", |
|
402 |
ylab="RMSE (°C)") |
|
403 |
print(p) |
|
402 | 404 |
dev.off() |
403 | 405 |
|
404 | 406 |
################################################ |
405 |
######### Figure 5. RMSE multi-timescale mulitple hold out Overtraining tendency
|
|
407 |
######### Figure 3. RMSE multi-timescale mulitple hold out Overtraining tendency
|
|
406 | 408 |
|
407 | 409 |
#x<-tb_ms_list[[1]] |
408 | 410 |
tb_ms_list_diff <- lapply(tb_ms_list,FUN=function(x){x[x$prop!=0,]}) |
... | ... | |
439 | 441 |
## Now create boxplots... |
440 | 442 |
layout_m<-c(2,2) #one row two columns |
441 | 443 |
|
442 |
png(paste("Figure5_paper_boxplot_overtraining_",out_prefix,".png", sep=""),
|
|
444 |
png(paste("Figure3_paper_boxplot_overtraining_",out_prefix,".png", sep=""),
|
|
443 | 445 |
height=480*layout_m[1],width=480*layout_m[2]) |
444 | 446 |
#boxplot(diff_kriging_CAI$rmse,diff_gam_CAI$rmse,diff_gwr_CAI$rmse,names=c("kriging_CAI","gam_CAI","gwr_CAI"), |
445 | 447 |
# main="Difference between training and testing daily rmse") |
... | ... | |
447 | 449 |
|
448 | 450 |
#monthly CAI |
449 | 451 |
boxplot(list_m_diff$kriging_CAI$rmse,list_m_diff$gam_CAI$rmse,list_m_diff$gwr_CAI$rmse, |
452 |
ylim=c(-9,1), outline=TRUE, |
|
450 | 453 |
names=c("kriging_CAI","gam_CAI","gwr_CAI"),ylab="RMSE (°C)",xlab="Interpolation Method", |
451 | 454 |
main="Difference between training and testing for monhtly rmse") |
452 | 455 |
legend("topleft",legend=c("a"),bty="n") #bty="n", don't put box around legend |
453 | 456 |
|
457 |
#monthly fss |
|
458 |
boxplot(list_m_diff$kriging_fss$rmse,list_m_diff$gam_fss$rmse,list_diff$gwr_fss$rmse, |
|
459 |
ylim=c(-9,1),outline=TRUE, |
|
460 |
names=c("kriging_FSS","gam_FSS","gwr_FSS"),ylab="RMSE (°C)",xlab="Interpolation Method", |
|
461 |
main="Difference between training and testing for monhtly rmse") |
|
462 |
legend("topleft",legend=c("c"),bty="n") |
|
463 |
|
|
454 | 464 |
#daily CAI |
455 | 465 |
boxplot(list_diff$kriging_CAI$rmse,list_diff$gam_CAI$rmse,list_diff$gwr_CAI$rmse, |
466 |
ylim=c(-12,1.5),outline=TRUE, |
|
456 | 467 |
names=c("kriging_CAI","gam_CAI","gwr_CAI"),ylab="RMSE (°C)",xlab="Interpolation Method", |
457 | 468 |
main="Difference between training and testing daily rmse") |
458 | 469 |
legend("topleft",legend=c("b"),bty="n") |
459 | 470 |
|
460 |
#monthly fss |
|
461 |
boxplot(list_m_diff$kriging_fss$rmse,list_m_diff$gam_fss$rmse,list_diff$gwr_fss$rmse, |
|
462 |
names=c("kriging_FSS","gam_FSS","gwr_FSS"),ylab="RMSE (°C)",xlab="Interpolation Method", |
|
463 |
main="Difference between training and testing for monhtly rmse") |
|
464 |
legend("topleft",legend=c("c"),bty="n") |
|
465 | 471 |
|
466 | 472 |
#daily fss |
467 | 473 |
boxplot(list_diff$kriging_fss$rmse,list_diff$gam_fss$rmse,list_diff$gwr_fss$rmse, |
474 |
ylim=c(-12,1.5),outline=TRUE, |
|
468 | 475 |
names=c("kriging_FSS","gam_FSS","gwr_FSS"),ylab="RMSE (°C)",xlab="Interpolation Method", |
469 | 476 |
main="Difference between training and testing daily rmse") |
470 | 477 |
legend("topleft",legend=c("d"),bty="n") |
... | ... | |
473 | 480 |
|
474 | 481 |
|
475 | 482 |
################################################ |
476 |
######### Figure 6: Spatial pattern of prediction for one day (maps)
|
|
483 |
######### Figure 4: Spatial pattern of prediction for one day (maps)
|
|
477 | 484 |
|
478 | 485 |
y_var_name <-"dailyTmax" |
479 | 486 |
index<-244 #index corresponding to Sept 1 |
... | ... | |
491 | 498 |
|
492 | 499 |
names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w", |
493 | 500 |
"mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST") |
494 |
nb_fig<- c("6a","6b","6c")
|
|
501 |
nb_fig<- c("4a","4b","4c")
|
|
495 | 502 |
list_plots_spt <- vector("list",length=length(lf)) |
496 | 503 |
for (i in 1:length(lf)){ |
497 | 504 |
pred_temp_s <-stack(lf[[i]]) |
... | ... | |
509 | 516 |
max_val <- 40 |
510 | 517 |
min_val <- -10 |
511 | 518 |
layout_m<-c(2,4) #one row two columns |
512 |
|
|
519 |
no_brks <- length(seq(min_val,max_val,by=0.1))-1 |
|
513 | 520 |
png(paste("Figure_",nb_fig[i],"_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""), |
514 | 521 |
height=480*layout_m[1],width=480*layout_m[2]) |
515 | 522 |
|
516 | 523 |
p <- levelplot(pred_temp_s,main=methods_names[i], ylab=NULL,xlab=NULL, |
517 | 524 |
par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m, |
518 | 525 |
par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5), |
519 |
names.attr=names_layers,col.regions=temp.colors,at=seq(min_val,max_val,by=0.25))
|
|
526 |
names.attr=names_layers,col.regions=temp.colors(no_brks),at=seq(min_val,max_val,by=0.1))
|
|
520 | 527 |
#col.regions=temp.colors(25)) |
521 | 528 |
print(p) |
522 | 529 |
dev.off() |
... | ... | |
526 | 533 |
layout_m<-c(2,4) # works if set to this?? ok set the resolution... |
527 | 534 |
#layout_m<-c(2*3,4) # works if set to this?? ok set the resolution... |
528 | 535 |
|
529 |
png(paste("Figure6_paper_","_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
|
|
536 |
png(paste("Figure4_paper_","_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
|
|
530 | 537 |
height=960*layout_m[1],width=960*layout_m[2]) |
531 | 538 |
#height=480*6,width=480*4) |
532 | 539 |
|
... | ... | |
538 | 545 |
dev.off() |
539 | 546 |
|
540 | 547 |
################################################ |
541 |
#Figure 7: Spatial transects for one day (maps)
|
|
548 |
#Figure 5 and Figure 6: Spatial transects for one day (maps)
|
|
542 | 549 |
|
543 |
#######Figure 7a: Map of transects
|
|
550 |
#######Figure 5: Map of transects
|
|
544 | 551 |
|
545 | 552 |
## Transects image location in OR |
546 | 553 |
layout_m<-c(1,1) |
547 |
png(paste("Figure7_paper_elevation_transect_paths_",out_prefix,".png", sep=""),
|
|
554 |
png(paste("Figure5_paper_elevation_transect_paths_",out_prefix,".png", sep=""),
|
|
548 | 555 |
height=480*layout_m[1],width=480*layout_m[2]) |
549 | 556 |
vx_text <- c(395770.1,395770.1,395770.1) #location of labels |
550 | 557 |
vy_text <-c(473000,297045.9,112611.5) |
... | ... | |
562 | 569 |
title("Transect Oregon") |
563 | 570 |
dev.off() |
564 | 571 |
|
565 |
#### TRANSECT PROFILES |
|
572 |
######Figure 6: TRANSECT PROFILES
|
|
566 | 573 |
nb_transect <- 3 |
567 | 574 |
list_transect2<-vector("list",nb_transect) |
568 | 575 |
list_transect3<-vector("list",nb_transect) |
... | ... | |
583 | 590 |
layers_names3 <- names(rast_pred3)<-c("mod1","mod3","mod6","elev") |
584 | 591 |
#pos<-c(1,2) # postions in the layer prection |
585 | 592 |
#transect_list |
586 |
list_transect2[[1]]<-c(transect_list[1],paste("Figure8a_paper_tmax_elevation_transect1_OR_",date_selected,
|
|
593 |
list_transect2[[1]]<-c(transect_list[1],paste("Figure6a_paper_tmax_elevation_transect1_OR_",date_selected,
|
|
587 | 594 |
paste("mod1_2_6",collapse="_"),out_prefix,sep="_")) |
588 |
list_transect2[[2]]<-c(transect_list[2],paste("Figure8b_tmax_elevation_transect2_OR_",date_selected,
|
|
595 |
list_transect2[[2]]<-c(transect_list[2],paste("Figure6b_tmax_elevation_transect2_OR_",date_selected,
|
|
589 | 596 |
paste("mod1_2_6",collapse="_"),out_prefix,sep="_")) |
590 |
list_transect2[[3]]<-c(transect_list[3],paste("Figure8c_paper_tmax_elevation_transect3_OR_",date_selected,
|
|
597 |
list_transect2[[3]]<-c(transect_list[3],paste("Figure6c_paper_tmax_elevation_transect3_OR_",date_selected,
|
|
591 | 598 |
paste("mod1_2_6",collapse="_"),out_prefix,sep="_")) |
592 | 599 |
|
593 |
list_transect3[[1]]<-c(transect_list[1],paste("Figure8a_tmax_elevation_transect1_OR_",date_selected,
|
|
600 |
list_transect3[[1]]<-c(transect_list[1],paste("Figure6a_tmax_elevation_transect1_OR_",date_selected,
|
|
594 | 601 |
paste("mod1_3_6",collapse="_"),out_prefix,sep="_")) |
595 |
list_transect3[[2]]<-c(transect_list[2],paste("Figure8b_tmax_elevation_transect2_OR_",date_selected,
|
|
602 |
list_transect3[[2]]<-c(transect_list[2],paste("Figure6b_tmax_elevation_transect2_OR_",date_selected,
|
|
596 | 603 |
paste("mod1_3_6",collapse="_"),out_prefix,sep="_")) |
597 |
list_transect3[[3]]<-c(transect_list[3],paste("Figure8c_tmax_elevation_transect3_OR_",date_selected,
|
|
604 |
list_transect3[[3]]<-c(transect_list[3],paste("Figure6c_tmax_elevation_transect3_OR_",date_selected,
|
|
598 | 605 |
paste("mod1_3_6",collapse="_"),out_prefix,sep="_")) |
599 | 606 |
|
600 | 607 |
names(list_transect2)<-c("Oregon Transect 1","Oregon Transect 2","Oregon Transect 3") |
... | ... | |
617 | 624 |
#title_plot2 |
618 | 625 |
#rast_pred2 |
619 | 626 |
#debug(plot_transect_m2) |
620 |
trans_data2 <-plot_transect_m2(list_transect2,rast_pred2,title_plot2,disp=FALSE,m_layers_sc) |
|
621 |
trans_data3 <-plot_transect_m2(list_transect3,rast_pred3,title_plot2,disp=FALSE,m_layers_sc) |
|
627 |
trans_data2 <- plot_transect_m2(list_transect2,rast_pred2,title_plot2,disp=FALSE,m_layers_sc)
|
|
628 |
trans_data3 <- plot_transect_m2(list_transect3,rast_pred3,title_plot2,disp=FALSE,m_layers_sc)
|
|
622 | 629 |
|
623 | 630 |
################################################ |
624 |
#Figure 9: Spatial pattern: Image differencing
|
|
631 |
#Figure7: Spatial pattern: Image differencing
|
|
625 | 632 |
#Do for january and September...? |
626 | 633 |
|
627 | 634 |
#names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w", |
... | ... | |
645 | 652 |
r_stack_diff <-stack(c(diff_pred_date1_list,diff_pred_date2_list)) |
646 | 653 |
names(r_stack_diff) <- c("Jan_Daily","Jan_CAI","Jan_FSS","Sept_Daily","Sept_CAI","Sept_FSS") |
647 | 654 |
temp.colors <- colorRampPalette(c('blue', 'white', 'red')) |
648 |
|
|
649 |
layout_m<-c(1,1) #one row two columns
|
|
650 |
png(paste("Figure9_paper_difference_image_",out_prefix,".png", sep=""),
|
|
655 |
#temp.colors <- colorRampPalette(c('blue', 'white', 'red')) |
|
656 |
layout_m<-c(2,3) #one row two columns
|
|
657 |
png(paste("Figure7_paper_difference_image_",out_prefix,".png", sep=""),
|
|
651 | 658 |
height=480*layout_m[1],width=480*layout_m[2]) |
652 |
plot(r_stack_diff,col=temp.colors(25)) |
|
653 |
#levelplot(r_stack_diff) |
|
659 |
#plot(r_stack_diff,col=temp.colors(25)) |
|
660 |
#r_diff1<-subset(r_stack_diff,1:3) |
|
661 |
#r_diff2<-subset(r_stack_diff,4:6) |
|
662 |
#p1<-levelplot(r_diff1, col.regions=matlab.like(100)) #January |
|
663 |
#p2<-levelplot(r_diff2,col.regions=matlab.like(100)) #January |
|
664 |
|
|
665 |
#p1<-levelplot(r_stack_diff,layers=1:3, col.regions=matlab.like(100)) #January |
|
666 |
#p2<-levelplot(r_stack_diff,layers=4:6, col.regions=matlab.like(100)) #January |
|
667 |
#grid.arrange(p1,p2,ncol=1) |
|
668 |
levelplot(r_stack_diff,col.regions=matlab.like(100), |
|
669 |
ylab=NULL,xlab=NULL, |
|
670 |
par.settings = list(axis.text = list(font = 2, cex = 2),layout=layout_m, |
|
671 |
par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5), |
|
672 |
) #January |
|
654 | 673 |
dev.off() |
655 | 674 |
### |
656 | 675 |
|
676 |
#scales=list(log="e",x=list(cex=.3),y=list(cex=.3)) #change font size |
|
657 | 677 |
|
658 | 678 |
#################################################################### |
659 | 679 |
#Figure 10: LST and Tmax at stations, elevation and land cover. |
Also available in: Unified diff
multitime scale paper, draft 2 revisions