Revision bcef031f
Added by Benoit Parmentier over 11 years ago
climate/research/oregon/interpolation/GAM_fusion_function_multisampling_validation_metrics.R | ||
---|---|---|
178 | 178 |
## Function to display metrics by months/seasons |
179 | 179 |
boxplot_month_from_tb <-function(tb_diagnostic,metric_names,out_prefix){ |
180 | 180 |
#Add code here... |
181 |
#d_month<-aggregate(TMax~month, data=tb_diagnostic, mean) #Calculate monthly mean for every station in OR |
|
182 |
#d_month<-aggregate(TMax~month, data=tb_diagnostic, legnth) #Calculate monthly mean for every station in OR |
|
181 |
date_f<-strptime(tb_diagnostic$date, "%Y%m%d") # interpolation date being processed |
|
182 |
tb_diagnostic$month<-strftime(date_f, "%m") # current month of the date being processed |
|
183 |
mod_names<-sort(unique(tb_diagnostic$pred_mod)) #models that have accuracy metrics |
|
184 |
tb_mod_list<-lapply(mod_names, function(k) subset(tb_diagnostic, pred_mod==k)) #this creates a list of 5 based on models names |
|
185 |
names(tb_mod_list)<-mod_names |
|
186 |
agg_by_month <-function(tb_mod_list,j,metric_names){ |
|
187 |
for (k in 1:length(metric_names)){ |
|
188 |
metric_ac<-metric_names[k] |
|
189 |
mod_pat<-glob2rx(paste(metric_ac,"_*",sep="")) |
|
190 |
mod_var<-grep(mod_pat,names(mod_metrics),value=TRUE) # using grep with "value" extracts the matching names |
|
191 |
d_month<-aggregate(metric_n~month, data=tb_mod_list[[j]], mean) #Calculate monthly mean for every station in OR |
|
192 |
} |
|
193 |
return(d_month) |
|
194 |
} |
|
195 |
test<-lapply(1:length(tb_mod_list),FUN=agg_by_month,tb_mod_list=tb_mod_list) |
|
196 |
|
|
197 |
t<-melt(tb_diagnostic, |
|
198 |
#measure=mod_var, |
|
199 |
id=c("date","pred_mod","prop","month"), |
|
200 |
na.rm=F) |
|
201 |
test<-cast(t,pred_mod+month~variable,mean) |
|
202 |
tb_mod_list<-lapply(mod_names, function(k) subset(tb_diagnostic, pred_mod==k)) #this creates a list of 5 based on models names |
|
203 |
for (k in 1:tb_mod_m_ist){ |
|
204 |
for (j in 1:length(metric_names)){ |
|
205 |
metric_ac<-metric_names[j] |
|
206 |
mod_pat<-glob2rx(paste(metric_ac,"_*",sep="")) |
|
207 |
mod_var<-grep(mod_pat,names(mod_metrics),value=TRUE) # using grep with "value" extracts the matching names |
|
208 |
#browser() |
|
209 |
test<-mod_metrics[mod_var] |
|
210 |
png(paste("boxplot_metric_",metric_ac, out_prefix,".png", sep="")) |
|
211 |
boxplot(test,outline=FALSE,horizontal=FALSE,cex=0.5, |
|
212 |
ylab=paste(metric_ac,"in degree C",sep=" ")) |
|
213 |
#legend("bottomleft",legend=paste(names(rows_total),":",rows_total,sep=""),cex=0.7,bty="n") |
|
214 |
title(as.character(t(paste(t(names(rows_total)),":",rows_total,sep=""))),cex=0.8) |
|
215 |
dev.off() |
|
216 |
} |
|
217 |
} |
|
218 |
|
|
183 | 219 |
|
184 | 220 |
|
185 | 221 |
} |
Also available in: Unified diff
validation first modification to add monthly averages for accuracy metrics