Project

General

Profile

« Previous | Next » 

Revision 61fa1397

Added by Benoit Parmentier almost 11 years ago

modifications of code for the productions of figures for manuscript draft 12/30

View differences:

climate/research/oregon/interpolation/multi_timescale_paper_interpolation.R
1 1
####################################  INTERPOLATION OF TEMPERATURES  #######################################
2
############################  Script for manuscript analyses,tables and figures: MULTITIME SCALE  ##############################
3
#This script uses the worklfow code applied to the Oregon case study. Multitime scale methods (GAM,GWR, Kriging) are tested with
4
#different covariates using FUSION and CAI. Accuracy methods are added in the the function script to evaluate results.
5
#Figures, tables and data for the  paper are also produced in the script.
2
############################  Script for manuscript analyses,tables and figures: MULTI TIME SCALE  ##############################
3
#This script uses the worklfow code applied to the Oregon case study. Single and Multi timescale procedures are compared.
4
#Single and Multitime scale (CAI and FSS)procedures are tested with different covariate combinations
5
#using GAM,GWR, Kriging. Results conurrently reside on NCEAS ATLAS server.
6
#Accuracy methods are added in the the function scripts to evaluate results.
7
#Analyses, figures, tables and data for the  paper are also produced in the script.
6 8
#AUTHOR: Benoit Parmentier 
7 9
#CREATED ON: 10/31/2013  
8
#MODIFIED ON: 12/23/2013            
9
#Version: 2
10
#MODIFIED ON: 12/25/2013            
11
#Version: 3
10 12
#PROJECT: Environmental Layers project                                     
11 13
#################################################################################################
12 14

  
......
38 40

  
39 41
#### FUNCTION USED IN SCRIPT
40 42

  
41
function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_10222013.R"
42
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_12232013.R"
43
function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_10222013.R" #first interp paper
44
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_12252013.R"
43 45

  
44 46
##############################
45 47
#### Parameters and constants  
46 48

  
47 49
script_path<-"/home/parmentier/Data/IPLANT_project/env_layers_scripts/" #path to script
48
source(file.path(script_path,function_analyses_paper1)) #source all functions used in this script.
49
source(file.path(script_path,function_analyses_paper2)) #source all functions used in this script.
50
source(file.path(script_path,function_analyses_paper1)) #source all functions used in this script 1.
51
source(file.path(script_path,function_analyses_paper2)) #source all functions used in this script 2.
50 52

  
51
#direct methods: gam, kriging, gwr
53
#Singlte time scale -direct methods: gam, kriging, gwr (no monthly holdout but 30%daily hold out)
52 54
in_dir1 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gam_daily_lst_comb5_11012013"
53 55
in_dir2 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_kriging_daily_lst_comb5_11022013"
54 56
in_dir3a <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gwr_daily_lst_comb5p1_3_11062013"
55 57
in_dir3b <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gwr_daily_lst_comb5p4_7_11292013"
56 58

  
57
#CAI: gam, kriging, gwr
59
#Multi time scale - CAI: gam, kriging, gwr
58 60
in_dir4 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gam_cai_lst_comb5_11032013"
59 61
in_dir5 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_kriging_cai_lst_comb5_11032013"
60 62
in_dir6 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gwr_cai_lst_comb5_11042013"
61
#FSS: gam, kriging, gwr
63
#Multi time scale - FSS: gam, kriging, gwr
62 64
in_dir7 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gam_fss_lst_comb5_11062013"
63 65
in_dir8 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_kriging_fss_lst_comb5_11052013"
64 66
in_dir9 <- "/data/project/layers/commons/Oregon_interpolation/output_data_365d_gwr_fss_lst_comb5_11052013"
65 67
###
66 68

  
67
### hold out 0-70
68

  
69
### Multi time scale: Results from monthly hold out 0-70%
69 70
in_dir10 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gam_fss_lst_mults_0_70_comb5_11082013"
70 71
in_dir11 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_kriging_fss_lst_mults_0_70_comb5_11132013"
71 72
in_dir12 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gwr_fss_lst_mults_0_70_comb5_11162013"
......
149 150
###################################################################
150 151
############### BEGIN SCRIPT ##################################
151 152

  
152
#############################PART I: Generate tables for paper ##########
153
###################### PART I: Generate tables for paper ##########
153 154
#Table 1: Covariates used (not produced in R)
154 155
#Table 2: Covariates models and functional form (not produced in R)
155 156
#Table 3: Combinations of models tested (not produced in R)
......
192 193
table4_paper$Formulas<-rep(list_formulas,3)                             
193 194
table4_paper<-table4_paper[(c(5,4,1,2,3))]  #reordering columns                           
194 195

  
195
#Testing siginificance between models
196
                             
