Project

General

Profile

« Previous | Next » 

Revision 35cb7399

Added by Benoit Parmentier almost 9 years ago

more changes to part3 assessment overall figure combined assessment

View differences:

climate/research/oregon/interpolation/global_run_scalingup_assessment_part3.R
6 6
#Analyses, figures, tables and data are also produced in the script.
7 7
#AUTHOR: Benoit Parmentier 
8 8
#CREATED ON: 03/23/2014  
9
#MODIFIED ON: 01/27/2016            
9
#MODIFIED ON: 02/02/2016            
10 10
#Version: 5
11 11
#PROJECT: Environmental Layers project     
12 12
#COMMENTS: Initial commit, script based on part 2 of assessment, will be modified further for overall assessment 
......
50 50
#in_dir <- "" #PARAM 0
51 51
#y_var_name <- "dailyTmax" #PARAM1
52 52
#interpolation_method <- c("gam_CAI") #PARAM2
53
out_suffix<-"global_analyses_overall_assessment_reg4_01272016"
53
out_suffix <- "global_analyses_overall_assessment_reg4_01272016"
54 54
#out_suffix <- "output_run10_1000x3000_global_analyses_02102015"
55 55
#out_suffix <- "run10_1500x4500_global_analyses_pred_1992_10052015" #PARAM3
56 56
#out_dir <- "/data/project/layers/commons/NEX_data/output_run10_1500x4500_global_analyses_pred_1992_10052015" #PARAM4
......
183 183

  
184 184
  setwd(out_dir)
185 185
  
186
  list_outfiles <- vector("list", length=23) #collect names of output files
186
  list_outfiles <- vector("list", length=23) #collect names of output files, this should be dynamic?
187 187
  list_outfiles_names <- vector("list", length=23) #collect names of output files
188 188
  counter_fig <- 0 #index of figure to collect outputs
189 189
  
......
195 195
  list_tb_fname <- list.files(path=file.path(in_dir,in_dir_list),"tb_diagnostic_v_NA_.*._run_global_analyses_pred_.*._reg4.txt",full.names=T)
196 196
  list_df_fname <- list.files(path=file.path(in_dir,in_dir_list),"df_tile_processed_.*._run_global_analyses_pred_.*._reg4.txt",full.names=T)
197 197
  list_summary_metrics_v_fname <- list.files(path=file.path(in_dir,in_dir_list),"summary_metrics_v2_NA_.*._run_global_analyses_pred_.*._reg4.txt",full.names=T)
198
  #need to fix this !! has all of the files in one list (for a region)
199
  #list_shp <- list.files(path=file.path(in_dir,file.path(in_dir_list,"shapefiles")),"*.shp",full.names=T)
198 200

  
199
  
200 201
  list_tb <- lapply(list_tb_fname,function(x){read.table(x,stringsAsFactors=F,sep=",")})
201 202
  tb <- do.call(rbind,list_tb)
202 203
  list_df <- lapply(list_df_fname,function(x){read.table(x,stringsAsFactors=F,sep=",")})
203 204
  df_tile_processed <- do.call(rbind,list_df)  
204 205
  list_summary_metrics_v <- lapply(list_summary_metrics_v_fname,function(x){read.table(x,stringsAsFactors=F,sep=",")})
205 206
  summary_metrics_v <- do.call(rbind,list_summary_metrics_v)  
207
  ##Stop added
206 208
  
207 209
  tb <-  read.table(list_tb[1],stringsAsFactors=F,sep=",")
208 210
  
......
242 244
  try(tb$reg <- tb$reg.x)
243 245
  try(summary_metrics_v$year_predicted <- summary_metrics_v$year_predicted.x)
244 246
  try(summary_metrics_v$reg <- summary_metrics_v$reg.x)  
247
  try(summary_metrics_v$lat <- summary_metrics_v$lat.x)
248
  try(summary_metrics_v$lon <- summary_metrics_v$lon.x)
249
  #summary_metrics_v
