Revision c1e644f6
Added by Benoit Parmentier about 11 years ago
climate/research/oregon/interpolation/multi_timescale_paper_interpolation.R | ||
---|---|---|
5 | 5 |
#Figures, tables and data for the paper are also produced in the script. |
6 | 6 |
#AUTHOR: Benoit Parmentier |
7 | 7 |
#CREATED ON: 10/31/2013 |
8 |
#MODIFIED ON: 12/10/2013
|
|
8 |
#MODIFIED ON: 12/14/2013
|
|
9 | 9 |
#Version: 1 |
10 | 10 |
#PROJECT: Environmental Layers project |
11 | 11 |
################################################################################################# |
... | ... | |
39 | 39 |
#### FUNCTION USED IN SCRIPT |
40 | 40 |
|
41 | 41 |
function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_10222013.R" |
42 |
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_12102013.R"
|
|
42 |
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_12122013.R"
|
|
43 | 43 |
|
44 | 44 |
############################## |
45 | 45 |
#### Parameters and constants |
... | ... | |
146 | 146 |
names(list_raster_obj_files)<- c("gam_daily","kriging_daily","gwr_daily","gwr_daily", |
147 | 147 |
"gam_CAI","kriging_CAI","gwr_CAI", |
148 | 148 |
"gam_fss","kriging_fss","gwr_fss") |
149 |
|
|
149 | 150 |
summary_metrics_v_list<-lapply(list_raster_obj_files,FUN=function(x){x<-load_obj(x);x[["summary_metrics_v"]]$avg$rmse}) |
150 | 151 |
names(summary_metrics_v_list) |
151 | 152 |
|
... | ... | |
551 | 552 |
trans_data3 <-plot_transect_m2(list_transect3,rast_pred3,title_plot3,disp=FALSE,m_layers_sc) |
552 | 553 |
|
553 | 554 |
################################################ |
554 |
|
|
555 | 555 |
#Figure 8: Spatial pattern: Image differencing and land cover |
556 | 556 |
#Do for january and September...? |
557 | 557 |
|
558 |
#names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w", |
|
559 |
# "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST") |
|
560 |
|
|
561 |
methods_name <-c("gam_daily","gam_CAI","gam_fss") |
|
562 |
index<-244 #index corresponding to Sept 1 |
|
563 |
y_var_name <-"dailyTmax" |
|
564 |
ref_mod <- 3 #mod1 |
|
565 |
alt_mod <- 6 |
|
566 |
file_format <- ".rst" |
|
567 |
NA_flag_val <- -9999 |
|
568 |
|
|
569 |
list_param_diff <- list(index,list_raster_obj_files,methods_name,y_var_name,ref_mod,alt_mod,NA_flag_val,file_format,out_dir,out_prefix) |
|
570 |
names(list_param_diff) <- c("index","list_raster_obj_files","methods_name","y_var_name","ref_mod","alt_mod","NA_flag_val","file_format","out_dir","out_prefix") |
|
571 |
|
|
572 |
#diff_list <- mclapply(1:365, list_param=list_param_diff, FUN=diff_date_rast_pred_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement |
|
573 |
|
|
574 |
diff_pred_date1_list<- diff_date_rast_pred_fun(1,list_param_diff) |
|
575 |
diff_pred_date2_list<- diff_date_rast_pred_fun(244,list_param_diff) |
|
576 |
r_stack_diff <-stack(c(diff_pred_date1_list,diff_pred_date2_list)) |
|
577 |
names(r_stack_diff) <- c("Jan_Daily","Jan_CAI","Jan_FSS","Sept_Daily","Sept_CAI","Sept_FSS") |
|
578 |
temp.colors <- colorRampPalette(c('blue', 'white', 'red')) |
|
579 |
|
|
580 |
layout_m<-c(1,1) #one row two columns |
|
581 |
png(paste("Figure_9_difference_image_",out_prefix,".png", sep=""), |
|
582 |
height=480*layout_m[1],width=480*layout_m[2]) |
|
583 |
plot(r_stack_diff,col=temp.colors(25)) |
|
584 |
#levelplot(r_stack_diff) |
|
585 |
dev.off() |
|
586 |
### |
|
587 |
|
|
588 |
LC_subset <- c("LC1","LC5","LC6","LC7","LC9","LC11") |
|
589 |
LC_names <- c("LC1_forest", "LC5_shrub", "LC6_grass", "LC7_crop", "LC9_urban","LC11_barren") |
|
590 |
plot() |
|
591 |
avl<-c(0,10,1,10,20,2,20,30,3,30,40,4,40,50,5,50,60,6,60,70,7,70,80,8,80,90,9,90,100,10)#Note that category 1 does not include 0!! |
|
592 |
|
|
593 |
stat_list <- extract_diff_by_landcover(r_stack_diff,s_raster,LC_subset,LC_names,avl) |
|
558 | 594 |
|
595 |
#stat_list <- extract_diff_by_landcover(s_raster,LC_subset,LC_names,avl) |
|
596 |
|
|
597 |
#write_out_raster_fun(s_raster,out_suffix=out_prefix,out_dir=out_dir,NA_flag_val=-9999,file_format=".rst") |
|
598 |
|
|
599 |
#show correlation with LST by day over the year, ok writeout s_raster of coveriate?? |
|
600 |
|
|
601 |
title_plots_list <-c("Jan_Daily","Jan_CAI","Jan_FSS","Sept_Daily","Sept_CAI","Sept_FSS") |
|
602 |
|
|
603 |
## Now create plots |
|
604 |
layout_m<-c(2,3) #one row two columns |
|
605 |
#savePlot(paste("fig6_diff_prediction_tmax_difference_land cover",mf_selected,mc_selected,date_selected,out_prefix,".png", sep="_"), type="png") |
|
606 |
|
|
607 |
png(paste("Figure_9_diff_prediction_tmax_difference_land cover,ac_metric","_",out_prefix,".png", sep=""), |
|
608 |
height=480*layout_m[1],width=480*layout_m[2]) |
|
609 |
par(mfrow=layout_m) |
|
610 |
#funciton plot |
|
611 |
for (i in 1:length(stat_list$avg)){ |
|
612 |
#i=i+1 |
|
613 |
zones_stat <- as.data.frame(stat_list$avg[[i]]) |
|
614 |
zones_stat$zones <- 0:10 |
|
615 |
|
|
616 |
plot(zones_stat$zones,zones_stat[,1],type="b",ylim=c(-4.5,6), |
|
617 |
ylab="",xlab="",axes=FALSE) |
|
618 |
#mtext("difference between mod3 and mod6 (degree C)",line=3,side=2,cex=1.2,font=2) #Add ylab with distance 3 from box |
|
619 |
#mtext("land cover percent classes",side=1,cex=1.2,line=3,font=2) |
|
620 |
lines(zones_stat$zones,zones_stat[,2],col="red",lty="dashed",pch=2) #shrub |
|
621 |
points(zones_stat$zones,zones_stat[,2],col="red",lty="dashed",pch=2) #shrub |
|
622 |
lines(zones_stat$zones,zones_stat[,3],col="green",lty="dotted",pch=3) #grass |
|
623 |
points(zones_stat$zones,zones_stat[,3],col="green",lty="dotted",pch=3) #grass |
|
624 |
lines(zones_stat$zones,zones_stat[,4],col="blue",lty="dashed",pch=4) #crop |
|
625 |
points(zones_stat$zones,zones_stat[,4],col="blue",lty="dashed",pch=4) #crop |
|
626 |
lines(zones_stat$zones,zones_stat[,5],col="darkgreen",lty="dashed",pch=5) |
|
627 |
points(zones_stat$zones,zones_stat[,5],col="darkgreen",lty="dashed",pch=5) |
|
628 |
lines(zones_stat$zones,zones_stat[,6],col="purple",lty="dashed",pch=6) |
|
629 |
points(zones_stat$zones,zones_stat[,6],col="purple",lty="dashed",pch=6) |
|
630 |
|
|
631 |
breaks_lab<-zones_stat$zones |
|
632 |
tick_lab<-c("0","1-10","","20-30","","40-50","","60-70","","80-90","90-100") #Not enough space for |
|
633 |
#tick_lab<-c("0","10-20","30-40","60-70","80-90","90-100") |
|
634 |
axis(side=1,las=1,tick=TRUE, |
|
635 |
at=breaks_lab,labels=tick_lab, cex.axis=1.2,font=2) #reduce number of labels to Jan and June |
|
636 |
#text(tick_lab, par(\u201cusr\u201d)[3], labels = tick_lab, srt = 45, adj = c(1.1,1.1), xpd = TRUE, cex=.9) |
|
637 |
axis(2,cex.axis=1.2,font=2) |
|
638 |
box() |
|
639 |
legend("topleft",legend=names(zones_stat)[-7], |
|
640 |
cex=1, col=c("black","red","green","blue","darkgreen","purple"),bty="n", |
|
641 |
lty=1,pch=1:7) |
|
642 |
title(paste(title_plots_list[i],sep=""),cex=1.4, font=2) |
|
643 |
#title(paste("Prediction tmax difference (",mf_selected,"-",mc_selected,") and land cover ",sep=""),cex=1.4,font=2) |
|
644 |
} |
|
645 |
dev.off() |
|
646 |
|
|
647 |
#### Now elev? |
|
648 |
#LC1<-mask(LC1,mask_ELEV_SRTM) |
|
649 |
# cellStats(LC1,"countNA") #Check that NA have been assigned to water and areas below 0 m |
|
650 |
|
|
651 |
#LC1_50_m<- LC1>50 |
|
652 |
#LC1_100_m<- LC1>=100 |
|
653 |
#LC1_50_m[LC1_50_m==0]<-NA |
|
654 |
#LC1_100_m[LC1_100_m==0]<-NA |
|
655 |
#LC1_50<-LC1_50_m*LC1 |
|
656 |
#LC1_100<-LC1_100_m*LC1 |
|
657 |
#avl<-c(0,500,1,500,1000,2,1000,1500,3,1500,2000,4,2000,4000,5) |
|
658 |
#rclmat<-matrix(avl,ncol=3,byrow=TRUE) |
|
659 |
#elev_rec<-reclass(ELEV_SRTM,rclmat) #Loss of layer names when using reclass |
|
660 |
|
|
661 |
#elev_rec_forest<-elev_rec*LC1_100_m |
|
662 |
#avg_elev_rec<-zonal(rast_diff,zones=elev_rec,stat="mean",na.rm=TRUE) |
|
663 |
#std_elev_rec<-zonal(rast_diff,zones=elev_rec,stat="sd",na.rm=TRUE) |
|
664 |
#avg_elev_rec_forest<-zonal(rast_diff,zones=elev_rec_forest,stat="mean",na.rm=TRUE) |
|
665 |
#std_elev_rec_forest<-zonal(rast_diff,zones=elev_rec_forest,stat="sd",na.rm=TRUE) |
|
666 |
|
|
667 |
## CREATE plots |
|
668 |
#X11() |
|
669 |
#plot(avg_elev_rec[,1],avg_elev_rec[,2],type="b",ylim=c(-10,1), |
|
670 |
# ylab="",xlab="",axes=FALSE) |
|
671 |
#mtext("tmax difference between FSS and CAI (degree C)",side=2,cex=1.2,line=3,font=2) |
|
672 |
#mtext("elevation classes (m)",side=1,cex=1.2,line=3,font=2) |
|
673 |
#lines(avg_elev_rec_forest[,1],avg_elev_rec_forest[,2],col="green",type="b") #Elevation and 100% forest... |
|
674 |
#breaks_lab<-avg_elev_rec[,1] |
|
675 |
#elev_lab<-c("0-500","500-1000","1000-1500","1500-2000","2000-4000") |
|
676 |
#axis(side=1,las=1, |
|
677 |
# at=breaks_lab,labels=elev_lab, cex=1.5,font=2) #reduce number of labels to Jan and June |
|
678 |
#axis(2,cex.axis=1.2,font=2) |
|
679 |
#legend("bottomleft",legend=c("Elevation", "elev_forest"), |
|
680 |
# cex=1, lwd=1.3,col=c("black","green"),bty="n", |
|
681 |
# lty=1) |
|
682 |
#box() |
|
683 |
#title(paste("Prediction tmax difference (",mf_selected,"-",mc_selected,") and elevation ",sep=""),cex=1.4,font=2) |
|
684 |
#savePlot(paste("fig7_diff_prediction_tmax_difference_elevation",mf_selected,mc_selected,date_selected,out_prefix,".png", sep="_"), type="png") |
|
685 |
#dev.off() |
|
559 | 686 |
|
560 | 687 |
################################################ |
561 | 688 |
#Figure 9: Spatial lag profiles and stations data |
562 | 689 |
|
563 |
y_var_name <-"dailyTmax" |
|
564 | 690 |
index<-244 #index corresponding to Sept 1 #For now create Moran's I for only one date... |
565 | 691 |
|
566 | 692 |
lf_moran_list<-lapply(list_raster_obj_files[c("gam_daily","gam_CAI","gam_fss")], |
... | ... | |
577 | 703 |
|
578 | 704 |
names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w", |
579 | 705 |
"mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST") |
580 |
|
|
581 |
list_filters<-lapply(1:20,FUN=autocor_filter_fun,f_type="queen") #generate lag 10 filters
|
|
706 |
nb_lag <-10 |
|
707 |
list_filters<-lapply(1:nb_lag,FUN=autocor_filter_fun,f_type="queen") #generate lag 10 filters
|
|
582 | 708 |
#moran_list <- lapply(list_filters,FUN=Moran,x=r) |
583 | 709 |
list_moran_df <- vector("list",length=length(lf)) |
584 | 710 |
for (j in 1:length(lf)){ |
... | ... | |
637 | 763 |
|
638 | 764 |
print(p) |
639 | 765 |
|
640 |
|
|
641 | 766 |
dev.off() |
642 | 767 |
|
643 | 768 |
###################### END OF SCRIPT ####################### |
644 | 769 |
|
770 |
# #LAND COVER INFORMATION |
|
771 |
|
|
772 |
# LC1: Evergreen/deciduous needleleaf trees |
|
773 |
# LC2: Evergreen broadleaf trees |
|
774 |
# LC3: Deciduous broadleaf trees |
|
775 |
# LC4: Mixed/other trees |
|
776 |
# LC5: Shrubs |
|
777 |
# LC6: Herbaceous vegetation |
|
778 |
# LC7: Cultivated and managed vegetation |
|
779 |
# LC8: Regularly flooded shrub/herbaceous vegetation |
|
780 |
# LC9: Urban/built-up |
|
781 |
# LC10: Snow/ice |
|
782 |
# LC11: Barren lands/sparse vegetation |
|
783 |
# LC12: Open water |
|
784 |
#1,5,79,11 |
|
785 |
### |
|
786 |
|
|
645 | 787 |
|
Also available in: Unified diff
multi timescale paper, add comparison through differences and land cover effects