196
#Testing siginificance between models                    
197 197
#mod_compk1 <-kruskal.test(tb1$rmse ~ as.factor(tb1$pred_mod)) #Kruskal Wallis test
198 198
#mod_compk2 <-kruskal.test(tb2$rmse ~ as.factor(tb2$pred_mod))
199 199
#print(mod_compk1) #not significant
......
339 339

  
340 340
################################################
341 341
######### Figure 3: Prediction procedures: direct, CAI and FSS 
342

  
343

  
342 344
#(figure created outside R)
343 345

  
344 346

  
......
540 542

  
541 543
#######Figure 7a: Map of transects
542 544

  
543
## Transects image location in OR             
544
png(paste("Figrue7_paper_elevation_transect_paths_",date_selected,out_prefix,".png", sep=""),
545
## Transects image location in OR  
546
layout_m<-c(1,1)
547
png(paste("Figure7_paper_elevation_transect_paths_",out_prefix,".png", sep=""),
545 548
    height=480*layout_m[1],width=480*layout_m[2])
549
vx_text <- c(395770.1,395770.1,395770.1) #location of labels
550
vy_text  <-c(473000,297045.9,112611.5)
546 551

  
547 552
plot(elev)
548 553
for(i in 1:length(transect_list)){
549 554
  filename<-sub(".shp","",transect_list[i])             #Removing the extension from file.
550 555
  transect<-readOGR(dirname(filename), basename(filename))                 #reading shapefile 
556
  #transect2 <- elide(transect, shift=c(0, -24000))
557
  #plot(transect2,add=TRUE)
558
  #writeOGR(transect2,dsn=".",layer="transect_OR_1_12282013",driver="ESRI Shapefile")
551 559
  plot(transect,add=TRUE)
552 560
}
561
text(x=vx_text,y=vy_text,labels=c("Transect 1","Transect 2","Transect 3"))
553 562
title("Transect Oregon")
554 563
dev.off()
555 564

  
......
667 676
#show correlation with LST by day over the year, ok writeout s_raster of coveriate??
668 677

  
669 678
title_plots_list <-c("Jan_Daily","Jan_CAI","Jan_FSS","Sept_Daily","Sept_CAI","Sept_FSS")
679
#reorder the list
680
order_list<- c(1,4,2,5,3,6)
670 681

  
671 682
## Now create plots
672
layout_m<-c(2,3) #one row two columns
683
layout_m<-c(3,2) #one row two columns
673 684
#savePlot(paste("fig6_diff_prediction_tmax_difference_land cover",mf_selected,mc_selected,date_selected,out_prefix,".png", sep="_"), type="png")
674 685

  
675 686
png(paste("Figure10_paper_diff_prediction_tmax_difference_land cover,ac_metric","_",out_prefix,".png", sep=""),
......
678 689
#funciton plot
679 690
for (i in 1:length(stat_list$avg)){
680 691
  #i=i+1
681
  zones_stat <- as.data.frame(stat_list$avg[[i]])
692
  index <- order_list[i]
693
  zones_stat <- as.data.frame(stat_list$avg[[index]])
682 694
  zones_stat$zones <- 0:10
683 695

  
684 696
  plot(zones_stat$zones,zones_stat[,1],type="b",ylim=c(-4.5,6),
......
708 720
  legend("topleft",legend=names(zones_stat)[-7], 
709 721
        cex=1.4, col=c("black","red","green","blue","darkgreen","purple"),bty="n",
710 722
        lty=1,pch=1:7)
711
  title(paste(title_plots_list[i],sep=""),cex=1.6, font=2)
723
  title(paste(title_plots_list[index],sep=""),cex=1.6, font=2)
712 724
  #title(paste("Prediction tmax difference (",mf_selected,"-",mc_selected,") and land cover ",sep=""),cex=1.4,font=2) 
713 725
}
714 726
dev.off()
......
759 771
list_title_plot<- list(c("Spatial lag profile on January 1, 2010"),
760 772
                  c("Spatial lag profile on September 1, 2010"))
761 773
#name used in the panel!!!
762
names_panel_plot <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w",
774
names_panel_plot <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + elev + N_w*E_w",
763 775
                 "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST")
764 776
layout_m<-c(2,4) # works if set to this?? ok set the resolution...
765 777
list_moran_df <- list(list_moran_df1,list_moran_df2)
......
794 806
################################################
795 807
#Figure 12: Monthly climatology, Daily deviation and bias
796 808

  
809
#The list of files for 365 days in 2010...
797 810
lf_delta_gam_fss <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_fss"]])$method_mod_obj,"delta") #getting objet
811
lf_daily_gam_fss <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_fss"]])$method_mod_obj,"daily") #getting objet
812
lf_clim_gam_fss <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_fss"]])$method_mod_obj,"clim") #getting objet
798 813

  
799
test01 <-stack(lf_delta_gam_fss[[287]]) #Ot.14
814
#The list of files for 365 days in 2010...
815
#y_var_name <- dailyTmax
816
lf_delta_gam_CAI <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_CAI"]])$method_mod_obj,"delta") #getting objet
817
lf_daily_gam_CAI <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_CAI"]])$method_mod_obj,y_var_name) #getting objet
818
lf_clim_gam_CAI <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_CAI"]])$method_mod_obj,"clim") #getting objet
819

  
820
index <- 289
821
temp_day_s <- stack(lf_clim_gam_CAI[[index]]$mod7,lf_delta_gam_CAI[[index]]$mod7,lf_daily_gam_CAI[[index]]$mod7)
822
names(temp_day_s) <- c("Monhtly Climatology","Daily Devation","Daily Prediction")
823

  
824
layout_m <- c(1,3)
825
png(paste("Figure12_paper_climatology_daily_deviation_daily_prediction_model7_levelplot_",out_prefix,".png", sep=""),
826
    height=480*layout_m[1],width=480*layout_m[2])
827
    #height=3*480*layout_m[1],width=2*480*layout_m[2])
828
    #height=480*6,width=480*4)
829
#par(mfrow=layout_m)    
800 830

  
801
test0 <-stack(lf_delta_gam_fss[[288]]) #Ot.15
802
test1 <-stack(lf_delta_gam_fss[[289]]) #Ot.16
803
test2<-stack(lf_delta_gam_fss[[290]]) #Ot.17
831
#plot(temp_day_s,col=  temp.colors(25),nr=layout_m,nc=layout_m,
832
#     cex=1.5) #use nr to choose number of columns in layout!!
804 833

  
805
plot(test01)
834
p1 <- levelplot(temp_day_s,col.region=temp.colors(25),layer=1)
835
p2 <- levelplot(temp_day_s,col.region=temp.colors(25),layer=2)
836
p3 <- levelplot(temp_day_s,col.region=temp.colors(25),layer=3)
837
grid.arrange(p1,p2,p3,ncol=3)
838
dev.off()
806 839

  
807
plot(test0)
808
plot(test1)
809
plot(test2)
810 840

  
841
##################################################
842
####### Figure 13 : Disussion section
811 843

  
812
################################################
813
#Figure 13: Tmax and LST averagees
844
############################
845
#Get Tmax and LST averages
814 846

  
815 847
names_tmp<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12")
816 848
LST_s<-subset(s_raster,names_tmp)
......
826 858
#It works for any variable with stack of monthly values...!!
827 859
LST_stat <- plot_mean_nobs_r_stack_by_month(var_s=LST_s,var_nobs=LST_nobs,y_range_nobs,y_range_avg,var_name,out_prefix)
828 860

  
829
##################################################
830
####### Figure 13 : disussion  
861

  
862
## open device for plottging
863
layout_m<-c(2,2) # works if set to this?? ok set the resolution...
864

  
865
png(paste("Figure13_paper_TMax_and_LST_relationship_",out_prefix,".png", sep=""),
866
    height=480*layout_m[1],width=480*layout_m[2])
867
par(mfrow=layout_m)    
831 868

  
832 869
##################################################
833 870
####### Figure 13a: spatial variation -MoranI and  std  
......
843 880
data_month_all <-convert_spdf_to_df_from_list(list_data_month_s) #long rownames
844 881
#LSTD_bias_avgm<-aggregate(LSTD_bias~month,data=data_month_all,mean)
845 882
#LSTD_bias_sdm<-aggregate(LSTD_bias~month,data=data_month_all,sd)
846
LST_avgm<-aggregate(LST~month,data=data_month_all,mean)
847
TMax_avgm<-aggregate(TMax~month,data=data_month_all,mean)
883
LST_avgm <- aggregate(LST~month,data=data_month_all,mean)
884
LST_avgm_min <- aggregate(LST~month,data=data_month_all,min)
885
LST_avgm_max <- aggregate(LST~month,data=data_month_all,max)
886
TMax_avgm <- aggregate(TMax~month,data=data_month_all,mean)
848 887

  
849 888
#plot(LST_avgm,type="b")
850 889
#lines(TMax_avgm,col="blue",add=T)
851
plot(data_month_all$month,data_month_all$LST, xlab="month",ylab="LST at station")
852
title(paste("Monthly LST at stations in Oregon", "2010",sep=" "))
853
png(paste("LST_at_stations_per_month_",out_prefix,".png", sep=""), type="png")
854
                  
890
#plot(data_month_all$month,data_month_all$LST, xlab="month",ylab="LST at station")                  
855 891

  
856 892
statistics_LST_s<- LST_stat$avg #extracted earlier!!!
857 893

  
858
png(paste("Monthly_mean_TMax_LST_at_Stations_",out_prefix,".png", sep=""), type="png")
859

  
860
plot(TMax_avgm,type="b",ylim=c(0,35),col="red",xlab="month",ylab="tmax (degree C)")
861
lines(1:12,LST_avgm$LST,type="b",col="blue")
894
##Now plot Figure 13a
895
plot(TMax_avgm,type="b",ylim=c(-10,50),col="black",xlab="month",ylab="tmax (degree C)")
896
lines(1:12,LST_avgm$LST,type="b",col="black",lty="dashed",pch=2)
862 897
#lines(1:12,statistics_LST_s$mean,type="b",col="darkgreen")
863
text(TMax_avgm[,1],TMax_avgm[,2],rownames(statistics_LST_s),cex=0.8,pos=2)
864
                  
865
legend("topleft",legend=c("TMax","LST"), cex=1, col=c("red","blue"),
866
              lty=1,bty="n")
898
lines(1:12,LST_avgm_min$LST,type="b",col="black",lty="dashed",pch=3)
899
lines(1:12,LST_avgm_max$LST,type="b",col="black",lty="dashed",pch=4)
900
text(1:12,LST_avgm$LST,month.abb,cex=0.8,pos=2)
901
legend("topleft",legend=c("TMax","LST","LST min","LST max"), cex=1, col=c("black","black","black","black"),
902
              lty=c("solid","dashed","dashed","dashed"),pch=1:4,bty="n")
867 903
title(paste("Monthly mean tmax and LST at stations in Oregon", "2010",sep=" "))           
868 904

  
869 905
##################################################
......
876 912
#data_month_all_grass<-data_month_all[data_month_all$LC6>=10,]
877 913
data_month_all_urban<-data_month_all[data_month_all$LC9>=50,]
878 914

  
879
LST_avgm_forest<-aggregate(LST~month,data=data_month_all_forest,mean)
880
LST_avgm_grass<-aggregate(LST~month,data=data_month_all_grass,mean)
881
LST_avgm_urban<-aggregate(LST~month,data=data_month_all_urban,mean)
882

  
883
plot(TMax_avgm,type="b",ylim=c(-7,42))
884
lines(LST_avgm$LST,col="blue",add=T)
885
lines(LST_avgm_forest,col="green",add=T)
886
lines(LST_avgm_grass,col="red",add=T)
887
lines(LST_avgm_urban,col="pink",add=T)
888
legend("topleft",legend=c("TMax","LST","LST_forest","LST_grass","LST_urban"), cex=0.8, col=c("black","blue","green","red","pink"),
889
       lty=1,bty="n")
915
LST_avgm_forest <-aggregate(LST~month,data=data_month_all_forest,mean)
916
LST_avgm_grass <-aggregate(LST~month,data=data_month_all_grass,mean)
917
LST_avgm_urban <-aggregate(LST~month,data=data_month_all_urban,mean)
918

  
919
##Now plot Figure 13b
920
plot(TMax_avgm,type="b",ylim=c(-7,50),col="black",xlab="month",ylab="tmax (degree C)")
921
lines(1:12,LST_avgm$LST,type="b",col="black",lty="dashed",pch=2)
922
lines(LST_avgm_forest,type="b",col="black",lty="dotted",pch=3)
923
lines(LST_avgm_grass,type="b",col="black",lty="dotdash",pch=4)
924
#lines(LST_avgm_urban,type="b",col="black",lty="longdash",pch=4)
925
legend("topleft",legend=c("TMax","LST","LST_forest","LST_grass"), cex=0.8, col=c("black","black","black","black","black"),
926
       lty=1:4,pch=1:4,bty="n")
890 927
title(paste("Monthly average tmax for stations in Oregon ", "2010",sep=""))
891 928

  
892
savePlot(paste("Temporal_profile_res",id[i],out_prefix,".png", sep=""), type="png")  
893

  
894 929
##################################################
895 930
####### Figure 13c: spatial variation -MoranI and  std  
896 931

  
......
899 934
list_lf_gam_CAI <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_CAI"]])$method_mod_obj,"dailyTmax") #getting objet
900 935
list_lf_gam_fss <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_fss"]])$method_mod_obj,"dailyTmax") #getting objet
901 936

  
902
#nb_lag <- 10
937
nb_lag <- 10
903 938
list_filters<-lapply(1:nb_lag,FUN=autocor_filter_fun,f_type="queen") #generate lag 10 filters
904
list_param_stat_moran <- list(filter=list_filters[[10]],lf_list=list_lf_gam_CAI)
905
tt <- stat_moran_std_raster_fun(1,list_param=list_param_stat_moran)
906
tt <- mclapply(1:11, list_param=list_param_stat_moran, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
907
list_param_stat_moran <- list(filter=list_filters[[10]],lf_list=list_lf_gam_fss)
939
list_param_stat_moran_CAI <- list(filter=list_filters[[10]],lf_list=list_lf_gam_CAI)
940
#tt <- stat_moran_std_raster_fun(1,list_param=list_param_stat_moran)
941
tt <- mclapply(1:11, list_param=list_param_stat_moran_CAI, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
908 942

  
909 943
#Takes 1 hour to get the average moran's I for the whole year so load moran_std_tt_fss2.RData
944
#list_param_stat_moran <- list(filter=list_filters[[10]],lf_list=list_lf_gam_fss)
910 945
#tt_fss <- mclapply(1:365, list_param=list_param_stat_moran, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
911 946
#save(tt_fss,file=file.path(out_dir,"moran_std_tt_fss.RData"))
912
#tx<- do.call(rbind,tt_fss)
947
#list_param_stat_moran <- list(filter=list_filters[[10]],lf_list=list_lf_gam_CAI)
948
#tt_CAI <- mclapply(1:365, list_param=list_param_stat_moran, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
949
#save(tt_CAI,file=file.path(out_dir,"moran_std_tt_CAI.RData"))
913 950

  
914
#dates <-strptime(dates, "%Y%m%d")   # interpolation date being processed
915
#mo<-as.integer(strftime(dates, "%m"))          # current month of the date being processed
916

  
917
dates<-unique(raster_obj$tb_diagnostic_v$date)
951
#tx<- do.call(rbind,tt_fss)
918 952
tt_fss2 <- load_obj("moran_std_tt_fss2.RData")
919 953
tx<- do.call(rbind,tt_fss2)
920
dates_proc<-strptime(dates, "%Y%m%d")   # interpolation date being processed
921 954

  
955
dates<-unique(raster_obj$tb_diagnostic_v$date)
956
dates_proc<-strptime(dates, "%Y%m%d")   # interpolation date being processed
922 957
dates_proc <- as.data.frame(dates_proc)
923 958
dates_proc$index <- 1:365
924 959
tx2 <- merge(tx,dates_proc,by="index")
......
937 972
# end of pasted
938 973
x<-subset(tb_mod_m_avg,pred_mod=="mod7")
939 974

  
940
plot(x$month,x$moranI,type="b",col="blue")
975
##Now plot Figure 13c
976
plot(x$month,x$moranI,ylim=c(0.72,0.92),ylab="Lag 10 Moran's I autocorrelation",
977
     xlab="Month",
978
     type="b",col="black",lty="solid",pch=1)
941 979
par(new=TRUE)              # key: ask for new plot without erasing old
942
plot(x$month,x$std,type="b",col="red",axes=F)
980
plot(x$month,x$std,type="b",col="black",lty="dashed",pch=2,axes=F,
981
     xlab="",ylab="")
943 982
  #axis(4,xlab="",ylab="elevation(m)")  
944 983
axis(4,cex=1.2)
984
legend("topleft",legend=c("Moran's I","Stand Dev."), cex=0.8, col=c("black","black"),
985
       lty=1:2,pch=1:2,bty="n")
986

  
987
title("Spatial variation in FSS surfaces")
945 988

  
946 989
##################################################
947 990
####### Figure 13d: correlation between elevation and LST
948 991

  
949 992
LST_s <- subset(s_raster,c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12"))
950
LST1 <- subset(LST_s,1)
951

  
952
test<-stack(LST_s,elev)
953
names(test) <- c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12","elev")
954
x_cor <-layerStats(test,stat="pearson",na.rm=T)
955
corr(values(LST1),values(elev))
956
plot(1:12,x_cor[[1]][1:12,13],type="b",ylab="corelation",xlab="month",main="correlation between elevation and LST")
957

  
958
#now summarize by month...
993
elev <- subset(s_raster,"elev_s")
994
LC1 <- subset(s_raster,"LC1")
959 995

  
960
#plot(data_month$TMax,add=TRUE)
961
#list_data_s <-extract_list_from_list_obj(load_obj(list_raster_obj_files$gam_CAI)$validation_mod_obj,"data_s")
962
#list_data_v <-extract_list_from_list_obj(load_obj(list_raster_obj_files$gam_CAI)$validation_mod_obj,"data_v")
996
#### Now elev
963 997

  
964
#data_s <- list_data_s[[1]]
965
#res_m <- data_s$dailyTmax - data_s$mod3
966
#SSRES_m <- sum((res_m)^2,na.rm=T)
967
#res_dev <- data_s$dailyTmax - data_s$mod3_del
968
#SSRES_dev <- sum((res_dev)^2,na.rm=T)
969
#SST <- sum((data_s$dailyTmax - mean(data_s$dailyTmax))^2,na.rm=T)
998
r_tmp1 <-stack(LST_s,elev)
999
names(r_tmp1) <- c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12","elev")
1000
x_cor_tmp1 <-layerStats(r_tmp,stat="pearson",na.rm=T)
970 1001

  
971
#1- (SSRES_m/SST)
972
#1- (SSRES_dev/SST)
1002
r_tmp2 <-stack(LST_s,LC1)
1003
names(r_tmp2) <- c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12","LC1")
1004
x_cor_tmp2 <-layerStats(r_tmp2,stat="pearson",na.rm=T)
973 1005

  
1006
##Now plot Figure 13d
1007
plot(1:12,x_cor_tmp1[[1]][1:12,13],ylim=c(-0.8,0.5),
1008
     type="b",lty="solid",pch=1,
1009
     ylab="Pearson corelation",xlab="month",main="Correlation between LST-elevation and LST-Forest")
1010
lines(1:12,x_cor_tmp2[[1]][1:12,13],type="b",lty="dashed",pch=2)
974 1011

  
1012
legend("topleft",legend=c("Correlation LST-Elevation","Correlation LST-Forest"), cex=1.1, col=c("black","black"),
1013
       lty=1:2,pch=1:2,bty="n")
975 1014

  
976
#### Now elev?
977
#LC1<-mask(LC1,mask_ELEV_SRTM)
978
#  cellStats(LC1,"countNA")        #Check that NA have been assigned to water and areas below 0 m
979
  
980
#LC1_50_m<- LC1>50
981
#LC1_100_m<- LC1>=100
982
#LC1_50_m[LC1_50_m==0]<-NA
983
#LC1_100_m[LC1_100_m==0]<-NA
984
#LC1_50<-LC1_50_m*LC1
985
#LC1_100<-LC1_100_m*LC1
986
#avl<-c(0,500,1,500,1000,2,1000,1500,3,1500,2000,4,2000,4000,5)
987
#rclmat<-matrix(avl,ncol=3,byrow=TRUE)
988
#elev_rec<-reclass(ELEV_SRTM,rclmat)  #Loss of layer names when using reclass
989
  
990
#elev_rec_forest<-elev_rec*LC1_100_m
991
#avg_elev_rec<-zonal(rast_diff,zones=elev_rec,stat="mean",na.rm=TRUE)
992
#std_elev_rec<-zonal(rast_diff,zones=elev_rec,stat="sd",na.rm=TRUE)
993
#avg_elev_rec_forest<-zonal(rast_diff,zones=elev_rec_forest,stat="mean",na.rm=TRUE)
994
#std_elev_rec_forest<-zonal(rast_diff,zones=elev_rec_forest,stat="sd",na.rm=TRUE)
995
  
996
## CREATE plots
997
#X11()
998
#plot(avg_elev_rec[,1],avg_elev_rec[,2],type="b",ylim=c(-10,1),
999
#       ylab="",xlab="",axes=FALSE)
1000
#mtext("tmax difference between FSS and CAI (degree C)",side=2,cex=1.2,line=3,font=2)
1001
#mtext("elevation classes (m)",side=1,cex=1.2,line=3,font=2)
1002
#lines(avg_elev_rec_forest[,1],avg_elev_rec_forest[,2],col="green",type="b") #Elevation and 100% forest...
1003
#breaks_lab<-avg_elev_rec[,1]
1004
#elev_lab<-c("0-500","500-1000","1000-1500","1500-2000","2000-4000")
1005
#axis(side=1,las=1,
1006
#       at=breaks_lab,labels=elev_lab, cex=1.5,font=2) #reduce number of labels to Jan and June
1007
#axis(2,cex.axis=1.2,font=2)
1008
#legend("bottomleft",legend=c("Elevation", "elev_forest"), 
1009
#         cex=1, lwd=1.3,col=c("black","green"),bty="n",
1010
#         lty=1)
1011
#box()
1012
#title(paste("Prediction tmax difference (",mf_selected,"-",mc_selected,") and elevation ",sep=""),cex=1.4,font=2)
1013
#savePlot(paste("fig7_diff_prediction_tmax_difference_elevation",mf_selected,mc_selected,date_selected,out_prefix,".png", sep="_"), type="png")
1014
#dev.off()
1015
#closing file for figure 13
1016
dev.off()
1015 1017

  
1016 1018

  
1017 1019
###################### END OF SCRIPT #######################
climate/research/oregon/interpolation/multi_timescales_paper_interpolation_functions.R
5 5
#Functions used in the production of figures and data for the multi timescale paper are recorded.
6 6
#AUTHOR: Benoit Parmentier                                                                      #
7 7
#DATE CREATED: 11/25/2013            
8
#DATE MODIFIED: 12/23/2013            
9
#Version: 1
8
#DATE MODIFIED: 12/25/2013            
9
#Version: 2
10 10
#PROJECT: Environmental Layers project                                       #
11 11
#################################################################################################
12 12

  
......
454 454

  
455 455

  
456 456
#computer averages and nobs per month for a givenvarialbe
457
#plot_mean_nobs_r_stack_by_month
457 458
plot_mean_nobs_r_stack_by_month <-function(var_s,var_nobs,y_range_nobs,y_range_avg,var_name,out_prefix){
458 459
  
459 460
  LST_s <- var_s 

Also available in: Unified diff