245 250
  #tb_all <- tb
246 251
  #summary_metrics_v_all <- summary_metrics_v 
247 252
  
......
257 262
  
258 263
  #df_tiled_processed <- na.omit(df_tile_processed) #remove other list of folders irrelevant
259 264
  #list_shp_reg_files <- df_tiled_processed$shp_files
260
  list_shp_reg_files<- as.character(df_tile_processed$shp_files)
265
  
266
  #list_shp_reg_files<- as.character(df_tile_processed$shp_files) #this could be the solution!!
267
  list_shp_reg_files <- as.character(basename(list_df[[1]]$shp_files)) #this could be the solution!!
268
  #the shapefiles must be copied in the proper folder!!!
269
  #list_shp_reg_files<- file.path(in_dir,in_dir_list[1],"shapefile",list_shp_reg_files)
261 270
  #list_shp_reg_files <- file.path("/data/project/layers/commons/NEX_data/",out_dir,
262 271
  #          as.character(df_tile_processed$tile_coord),"shapefiles",basename(list_shp_reg_files))
263 272
  #list_shp_reg_files <- file.path("/data/project/layers/commons/NEX_data/",out_dir,
......
620 629
  
621 630
  table(tb$pred_mod)
622 631
  table(tb$index_d)
623
  table(subset(tb,pred_mod!="mod_kr"))
632
  #table(subset(tb,pred_mod!="mod_kr"))
624 633
  table(subset(tb,pred_mod=="mod1")$index_d)
625 634
  #aggregate()
626 635
  tb$predicted <- 1
627 636
  test <- aggregate(predicted~pred_mod+tile_id,data=tb,sum)
628
  xyplot(predicted~pred_mod | tile_id,data=subset(as.data.frame(test),
629
                                                  pred_mod!="mod_kr"),type="h")
637
  #xyplot(predicted~pred_mod | tile_id,data=subset(as.data.frame(test),
638
  #                                                pred_mod!="mod_kr"),type="h")
630 639
  
631 640
  as.character(unique(test$tile_id)) #141 tiles
632 641
  
......
663 672
  ##### Figure 8: Breaking down accuracy by regions!! #####
664 673
  
665 674
  #summary_metrics_v <- merge(summary_metrics_v,df_tile_processed,by="tile_id")
675
  ##First plot with all models together
666 676
  
667 677
  ## Figure 8a
668 678
  res_pix <- 480
......
673 683
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
674 684
  
675 685
  p<- bwplot(rmse~pred_mod | reg, data=tb,
676
             main="RMSE per model and region over all tiles")
686
             main="RMSE per model and region over all tiles with outliers")
677 687
  print(p)
678 688
  dev.off()
679 689
  
......
684 694
  png(filename=paste("Figure8b_boxplot_overall_separated_by_region_scaling_","_",out_suffix,".png",sep=""),
685 695
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
686 696
  
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")
697
  #boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod)
698
  #title("RMSE per model over all tiles")
689 699
  p<- bwplot(rmse~pred_mod | reg, data=tb,ylim=c(0,5),
690
             main="RMSE per model and region over all tiles")
700
             main="RMSE per model and region over all tiles with scaling")
691 701
  print(p)
692 702
  dev.off()
693 703
  
694 704
  list_outfiles[[counter_fig+1]] <- paste("Figure8b_boxplot_overall_separated_by_region_scaling_",model_name[i],"_",out_suffix,".png",sep="")
695 705
  counter_fig <- counter_fig + 1
696 706
  
697
  ## Select mod1 only now
698
  tb_subset <- subset(tb,model_name=="mod1")
699
  ## Figure 8c
707
  ##Second, plot for each model separately
700 708
  
701
  res_pix <- 480
702
  col_mfrow <- 1
703
  row_mfrow <- 1
