Project

General

Profile

« Previous | Next » 

Revision 9c627105

Added by Benoit Parmentier over 11 years ago

initial commit combined boxplots for later use

View differences:

climate/research/oregon/interpolation/IBS_combined_boxplots.R
1
### PLOTTING ALL MODELS IN ONE PLOT
2

  
3
names(tmp44)
4
tb_gam<-subset(tmp44$gam1)
5
tb_gwr
6
tb_gam<-tmp44
7
tb_cai4
8
tb_fus5
9
tab_list<-tmp44
10

  
11
names(tb_gam)
12
tb_gam<-tb_gam[,-11]
13
names_methods<-c("kr","gwr","gam","cai","fss")
14
tb_list[[1]]<-tb_gam
15
metric_selected<-"RMSE"
16
tb_methods_combined<-function(tab_list,metric_selected,names_methods){
17
  tab_metric<-tab_list
18
  for (k in 1:length(tab_list)){
19
    #tab_list[[k]]$methods<-rep(names_methods[k],nrow(tab_list[[k]]))
20
    tab_metric[[k]]<-subset(tab_list[[k]],metric==metric_selected)
21
    new_names<-paste(names_methods[k],names(tab_metric[[k]])[4:ncol(tab_metric[[k]])],sep="_")
22
    names(tab_metric[[k]])[4:ncol(tab_metric[[k]])]<-new_names
23
    tab_metric[[k]]<-tab_metric[[k]][4:ncol(tab_metric[[k]])]
24
  }
25
  tab_sub<-tab_list[[k]][,1:3]
26
  tab_all<-do.call(cbind,tab_metric)
27
  tab_all<-cbind(tab_sub,tab_all)
28
  return(tab_all)
29
}
30

  
31
tab_combined<-tb_methods_combined(tab_list,metric_selected,names_methods)
32
head(tab_combined)
33
dim(tab_combined)
34
tmp_names<-names(tab_combined)
35
tmp_names2<-strsplit(tmp_names[4:length(tmp_names)],"\\.")
36
for (k in 1:length(tmp_names2)){
37
  tmp_names2[[k]]<-tmp_names2[[k]][[2]]
38
}
39
tab_combined2<-tab_combined
40
names(tab_combined2[4:length(tab_combined)])<-as.character(tmp_names2)
41
##DROP SOME MODELS
42
drop_mod_names<-c("kr_mod8","kr_mod9","gam_mod8","gam_mod9","cai_mod9","fss_mod9")
43
pos<-match(drop_mod_names,tmp_names2)
44
tab_combined2<-tab_combined2[4:length(tab_combined2)]
45
tab_combined2<-tab_combined2[,-pos]
46
tmp_names2<-as.character(tmp_names2[-pos])
47
pos<-match(c("cai_mod10","fss_mod10"),tmp_names2)
48
tmp_names2[pos]<-c("cai_mod9","fss_mod9")
49
X11(width=18,height=6)
50
boxplot(tab_combined2,las=2,names=tmp_names2,
51
        ylim=c(1,5),ylab="RMSE", outline=FALSE)
