Revision 7c069e64
Added by Benoit Parmentier over 10 years ago
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/09/2014
|
|
7 |
#MODIFIED ON: 07/18/2014
|
|
8 | 8 |
#Version: 5 |
9 | 9 |
#PROJECT: Environmental Layers project |
10 | 10 |
################################################################################################# |
... | ... | |
31 | 31 |
library(automap) # Kriging automatic fitting of variogram using gstat |
32 | 32 |
library(rgeos) # Geometric, topologic library of functions |
33 | 33 |
#RPostgreSQL # Interface R and Postgres, not used in this script |
34 |
library(gridExtra) |
|
35 |
library(colorRamps) |
|
34 |
library(gridExtra) # Combining lattice plots
|
|
35 |
library(colorRamps) # Palette/color ramps for symbology
|
|
36 | 36 |
#Additional libraries not used in workflow |
37 | 37 |
library(pgirmess) # Krusall Wallis test with mulitple options, Kruskalmc {pgirmess} |
38 |
library(ncf) |
|
38 |
library(ncf) # No paramtric covariance function |
|
39 |
|
|
39 | 40 |
#### FUNCTION USED IN SCRIPT |
40 | 41 |
|
41 | 42 |
function_analyses_paper <-"contribution_of_covariates_paper_interpolation_functions_05212014.R" |
... | ... | |
66 | 67 |
met_stations_outfiles_obj_file<-"/data/project/layers/commons/data_workflow/output_data_365d_gam_fus_lst_test_run_07172013/met_stations_outfiles_obj_gam_fusion__365d_gam_fus_lst_test_run_07172013.RData" |
67 | 68 |
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 |
68 | 69 |
y_var_name <- "dailyTmax" |
69 |
out_prefix<-"_07032014"
|
|
70 |
out_prefix<-"_07182014"
|
|
70 | 71 |
out_dir<-"/home/parmentier/Data/IPLANT_project/paper_contribution_covar_analyses_tables_fig" |
71 | 72 |
setwd(out_dir) |
72 | 73 |
|
... | ... | |
219 | 220 |
table_data1 <- table_data1[1,] |
220 | 221 |
|
221 | 222 |
table_ac <-do.call(rbind, list(table_data1,table_data3,table_data4)) |
222 |
table_ac <- round(table_ac,digit=3) #roundto three digits teh differences
|
|
223 |
table_ac <- round(table_ac,digit=3) #roundto three digits the differences
|
|
223 | 224 |
|
224 | 225 |
#combined tables with accuracy metrics and their standard deviations |
225 | 226 |
table4_paper <-table_combined_symbol(table_ac,table_sd,"±") |
... | ... | |
231 | 232 |
table4_paper$Model <-model_col |
232 | 233 |
names(table4_paper)<- names_table_col |
233 | 234 |
|
234 |
file_name<-paste("table4_compariaons_interpolation_methods_avg_paper","_",out_prefix,".txt",sep="")
|
|
235 |
file_name<-paste("table4_comparisons_interpolation_methods_avg_paper","_",out_prefix,".txt",sep="")
|
|
235 | 236 |
write.table(as.data.frame(table4_paper),file=file_name,sep=",") |
236 | 237 |
|
237 | 238 |
#################################### |
... | ... | |
990 | 991 |
l_obj[[1]]<-raster_prediction_obj_1 |
991 | 992 |
l_obj[[2]]<-raster_prediction_obj_2 |
992 | 993 |
l_table <- vector("list",length=length(l_obj)) |
994 |
l_s_table_term_tb <- vector("list",length(l_obj)) |
|
993 | 995 |
for (k in 1:length(l_obj)){ |
994 | 996 |
raster_prediction_obj<- l_obj[[k]] |
997 |
#extract models for every day |
|
995 | 998 |
list_myModels <- extract_list_from_list_obj(raster_prediction_obj$method_mod_obj,"mod") |
996 | 999 |
|
997 | 1000 |
list_models_info <-lapply(1:length(list_myModels),FUN=create_s_and_p_table_term_models,list_myModels) |
... | ... | |
999 | 1002 |
names(list_models_info)<-dates #adding names to the list |
1000 | 1003 |
|
1001 | 1004 |
#Prepare and process p. value information regarding models: count number of times values were above a threshold. |
1002 |
s.table_term_tb <-extract_from_list_obj(list_models_info,"s.table_term") |
|
1003 |
|
|
1005 |
#s.table_term_tb <-extract_from_list_obj(list_models_info,"s.table_term") |
|
1006 |
s.table_term_list <- extract_list_from_list_obj(list_models_info,"s.table_term") |
|
1007 |
names(s.table_term_list) <- dates #adding names to the list |
|
1008 |
#Adding dates to df |
|
1009 |
s.table_term_list <- add_rownames_list_df(s.table_term_list) |
|
1010 |
s.table_term_tb <- do.call(rbind.fill,s.table_term_list) |
|
1011 |
#Adding month to df |
|
1012 |
#s.table_term_tb <- add_month_tag(s.table_term_tb) |
|
1013 |
s.table_term_tb$month <- add_month_tag(s.table_term_tb,"rownames") |
|
1014 |
|
|
1004 | 1015 |
threshold_val<-c(0.01,0.05,0.1) |
1005 | 1016 |
s.table_term_tb$p_val_rec1 <- s.table_term_tb[["p-value"]] < threshold_val[1] |
1006 | 1017 |
s.table_term_tb$p_val_rec2 <- s.table_term_tb[["p-value"]] < threshold_val[2] |
1007 | 1018 |
s.table_term_tb$p_val_rec3 <- s.table_term_tb[["p-value"]] < threshold_val[3] |
1008 | 1019 |
|
1009 | 1020 |
names_var <- c("p_val_rec1","p_val_rec2","p_val_rec3") |
1021 |
|
|
1022 |
|
|
1010 | 1023 |
t2<-melt(s.table_term_tb, |
1011 | 1024 |
measure=names_var, |
1012 | 1025 |
id=c("mod_name","term_name"), |
... | ... | |
1038 | 1051 |
tables_AIC_ac_p_val <-list(table,summary_s.table_term2) |
1039 | 1052 |
names(tables_AIC_ac_p_val) <-c("table","s.table_p_val_term") |
1040 | 1053 |
l_table[[k]] <- tables_AIC_ac_p_val |
1054 |
l_s_table_term_tb[[k]] <- s.table_term_tb |
|
1041 | 1055 |
} |
1042 | 1056 |
|
1043 | 1057 |
## Now prepare table |
... | ... | |
1071 | 1085 |
file_name<-paste("table6b_paper","_",out_prefix,".txt",sep="") |
1072 | 1086 |
write.table(table6b,file=file_name,sep=",") |
1073 | 1087 |
|
1088 |
##Add new figure: |
|
1089 |
|
|
1090 |
s.table_term_tb <- l_s_table_term_tb[[2]] #baseline 2 (lat*lon) |
|
1091 |
s.table_term_tb <- l_s_table_term_tb[[1]] #baseline 1 (lat*lon+elev_s) |
|
1092 |
tt <- aggregate(s.table_term_tb$p_val_rec2~s.table_term_tb$month,FUN=mean) |
|
1093 |
tt <- aggregate(s.table_term_tb$p_val_rec2~s.table_term_tb$month,FUN=mean) |
|
1094 |
plot(tt) |
|
1095 |
test <- subset(s.table_term_tb,mod_name=="mod4" & term_name=="s(LST)") |
|
1096 |
tt<-aggregate(test$p_val_rec3~test$month,FUN=mean) |
|
1097 |
plot(tt,type="l",ylim=c(0.2,1)) |
|
1098 |
test2 <- subset(s.table_term_tb,mod_name=="mod4" & term_name=="s(elev_s)") |
|
1099 |
tt2<-aggregate(test2$p_val_rec2~test2$month,FUN=mean) |
|
1100 |
plot(tt2) |
|
1101 |
lines(tt2) |
|
1102 |
test1 <- subset(s.table_term_tb,mod_name=="mod1" & term_name=="s(elev_s)") |
|
1103 |
tt1<-aggregate(test1$p_val_rec2~test1$month,FUN=mean) |
|
1104 |
plot(tt1) |
|
1105 |
#model with LST and elev |
|
1106 |
tb1_mod4_month <- raster_prediction_obj_1$summary_month_metrics_v[[4]] #note that this is for model1 |
|
1107 |
#model with lev only |
|
1108 |
b1_mod1_month <- raster_prediction_obj_1$summary_month_metrics_v[[1]] #note that this is for model1 |
|
1109 |
|
|
1110 |
tb1_mod1_month<-raster_prediction_obj_1$summary_month_metrics_v[[1]] #note that this is for model1 |
|
1111 |
plot((tb1_mod4_month$rme) - tb1_mod1_month$rmse) |
|
1112 |
|
|
1113 |
#now get correlation with LST and elev |
|
1114 |
list_data_s <-extract_list_from_list_obj(raster_prediction_obj_1$validation_mod_obj,"data_s") |
|
1115 |
list_data_v <-extract_list_from_list_obj(raster_prediction_obj_1$validation_mod_obj,"data_v") |
|
1116 |
|
|
1117 |
data_v_combined <-convert_spdf_to_df_from_list(list_data_v) #long rownames |
|
1118 |
|
|
1119 |
|
|
1120 |
#LSTD_bias_avgm<-aggregate(LSTD_bias~month,data=data_month_all,mean) |
|
1121 |
#LSTD_bias_sdm<-aggregate(LSTD_bias~month,data=data_month_all,sd) |
|
1122 |
data_v_combined |
|
1123 |
LST_avgm <- aggregate(LST~month+id,data=data_v_combined,mean) |
|
1124 |
#test <- aggregate(LST+dailyTmax~month+id,data=data_v_combined,mean) |
|
1125 |
TMax_avgm <- aggregate(dailyTmax~month+id,data=data_v_combined,mean) |
|
1126 |
|
|
1127 |
elev_id <- aggregate(elev~id,data=data_v_combined,mean) |
|
1128 |
l_df_cor<- vector("list",length=12) |
|
1129 |
for(i in 1:12){ |
|
1130 |
df_LST <- subset(LST_avgm,month==i) |
|
1131 |
df_TMax <- subset(TMax_avgm,month==i) |
|
1132 |
df <-merge(df_LST,df_TMax,by="id",all=F) |
|
1133 |
df_tmp <- merge(df,elev_id,by="id",all=F) |
|
1134 |
cor_LST_dailyTmax <- cor(df_tmp$LST,df_tmp$dailyTmax) |
|
1135 |
cor_elev_dailyTmax <- cor(df_tmp$elev,df_tmp$dailyTmax) |
|
1136 |
df_cor <- data.frame(LST_tmax=cor_LST_dailyTmax,elev_tmax=cor_elev_dailyTmax) |
|
1137 |
l_df_cor[[i]] <- df_cor |
|
1138 |
} |
|
1139 |
#cor elev~ tmax by month |
|
1140 |
#cor LST tmax by month |
|
1141 |
df_cor <- do.call(rbind,l_df_cor) |
|
1142 |
plot(df_cor$LST_tmax,ylim=c(-1,1),col="red",type="l") |
|
1143 |
lines(df_cor$elev_tmax,ylim=c(-1,1),col="blue") |
|
1144 |
|
|
1074 | 1145 |
######################## |
1075 | 1146 |
### Prepare table 7: correlation matrix between covariates |
1076 | 1147 |
|
Also available in: Unified diff
contributions of covariates and methods: revisions -adding analyses for LST contribution