709
  for(i in 1:length(model_name)){
710
    
711
    tb_subset <- subset(tb,pred_mod==model_name[i])#mod1 is i=1, mod_kr is last
712
    ## Figure 8c
704 713
  
705
  png(filename=paste("Figure8c_boxplot_overall_separated_by_region_with_oultiers_","mod1","_",out_suffix,".png",sep=""),
714
    res_pix <- 480
715
    col_mfrow <- 1
716
    row_mfrow <- 1
717
  
718
    fig_filename <- paste("Figure8c_boxplot_overall_separated_by_region_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="")
719
    png(filename=fig_filename,
706 720
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
707 721
  
708
  p<- bwplot(rmse~pred_mod | reg, data=tb_subset,
709
             main="RMSE per model and region over all tiles")
710
  print(p)
711
  dev.off()
722
    p<- bwplot(rmse~pred_mod | reg, data=tb_subset,
723
             main="RMSE per model and region over all tiles with outliers")
724
    print(p)
725
    dev.off()
712 726
  
713
  list_outfiles[[counter_fig+1]] <- paste("Figure8c_boxplot_overall_separated_by_region_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="")
714
  counter_fig <- counter_fig + 1
727
    list_outfiles[[counter_fig+1]] <- fig_filename
728
    counter_fig <- counter_fig + 1
715 729
  
716
  ## Figure 8d
717
  png(filename=paste("Figure8d_boxplot_overall_separated_by_region_scaling_","mod1","_",out_suffix,".png",sep=""),
730
    ## Figure 8d
731
    fig_filename <- paste("Figure8d_boxplot_overall_separated_by_region_scaling_",model_name[i],"_",out_suffix,".png",sep="")
732
    png(filename=fig_filename,
718 733
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
719 734
  
720
  boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod)
721
  title("RMSE per model over all tiles")
722
  p<- bwplot(rmse~pred_mod | reg, data=tb_subset,ylim=c(0,5),
723
             main="RMSE per model and region over all tiles")
724
  print(p)
725
  dev.off()
735
    #boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod)
736
    #title("RMSE per model over all tiles")
737
    p<- bwplot(rmse~pred_mod | reg, data=tb_subset,ylim=c(0,5),
738
             main="RMSE per model and region over all tiles with scaling")
739
    print(p)
740
    dev.off()
726 741
  
727
  list_outfiles[[counter_fig+1]] <- paste("Figure8d_boxplot_overall_separated_by_region_scaling_",model_name[i],"_",out_suffix,".png",sep="")
728
  counter_fig <- counter_fig + 1
742
    list_outfiles[[counter_fig+1]] <- fig_filename
743
    counter_fig <- counter_fig + 1
744

  
745
  }
746
 
729 747

  
730 748
  #####################################################
731 749
  #### Figure 9: plotting boxplot by year and regions ###########
......
734 752
  res_pix <- 480
735 753
  col_mfrow <- 1
736 754
  row_mfrow <- 1
737
  
755

  
738 756
  png(filename=paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep=""),
739 757
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
740
  
741
  p<- bwplot(rmse~pred_mod | reg + year_predicted, data=tb,
742
             main="RMSE per model and region over all tiles")
758
  #This will need to be changed, the layout is difficult at this stage 
759
  #p<- bwplot(rmse~pred_mod + reg + year_predicted, data=tb,
760
  #           main="RMSE per model and region over all tiles")
743 761
  p<- bwplot(rmse~pred_mod | reg + year_predicted, data=tb,
744 762
             main="RMSE per model and region over all tiles")
745 763
  print(p)
......
749 767
  png(filename=paste("Figure8b_boxplot_overall_separated_by_region_year_scaling_",model_name[i],"_",out_suffix,".png",sep=""),
750 768
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
751 769
  
752
  boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod)
753
  title("RMSE per model over all tiles")
770
  #boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod)
771
  #title("RMSE per model over all tiles")
754 772
  p<- bwplot(rmse~pred_mod | reg + year_predicted, data=tb,ylim=c(0,5),
755 773
             main="RMSE per model and region over all tiles")
756 774
  print(p)

Also available in: Unified diff