52
title(paste("Root Mean Square Errors for daily maximum temperature models",sep=""))
53
grid()
54
savePlot(paste("fig2_boxplot_all_models_combined_",out_prefix,".png", sep=""), type="png")
55
dev.off()
56

  
57
mean(tab_combined[4:49])
58

  
59
inlistobj2<-inlistobj[3:5]
60
namesobj2<-names_obj[3:5]
61
namesobj2<-c("gam","cai","fss")
62

  
63
tab_formulas_fun<-function(list_obj2,path_data,names_obj2){
64
  inlistobj2<-list_obj2
65
  nel<-length(inlistobj2)
66
  #method_mod <-vector("list",nel) #list of one row data.frame
67
  method_tb <-vector("list",nel) #list of one row data.frame
68
  list_formulas_mod<-vector("list",length(inlistobj2))
69
  for (k in 1:length(inlistobj2)){
70
    mod_tmp<-load_obj(as.character(inlistobj2[k]))
71
    tmp_formulas<-vector("list",length(mod_tmp[[1]]$mod_obj))
72
    for (j in 1:length(mod_tmp[[1]]$mod_obj)){
73
      mod<-mod_tmp[[1]]$mod_obj[[j]]
74
      tmp_formulas[[j]]<-formula(mod)
75
      #tb<-mod_tmp[[1]][[3]][0,] #copy of the data.frame structure that holds the acuary metrics
76
    }
77
    #j=1
78
    list_formulas_mod[[k]]<-as.character(tmp_formulas)
79
  }
80
  names(tmp_formulas)<-names_obj2
81
  return(tmp_formulas)
82
}
83

  
84
#write.table(as.character(list_formulas_mod[[k]]),file="formulas_CAI4_01052013.txt",sep=",")
85
formulas_all<-list_formulas_mod[[1]]
86
formulas_all<-tab_formulas_fun(inlistobj2,path_data,namesobj2)
87
write.table(as.character(formulas_all),file="formulas_GAM1_01052013.txt",sep=",")
88

  
89
##EXPLORATION CODE
90

  
91
lf_raster_fus<-"_365d_GAM_fus5_all_lstd_12302012.rst"
92
#lf_raster_fus<-"_365d_GAM_fusion_all_lstd_12272012.rst"
93

  
94
lf_raster_cai<-"_365d_GAM_CAI4_all_12272012.rst"
95
date_selected<-"20100901"
96
#titles<-list(cai=c("cai_kr","cai_mod5","cai mod8"),
97
#             fusion=c("fusion_kr"," fusion_mod5"," fusion_mod8"))
98

  
99
file_pat1<-glob2rx(paste("*",date_selected,"*",lf_raster_cai,sep="")) #Search for files in relation to fusion                                   
100
file_pat2<-glob2rx(paste("*",date_selected,"*",lf_raster_fus,sep="")) #Search for files in relation to fusion
101
lf_1<-list.files(pattern=file_pat1) #Search for files in relation to fusion                  
102
lf_2<-list.files(pattern=file_pat2) #Search for files in relation to fusion
103

  
104
#titles<-list(c("cai_kr","cai_mod1","cai_mod2","cai_mod3","cai_mod4","cai_mod5","cai_mod6","cai_mod7","cai_mod8","cai_mod9","fss_kr"))
105
titles<-list(c("fss_kr","fss_mod1","fss_mod2","fss_mod3","fss_mod4","fss_mod5","fss_mod6","fss_mod7","fss_mod8","fss_mod9","cai_kr"))
106

  
107
r1<-stack(lf_cai) #CAI
108
r2<-stack(lf_fus)#FUS
109

  
110
predictions<-stack(r2,subset(r1,1))
111
predictions<-mask(predictions,mask_rast)
112
layerNames(predictions)<-unlist(titles)
113
plot_name_pan<-unlist(titles)
114
#plot_name_pan<-c('cai_kr (RMSE=2.29)','cai_mod7 (RMSE=2.38)','fss_kr (RMSE=2.29')
115
s.range <- c(min(minValue(predictions)), max(maxValue(predictions)))
116
#s.range <- s.range+c(5,-5)
117
col.breaks <- pretty(s.range, n=50)
118
lab.breaks <- pretty(s.range, n=5)
119
temp.colors <- colorRampPalette(c('blue', 'white', 'red'))
120
X11(height=6,width=36)
121
X11(height=6,width=18)
122
s.range<-c(-5,35)
123
#plot(predictions, breaks=col.breaks, col=rev(heat.colors(length(col.breaks)-1)),
124
#   axis=list(at=lab.breaks, labels=lab.breaks))
125
plot(predictions, breaks=col.breaks, col=temp.colors(length(col.breaks)-1),
126
     axis=list(at=lab.breaks, labels=lab.breaks))
127
#plot(reg_outline, add=TRUE)
128
savePlot(paste("comparison_one_date_CAI_fusion_tmax_prediction_levelplot",date_selected,out_prefix,".png", sep=""),type="png")
129
X11(height=12,width=24)
130

  
131
png(paste("comparison_one_date_CAI_fusion_tmax_prediction_levelplot_",date_selected,out_prefix,".png", sep=""),
132
    height=480*layout_m[1],width=480*layout_m[2])
133
levelplot(predictions,main="Interpolated Surfaces Comparison", ylab=NULL,xlab=NULL,par.settings = list(axis.text = list(font = 2, cex = 1.3),
134
          par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
135
          names.attr=plot_name_pan,col.regions=temp.colors,at=seq(s.range[1],s.range[2],by=0.25))
136
#col.regions=temp.colors(25))
137
saveplot(paste("comparison_one_date_CAI_fusion_tmax_prediction_levelplot_all",date_selected,out_prefix,".png", sep=""),type="png")
138
dev.off()
139

  
140

  
141
#daily_delta<-raster(lf_2[c(2)])
142
#bias_mod6<-raster(lf_2[c(9)])
143
#fus_mod6<-raster(lf_2[c(18)])
144

  
145
#clim_mod6<-raster(lf_1[c(9)])
146
#cai_mod6<-raster(lf_1[c(18)])
147
#tmp_cai<-daily_delta+clim_mod6
148
#clim2_mod6<-themolst-bias_mod6-273.16
149
#tmp_fus<-daily_delta+themolst-bias_mod6-273.16
150
#test_fus<-fus_mod6-tmp_fus
151
#test_cai<-cai_mod6-tmp_cai
152
#s_pred<-stack(test_fus,test_cai)
153
#plot(s_pred)
154
#s_clim<-stack(clim2_mod6,clim_mod6)
155
#diff<-test_fus-test_cai
156
#plot(diff)
157
#diff<-clim2_mod6-clim2_mod6
158
#plot(diff)

Also available in: Unified diff