Revision 8188ecd6
Added by Benoit Parmentier almost 9 years ago
climate/research/oregon/interpolation/global_run_scalingup_assessment_part2.R | ||
---|---|---|
5 | 5 |
#Analyses, figures, tables and data are also produced in the script. |
6 | 6 |
#AUTHOR: Benoit Parmentier |
7 | 7 |
#CREATED ON: 03/23/2014 |
8 |
#MODIFIED ON: 01/03/2016
|
|
8 |
#MODIFIED ON: 01/04/2016
|
|
9 | 9 |
#Version: 5 |
10 | 10 |
#PROJECT: Environmental Layers project |
11 | 11 |
#COMMENTS: analyses for run 10 global analyses,all regions 1500x4500km with additional tiles to increase overlap |
... | ... | |
164 | 164 |
mosaic_plot <- list_param_run_assessment_plotting$mosaic_plot #FALSE #PARAM7 |
165 | 165 |
proj_str<- list_param_run_assessment_plotting$proj_str #CRS_WGS84 #PARAM 8 #check this parameter |
166 | 166 |
file_format <- list_param_run_assessment_plotting$file_format #".rst" #PARAM 9 |
167 |
NA_value <- list_param_run_assessment_plotting$NA_value #-9999 #PARAM10
|
|
167 |
NA_flag_val <- list_param_run_assessment_plotting$NA_flag_val #-9999 #PARAM10
|
|
168 | 168 |
multiple_region <- list_param_run_assessment_plotting$multiple_region # <- TRUE #PARAM 11 |
169 | 169 |
countries_shp <- list_param_run_assessment_plotting$countries_shp #<- "world" #PARAM 12 |
170 | 170 |
plot_region <- list_param_run_assessment_plotting$plot_region # PARAM13 |
... | ... | |
173 | 173 |
df_assessment_files_name <- list_param_run_assessment_plotting$df_assessment_files_name #PARAM 16 |
174 | 174 |
threshold_missing_day <- list_param_run_assessment_plotting$threshold_missing_day #PARM17 |
175 | 175 |
|
176 |
NA_flag_val <- NA_value
|
|
176 |
NA_value <- NA_flag_val
|
|
177 | 177 |
|
178 | 178 |
##################### START SCRIPT ################# |
179 | 179 |
|
... | ... | |
220 | 220 |
tb_s$tile_id <- as.character(tb_s$tile_id) |
221 | 221 |
|
222 | 222 |
#multiple regions? #this needs to be included in the previous script!!! |
223 |
if(multiple_region==TRUE){ |
|
224 |
df_tile_processed$reg <- basename(dirname(as.character(df_tile_processed$path_NEX))) |
|
225 |
tb <- merge(tb,df_tile_processed,by="tile_id") |
|
226 |
tb_s <- merge(tb_s,df_tile_processed,by="tile_id") |
|
227 |
tb_month_s<- merge(tb_month_s,df_tile_processed,by="tile_id") |
|
228 |
summary_metrics_v <- merge(summary_metrics_v,df_tile_processed,by="tile_id") |
|
229 |
} |
|
230 |
|
|
231 |
tb_all <- tb |
|
223 |
#if(multiple_region==TRUE){ |
|
224 |
df_tile_processed$reg <- as.character(df_tile_processed$reg) |
|
225 |
tb <- merge(tb,df_tile_processed,by="tile_id") |
|
226 |
tb_s <- merge(tb_s,df_tile_processed,by="tile_id") |
|
227 |
tb_month_s<- merge(tb_month_s,df_tile_processed,by="tile_id") |
|
228 |
summary_metrics_v <- merge(summary_metrics_v,df_tile_processed,by="tile_id") |
|
229 |
#} |
|
232 | 230 |
|
233 |
summary_metrics_v_all <- summary_metrics_v |
|
231 |
#tb_all <- tb |
|
232 |
#summary_metrics_v_all <- summary_metrics_v |
|
234 | 233 |
|
235 | 234 |
#table(summary_metrics_v_all$reg) |
236 | 235 |
#table(summary_metrics_v$reg) |
... | ... | |
345 | 344 |
res_pix <- 480 |
346 | 345 |
col_mfrow <- 1 |
347 | 346 |
row_mfrow <- 1 |
348 |
fig_name <- paste("Figure2a_boxplot_with_oultiers_by_tiles_",model_name[i],"_",out_suffix,".png",sep="")
|
|
347 |
fig_filename <- paste("Figure2a_boxplot_with_oultiers_by_tiles_",model_name[i],"_",out_suffix,".png",sep="")
|
|
349 | 348 |
png(filename=paste("Figure2a_boxplot_with_oultiers_by_tiles_",model_name[i],"_",out_suffix,".png",sep=""), |
350 | 349 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
351 | 350 |
|
... | ... | |
355 | 354 |
dev.off() |
356 | 355 |
list_outfiles[[counter_fig+i]] <- fig_filename |
357 | 356 |
} |
358 |
|
|
357 |
counter_fig <- counter_fig + length(model_name) |
|
359 | 358 |
## Figure 2b |
360 | 359 |
#with ylim and removing trailing... |
361 | 360 |
for(i in 1:length(model_name)){ #there are two models!! |
... | ... | |
381 | 380 |
############### |
382 | 381 |
### Figure 3: boxplot of average RMSE by model acrosss all tiles |
383 | 382 |
|
384 |
## Figure 3a |
|
385 |
res_pix <- 480 |
|
386 |
col_mfrow <- 1 |
|
387 |
row_mfrow <- 1 |
|
388 |
|
|
389 |
png(filename=paste("Figure3a_boxplot_overall_region_with_oultiers_",model_name[i],"_",out_suffix,".png",sep=""), |
|
390 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
391 |
|
|
392 |
boxplot(rmse~pred_mod,data=tb)#,names=tb$pred_mod) |
|
393 |
title("RMSE per model over all tiles") |
|
394 |
dev.off() |
|
395 |
list_outfiles[[counter_fig+1]] <- paste("Figure3a_boxplot_overall_region_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="") |
|
396 |
|
|
397 |
## Figure 3b |
|
398 |
png(filename=paste("Figure3b_boxplot_overall_region_scaling_",model_name[i],"_",out_suffix,".png",sep=""), |
|
399 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
400 |
|
|
401 |
boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod) |
|
402 |
title("RMSE per model over all tiles") |
|
403 |
|
|
404 |
dev.off() |
|
405 |
list_outfiles[[counter_fig+2]] <- paste("Figure3b_boxplot_overall_region_scaling_",model_name[i],"_",out_suffix,".png",sep="") |
|
406 |
counter_fig <- counter_fig + 2 |
|
383 |
for(i in 1:length(model_name)){ #there are two models!! |
|
384 |
## Figure 3a |
|
385 |
res_pix <- 480 |
|
386 |
col_mfrow <- 1 |
|
387 |
row_mfrow <- 1 |
|
388 |
|
|
389 |
png(filename=paste("Figure3a_boxplot_overall_region_with_oultiers_",model_name[i],"_",out_suffix,".png",sep=""), |
|
390 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
391 |
|
|
392 |
boxplot(rmse~pred_mod,data=tb)#,names=tb$pred_mod) |
|
393 |
title("RMSE per model over all tiles") |
|
394 |
dev.off() |
|
395 |
list_outfiles[[counter_fig+1]] <- paste("Figure3a_boxplot_overall_region_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="") |
|
396 |
|
|
397 |
## Figure 3b |
|
398 |
png(filename=paste("Figure3b_boxplot_overall_region_scaling_",model_name[i],"_",out_suffix,".png",sep=""), |
|
399 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
400 |
|
|
401 |
boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod) |
|
402 |
title("RMSE per model over all tiles") |
|
403 |
|
|
404 |
dev.off() |
|
405 |
list_outfiles[[counter_fig+2]] <- paste("Figure3b_boxplot_overall_region_scaling_",model_name[i],"_",out_suffix,".png",sep="") |
|
406 |
} |
|
407 |
counter_fig <- counter_fig + length(model_name) |
|
407 | 408 |
|
408 | 409 |
################ |
409 | 410 |
### Figure 4: plot predicted tiff for specific date per model |
... | ... | |
472 | 473 |
list_outfiles[[counter_fig+i]] <- fig_filename |
473 | 474 |
} |
474 | 475 |
|
475 |
counter_fig <- counter_fig+length(model_name)
|
|
476 |
counter_fig <- counter_fig + length(model_name)
|
|
476 | 477 |
|
477 | 478 |
###################### |
478 | 479 |
### Figure 6: plot map of average RMSE per tile at centroids |
... | ... | |
527 | 528 |
sum(df_tile_processed$metrics_v)/length(df_tile_processed$metrics_v) #80 of tiles with info |
528 | 529 |
|
529 | 530 |
#coordinates |
530 |
#coordinates(summary_metrics_v) <- c("lon","lat")
|
|
531 |
coordinates(summary_metrics_v) <- c("lon.y","lat.y")
|
|
531 |
#try(coordinates(summary_metrics_v) <- c("lon","lat"))
|
|
532 |
try(coordinates(summary_metrics_v) <- c("lon.y","lat.y"))
|
|
532 | 533 |
|
533 | 534 |
#threshold_missing_day <- c(367,365,300,200) |
534 | 535 |
|
... | ... | |
539 | 540 |
|
540 | 541 |
#plot(summary_metrics_v) |
541 | 542 |
#Make this a function later so that we can explore many thresholds... |
542 |
|
|
543 |
#Problem here |
|
544 |
#Browse[3]> c |
|
545 |
#Error in grid.Call.graphics(L_setviewport, pvp, TRUE) : |
|
546 |
#non-finite location and/or size for viewport |
|
547 |
|
|
543 | 548 |
j<-1 #for model name 1 |
544 | 549 |
for(i in 1:length(threshold_missing_day)){ |
545 | 550 |
|
... | ... | |
571 | 576 |
|
572 | 577 |
list_outfiles[[counter_fig+i]] <- fig_filename |
573 | 578 |
} |
574 |
counter_fig <- counter_fig+length(threshold_missing_day) |
|
579 |
counter_fig <- counter_fig+length(threshold_missing_day) #currently 4 days...
|
|
575 | 580 |
|
576 |
png(filename=paste("Figure7b_number_daily_predictions_per_models","_",out_suffix,".png",sep=""), |
|
581 |
png(filename=paste("Figure7b_number_daily_predictions_per_models","_",out_suffix,".png",sep=""),
|
|
577 | 582 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
578 | 583 |
|
579 | 584 |
xyplot(n~pred_mod | tile_id,data=subset(as.data.frame(summary_metrics_v), |
... | ... | |
662 | 667 |
##################################################### |
663 | 668 |
#### Figure 9: plotting boxplot by year and regions ########### |
664 | 669 |
|
665 |
## Figure 9a |
|
666 |
res_pix <- 480 |
|
667 |
col_mfrow <- 1 |
|
668 |
row_mfrow <- 1 |
|
669 |
|
|
670 |
png(filename=paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep=""), |
|
671 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
672 |
|
|
673 |
p<- bwplot(rmse~pred_mod | reg + year, data=tb, |
|
674 |
main="RMSE per model and region over all tiles") |
|
675 |
print(p) |
|
676 |
dev.off() |
|
677 |
|
|
678 |
## Figure 9b |
|
679 |
png(filename=paste("Figure8b_boxplot_overall_separated_by_region_year_scaling_",model_name[i],"_",out_suffix,".png",sep=""), |
|
680 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
681 |
|
|
682 |
boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod) |
|
683 |
title("RMSE per model over all tiles") |
|
684 |
p<- bwplot(rmse~pred_mod | reg, data=tb,ylim=c(0,5), |
|
685 |
main="RMSE per model and region over all tiles") |
|
686 |
print(p) |
|
687 |
dev.off() |
|
688 |
|
|
689 |
list_outfiles[[counter_fig+1]] <- paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="") |
|
690 |
counter_fig <- counter_fig + 1 |
|
670 |
# ## Figure 9a
|
|
671 |
# res_pix <- 480
|
|
672 |
# col_mfrow <- 1
|
|
673 |
# row_mfrow <- 1
|
|
674 |
# |
|
675 |
# png(filename=paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep=""),
|
|
676 |
# width=col_mfrow*res_pix,height=row_mfrow*res_pix)
|
|
677 |
# |
|
678 |
# p<- bwplot(rmse~pred_mod | reg + year, data=tb,
|
|
679 |
# main="RMSE per model and region over all tiles")
|
|
680 |
# print(p)
|
|
681 |
# dev.off()
|
|
682 |
# |
|
683 |
# ## Figure 9b
|
|
684 |
# png(filename=paste("Figure8b_boxplot_overall_separated_by_region_year_scaling_",model_name[i],"_",out_suffix,".png",sep=""),
|
|
685 |
# width=col_mfrow*res_pix,height=row_mfrow*res_pix)
|
|
686 |
# |
|
687 |
# boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod)
|
|
688 |
# title("RMSE per model over all tiles")
|
|
689 |
# p<- bwplot(rmse~pred_mod | reg, data=tb,ylim=c(0,5),
|
|
690 |
# main="RMSE per model and region over all tiles")
|
|
691 |
# print(p)
|
|
692 |
# dev.off()
|
|
693 |
# |
|
694 |
# list_outfiles[[counter_fig+1]] <- paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="")
|
|
695 |
# counter_fig <- counter_fig + 1
|
|
691 | 696 |
|
692 | 697 |
############################################################## |
693 | 698 |
############## Prepare object to return |
694 | 699 |
############## Collect information from assessment ########## |
695 | 700 |
|
701 |
# #comments |
|
702 |
comments_str <- c("tile processed for the region", |
|
703 |
"boxplot with outlier", |
|
704 |
"boxplot with outlier", |
|
705 |
"boxplot scaling by tiles", |
|
706 |
"boxplot scaling by tiles", |
|
707 |
"boxplot overall region with outliers", |
|
708 |
"boxplot overall region with scaling", |
|
709 |
"Barplot of metrics ranked by tile", |
|
710 |
"Barplot of metrics ranked by tile", |
|
711 |
"Average metrics map centroids", |
|
712 |
"Average metrics map centroids", |
|
713 |
"Number of missing day threshold1 map centroids", |
|
714 |
"Number of missing day threshold1 map centroids", |
|
715 |
"Number of missing day threshold1 map centroids", |
|
716 |
"Number of missing day threshold1 map centroids", |
|
717 |
"number_daily_predictions_per_model", |
|
718 |
"histogram number_daily_predictions_per_models", |
|
719 |
"boxplot overall separated by region with_outliers", |
|
720 |
"boxplot overall separated by region with_scaling") |
|
721 |
|
|
722 |
# c("figure_1","figure_2a","figure_2a","figure_2b","figure_2b","figure_3a","figure_3b","figure_5", |
|
723 |
# "figure_5","figure_6","figure_6", |
|
724 |
# Figure_7a |
|
725 |
# Figure_7a |
|
726 |
#Number of missing day threshold1 map centroids Figure_7a |
|
727 |
#Number of missing day threshold1 map centroids Figure_7a |
|
728 |
#number_daily_predictions_per_model Figure_7b |
|
729 |
#histogram number_daily_predictions_per_models Figure_7c |
|
730 |
#boxplot_overall_separated_by_region_with_oultiers_ Figure 8a |
|
731 |
#boxplot_overall_separated_by_region_with_scaling Figure 8b |
|
732 |
|
|
696 | 733 |
outfiles_names <- c("summary_metrics_v_names","tb_v_accuracy_name","tb_month_s_name","tb_s_accuracy_name", |
697 | 734 |
"data_month_s_name","data_day_v_name","data_day_s_name","data_month_v_name", "tb_month_v_name", |
698 | 735 |
"pred_data_month_info_name","pred_data_day_info_name","df_tile_processed_name","df_tiles_all_name", |
... | ... | |
741 | 778 |
# histogram number_daily_predictions_per_models Figure_7c |
742 | 779 |
# boxplot_overall_separated_by_region_with_oultiers_ Figure 8a |
743 | 780 |
# boxplot_overall_separated_by_region_with_scaling Figure 8b |
781 |
|
|
782 |
# Browse[3]> c |
|
783 |
# Error in text.default(coordinates(pt)[1], coordinates(pt)[2], labels = i, : |
|
784 |
# X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 2 at size 16 could not be loaded |
|
785 |
# In addition: Warning message: |
|
786 |
# In polypath(x = mcrds[, 1], y = mcrds[, 2], border = border, col = col, : |
|
787 |
# Path drawing not available for this device |
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
# Browse[2]> for(i in 1:length(threshold_missing_day)){ |
|
792 |
# + |
|
793 |
# + #summary_metrics_v$n_missing <- summary_metrics_v$n == 365 |
|
794 |
# + #summary_metrics_v$n_missing <- summary_metrics_v$n < 365 |
|
795 |
# + summary_metrics_v$n_missing <- summary_metrics_v$n < threshold_missing_day[i] |
|
796 |
# + summary_metrics_v_subset <- subset(summary_metrics_v,model_name=="mod1") |
|
797 |
# + |
|
798 |
# + #res_pix <- 1200 |
|
799 |
# + res_pix <- 960 |
|
800 |
# + |
|
801 |
# + col_mfrow <- 1 |
|
802 |
# + row_mfrow <- 1 |
|
803 |
# + fig_filename <- paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i], |
|
804 |
# + "_",out_suffix,".png",sep="") |
|
805 |
# + png(filename=paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i], |
|
806 |
# + "_",out_suffix,".png",sep=""), |
|
807 |
# + width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
808 |
# + |
|
809 |
# + model_name[j] |
|
810 |
# + |
|
811 |
# + p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black')) |
|
812 |
# + #title("(a) Mean for 1 January") |
|
813 |
# + p <- bubble(summary_metrics_v_subset,"n_missing",main=paste("Missing per tile and by ",model_name[j]," for ", |
|
814 |
# + threshold_missing_day[i])) |
|
815 |
# + p1 <- p+p_shp |
|
816 |
# + try(print(p1)) #error raised if number of missing values below a threshold does not exist |
|
817 |
# + dev.off() |
|
818 |
# + |
|
819 |
# + list_outfiles[[counter_fig+i]] <- fig_filename |
|
820 |
# + } |
|
821 |
# debug at /nobackupp8/bparmen1/env_layers_scripts/global_run_scalingup_assessment_part2_01042016.R#272: i |
|
822 |
# Browse[3]> counter_fig <- counter_fig+length(threshold_missing_day) #currently 4 days... |
|
823 |
# Browse[3]> c |
|
824 |
# Error in grid.Call.graphics(L_setviewport, pvp, TRUE) : |
|
825 |
# non-finite location and/or size for viewport |
Also available in: Unified diff
plotting assessment figure function, collecting output figures into table