Project

General

Profile

« Previous | Next » 

Revision 47fc2e4d

Added by Benoit Parmentier almost 9 years ago

more changes to part2 assessment figure 2 production to clean up and record figures produced

View differences:

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: 02/01/2016            
8
#MODIFIED ON: 02/03/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
  year_predicted <- list_param_run_assessment_plotting$year_predicted
165 165
 
166 166
  NA_value <- NA_flag_val 
167

  
167
  metric_name <- "rmse" #to be added to the code later...
168
  
168 169
  ##################### START SCRIPT #################
169 170
  
170 171
  ####### PART 1: Read in data ########
......
178 179

  
179 180
  setwd(out_dir)
180 181
  
181
  list_outfiles <- vector("list", length=23) #collect names of output files
182
  list_outfiles_names <- vector("list", length=23) #collect names of output files
182
  list_outfiles <- vector("list", length=25) #collect names of output files
183
  list_outfiles_names <- vector("list", length=25) #collect names of output files
183 184
  counter_fig <- 0 #index of figure to collect outputs
184 185
  
185 186
  #i <- year_predicted
......
329 330
  #unique(summaty_metrics$tile_id)
330 331
  #text(lat-shp,)
331 332
  #union(list_shp_reg_files[[1]],list_shp_reg_files[[2]])
333
  #Row used in constructing output table...
334

  
332 335
  list_outfiles[[counter_fig+1]] <- paste("Figure1_tile_processed_region_",region_name,"_",out_suffix,".png",sep="")
333 336
  counter_fig <- counter_fig+1
337
  #this will be changed to be added to data.frame on the fly
338
  r1 <-c("figure_1","Tiles processed for the region",NA,NA,region_name,year_predicted,list_outfiles[[1]]) 
334 339
  
335 340
  ###############
336 341
  ### Figure 2: boxplot of average accuracy by model and by tiles
......
355 360
    list_outfiles[[counter_fig+i]] <- fig_filename
356 361
  }
357 362
  counter_fig <- counter_fig + length(model_name)
363
  
364
  r2 <-c("figure_2a","Boxplot of accuracy with outliers by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[2]]) 
365
  r3 <-c("figure_2a","boxplot of accuracy with outliers by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[3]])
366
  
358 367
  ## Figure 2b
359 368
  #with ylim and removing trailing...
360 369
  for(i in  1:length(model_name)){ #there are two models!!
......
376 385
  }
377 386
  counter_fig <- counter_fig + length(model_name)
378 387
  #bwplot(rmse~tile_id, data=subset(tb,tb$pred_mod=="mod1"))
379
 
388
  r4 <-c("figure_2b","Boxplot of accuracy with scaling by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[4]])  
389
  r5 <-c("figure_2b","Boxplot of accuracy with scaling by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[5]])  
390

  
380 391
  ###############
381 392
  ### Figure 3: boxplot of average RMSE by model acrosss all tiles
382 393
  
......
407 418
    list_outfiles[[counter_fig+2]] <- paste("Figure3b_boxplot_overall_region_scaling_",model_name[i],"_",out_suffix,".png",sep="")
408 419
  }
409 420
  counter_fig <- counter_fig + length(model_name)
421
  r6 <-c("figure_3a","Boxplot overall accuracy with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[6]])  
422
  r7 <-c("figure_3b","Boxplot overall accuracy with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[7]])  
423
  r8 <-c("figure_3a","Boxplot overall accuracy with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[8]])
424
  r9 <-c("figure_3b","Boxplot overall accuracy with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[9]])  
410 425

  
411 426
  ################ 
412 427
  ### Figure 4: plot predicted tiff for specific date per model
......
476 491
  }
477 492
  
478 493
  counter_fig <- counter_fig + length(model_name)
494
  
495
  r10 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[8]])
496
  r11 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[9]])  
479 497

  
480 498
  ######################
481 499
  ### Figure 6: plot map of average RMSE per tile at centroids
......
483 501
  ### Without 
484 502
  
485 503
  #list_df_ac_mod <- vector("list",length=length(lf_pred_list))
486
  list_df_ac_mod <- vector("list",length=2)
504
  list_df_ac_mod <- vector("list",length=length(model_name))
487 505
  
488 506
  for (i in 1:length(model_name)){
489 507
    
......
518 536
  }
519 537
  counter_fig <- counter_fig+length(model_name)
520 538

  
521
  
539
  r12 <-c("figure_6","Average accuracy metrics map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[8]])
540
  r13 <-c("figure_6","Average accuracy metrics map at centroids","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[9]])  
541

  
522 542
  ######################
523 543
  ### Figure 7: Number of predictions: daily and monthly
524 544
  
......
547 567
   #Error in grid.Call.graphics(L_setviewport, pvp, TRUE) : 
548 568
  #non-finite location and/or size for viewport
549 569

  
550
  j<-1 #for model name 1
570
  j<-1 #for model name 1,mod1
551 571
  for(i in 1:length(threshold_missing_day)){
552 572
    
553 573
    #summary_metrics_v$n_missing <- summary_metrics_v$n == 365
......
564 584
      res_pix <- 960
565 585
      col_mfrow <- 1
566 586
      row_mfrow <- 1
587
      #only mod1 right now
567 588
      png(filename=paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i],
568 589
                       "_",out_suffix,".png",sep=""),
569 590
        width=col_mfrow*res_pix,height=row_mfrow*res_pix)
......
584 605
  }
585 606
  counter_fig <- counter_fig+length(threshold_missing_day) #currently 4 days...
586 607

  
608
  r14 <-c("figure_7","Number of missing days threshold1 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[8]])
609
  r15 <-c("figure_7","Number of missing days threshold2 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[9]])  
610
  r16 <-c("figure_7","Number of missing days threshold3 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[8]])
611
  r17 <-c("figure_7","Number of missing days threshold4 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[9]])  
612

  
587 613
  ### Potential
588 614
  png(filename=paste("Figure7b_number_daily_predictions_per_models","_",out_suffix,".png",sep=""),
589 615
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
......
594 620
  
595 621
  list_outfiles[[counter_fig+1]] <- paste("Figure7b_number_daily_predictions_per_models","_",out_suffix,".png",sep="")
596 622
  counter_fig <- counter_fig + 1
623
  r18 <-c("figure_7b","Number of daily predictions per_models","mod1",metric_name,region_name,year_predicted,list_outfiles[[9]])  
597 624
  
598 625
  table(tb$pred_mod)
599 626
  table(tb$index_d)
......
621 648
  
622 649
  list_outfiles[[counter_fig+1]] <- paste("Figure7c_histogram_number_daily_predictions_per_models","_",out_suffix,".png",sep="")
623 650
  counter_fig <- counter_fig + 1
651
  r19 <-c("figure_7c","Histogram number daily predictions per models","mod1",metric_name,region_name,year_predicted,list_outfiles[[9]])  
624 652

  
653
  
625 654
  #table(tb)
626 655
  ## Figure 7b
627 656
  #png(filename=paste("Figure7b_number_daily_predictions_per_models","_",out_suffix,".png",sep=""),
......
640 669
  ##### Figure 8: Breaking down accuracy by regions!! #####
641 670
  
642 671
  #summary_metrics_v <- merge(summary_metrics_v,df_tile_processed,by="tile_id")
672
  
673
  ##################
643 674
  ##First plot with all models together
644 675
  
645 676
  ## Figure 8a
......
655 686
  print(p)
656 687
  dev.off()
657 688
  
658
  list_outfiles[[counter_fig+1]] <- paste("Figure8a_boxplot_overall_separated_by_region_with_oultiers_",out_suffix,".png",sep="")
689
  list_outfiles[[counter_fig+1]] <- paste("Figure8a_boxplot_overall_accuracy_by_model_separated_by_region_with_oultiers_",out_suffix,".png",sep="")
659 690
  counter_fig <- counter_fig + 1
660 691
  
661 692
  ## Figure 8b
......
669 700
  print(p)
670 701
  dev.off()
671 702
  
672
  list_outfiles[[counter_fig+1]] <- paste("Figure8b_boxplot_overall_separated_by_region_scaling_",model_name[i],"_",out_suffix,".png",sep="")
703
  list_outfiles[[counter_fig+1]] <- paste("Figure8b_boxplot_overall_accuracy_by_model_separated_by_region_scaling_",out_suffix,".png",sep="")
673 704
  counter_fig <- counter_fig + 1
674 705
  
706
  
707
  r20 <-c("figure 8a","Boxplot overall accuracy by model separated by region with outliers",NA,metric_name,region_name,year_predicted,list_outfiles[[20]])  
708
  r21 <-c("figure 8b","Boxplot overall accuracy by model separated by region with scaling",NA,metric_name,region_name,year_predicted,list_outfiles[[21]])  
709

  
710
  #######
675 711
  ##Second, plot for each model separately
676 712
  
677 713
  for(i in 1:length(model_name)){
......
683 719
    col_mfrow <- 1
684 720
    row_mfrow <- 1
685 721
  
686
    fig_filename <- paste("Figure8c_boxplot_overall_separated_by_region_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="")
722
    fig_filename <- paste("Figure8c_boxplot_overall_accuracy_separated_by_region_with_outliers_",model_name[i],"_",out_suffix,".png",sep="")
687 723
    png(filename=fig_filename,
688 724
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
689 725
  
......
696 732
    counter_fig <- counter_fig + 1
697 733
  
698 734
    ## Figure 8d
699
    fig_filename <- paste("Figure8d_boxplot_overall_separated_by_region_scaling_",model_name[i],"_",out_suffix,".png",sep="")
735
    fig_filename <- paste("Figure8d_boxplot_overall_accuracy_separated_by_region_scaling_",model_name[i],"_",out_suffix,".png",sep="")
700 736
    png(filename=fig_filename,
701 737
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
702 738
  
......
711 747
    counter_fig <- counter_fig + 1
712 748

  
713 749
  }
714
 
750
  
751
  r22 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[20]])  
752
  r23 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[21]])  
753
  r24 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[20]])  
754
  r25 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[21]])  
755

  
715 756
  #####################################################
716 757
  #### Figure 9: plotting boxplot by year and regions ###########
717 758
  
......
747 788
  ############## Collect information from assessment ##########
748 789
  
749 790
  # This is hard coded and can be improved later on for flexibility. It works for now...                                                                 
750
  comments_str <- 
751
c("tile processed for the region",
752
  "boxplot with outliers",                                                          
753
  "boxplot with outliers",
754
  "boxplot scaling by tiles",
755
  "boxplot scaling by tiles",
756
  "boxplot overall region with outliers",
757
  "boxplot overall region with scaling",
758
  "boxplot overall region with outliers",
759
  "boxplot overall region with scaling",
760
  "Barplot of accuracy metrics ranked by tile",
761
  "Barplot of accuracy metrics ranked by tile",
762
  "Average accuracy metrics map at centroids",
763
  "Average accuracy metrics map at centroids",
764
  "Number of missing day threshold1 map centroids",
765
  "Number of missing day threshold2 map centroids",
766
  "Number of missing day threshold3 map centroids",
767
  "Number of missing day threshold4 map centroids",
768
  "number_daily_predictions_per_model",
769
  "histogram number_daily_predictions_per_models",
770
  "boxplot overall separated by region with_outliers",
771
  "boxplot overall separated by region with_scaling",
772
  "boxplot overall separated by region with_outliers",
773
  "boxplot overall separated by region with_scaling")
791
  #This data.frame contains all the files from the assessment
774 792

  
775
                                            model_name=col_model_name,
776
                                            reg=col_reg,
777
                                            year_predicted=col_year_predicted,
778
                                            filename=unlist(list_outfiles))
779
    comments_str <- 
780 793
  #Should have this at the location of the figures!!! will be done later?    
781
  r1 <-c("figure_1","tile processed for the region",NA,region_name,year_predicted,list_outfiles[[1]])
782
  r2 <-c("figure_2a","boxplot with outliers","mod1",region_name,year_predicted,list_outfiles[[2]])  
783
  r3 <-c("figure_2a","boxplot scaling by tiles","mod_kr",region_name,year_predicted,list_outfiles[[3]])  
784
  r4 <-c("figure_2b","boxplot scaling by tiles","mod1",region_name,year_predicted,list_outfiles[[4]])  
785
  r5 <-c("figure_2b","boxplot scaling by tiles","mod_kr",region_name,year_predicted,list_outfiles[[5]])  
786
  r6 <-c("figure_3a","boxplot scaling by tiles","mod1",region_name,year_predicted,list_outfiles[[6]])  
787
  r7 <-c("figure_3b","boxplot scaling by tiles","mod1",region_name,year_predicted,list_outfiles[[7]])  
788
  r8 <-c("figure_3a","boxplot scaling by tiles","mod_kr",region_name,year_predicted,list_outfiles[[8]])
789
  r9 <-c("figure_3b","boxplot scaling by tiles","mod_kr",region_name,year_predicted,list_outfiles[[9]])  
790

  
791
  NA,"mod1","mod_kr","mod1","mod_kr","mod1","mod_1","mod_kr","mod_kr",
792

  
793
  
794
  c("tile processed for the region",
795
  "boxplot with outliers",                                                          
796
  "boxplot with outliers",
797
  "boxplot scaling by tiles",
798
  "boxplot scaling by tiles",
799
  "boxplot overall region with outliers",
800
  "boxplot overall region with scaling",
801
  "boxplot overall region with outliers",
802
  "boxplot overall region with scaling",
803
  "Barplot of accuracy metrics ranked by tile",
804
  "Barplot of accuracy metrics ranked by tile",
805
  "Average accuracy metrics map at centroids",
806
  "Average accuracy metrics map at centroids",
807
  "Number of missing day threshold1 map centroids",
808
  "Number of missing day threshold2 map centroids",
809
  "Number of missing day threshold3 map centroids",
810
  "Number of missing day threshold4 map centroids",
811
  "number_daily_predictions_per_model",
812
  "histogram number_daily_predictions_per_models",
813
  "boxplot overall separated by region with_outliers",
814
  "boxplot overall separated by region with_scaling",
815
  "boxplot overall separated by region with_outliers",
816
  "boxplot overall separated by region with_scaling")
817

  
818

  
819
  figure_no <- c("figure_1","figure_2a","figure_2a","figure_2b","figure_2b","figure_3a","figure_3b","figure_3a","figure_3b",
820
                 "figure_5", "figure_5","figure_6","figure_6","Figure_7a","Figure_7a","Figure_7a","Figure_7a","Figure_7b",
821
                 "Figure_7c","Figure 8a","Figure 8b","Figure 8c","Figure 8d","Figure 8c","Figure 8d")
822

  
823
  col_model_name <- c(NA,"mod1","mod_kr","mod1","mod_kr","mod1","mod_1","mod_kr","mod_kr",
824
                      "mod1","mod_kr","mod1","mod_kr","mod1","mod1","mod1","mod1",NA,
825
                      NA,NA,NA,"mod1","mod1","mod_kr","mod_kr")
826
  
827
-rw-r--r-- 1 parmentier layers  14441 Feb  2 16:06 Figure2a_boxplot_with_oultiers_by_tiles_mod1_global_analyses_overall_assessment_reg4_01272016.png
828
-rw-r--r-- 1 parmentier layers  13617 Feb  2 16:06 Figure2a_boxplot_with_oultiers_by_tiles_mod_kr_global_analyses_overall_assessment_reg4_01272016.png
829
-rw-r--r-- 1 parmentier layers   9638 Feb  2 16:07 Figure2b_boxplot_scaling_by_tiles_mod1_global_analyses_overall_assessment_reg4_01272016.png
830
-rw-r--r-- 1 parmentier layers   9606 Feb  2 16:07 Figure2b_boxplot_scaling_by_tiles_mod_kr_global_analyses_overall_assessment_reg4_01272016.png
831
-rw-r--r-- 1 parmentier layers   4925 Feb  2 16:07 Figure3a_boxplot_overall_region_with_oultiers_mod1_global_analyses_overall_assessment_reg4_01272016.png
832
-rw-r--r-- 1 parmentier layers   4527 Feb  2 16:07 Figure3b_boxplot_overall_region_scaling_mod1_global_analyses_overall_assessment_reg4_01272016.png
833
-rw-r--r-- 1 parmentier layers   5193 Feb  2 16:07 Figure3a_boxplot_overall_region_with_oultiers_mod_kr_global_analyses_overall_assessment_reg4_01272016.png
834
-rw-r--r-- 1 parmentier layers   4522 Feb  2 16:07 Figure3b_boxplot_overall_region_scaling_mod_kr_global_analyses_overall_assessment_reg4_01272016.png
835
-rw-r--r-- 1 parmentier layers   6079 Feb  2 16:07 Figure5_ac_metrics_ranked_mod1_global_analyses_overall_assessment_reg4_01272016.png
836
-rw-r--r-- 1 parmentier layers   6251 Feb  2 16:07 Figure5_ac_metrics_ranked_mod_kr_global_analyses_overall_assessment_reg4_01272016.png
837
-rw-r--r-- 1 parmentier layers 120492 Feb  2 16:08 Figure6_ac_metrics_map_centroids_tile_mod1_global_analyses_overall_assessment_reg4_01272016.png
838
-rw-r--r-- 1 parmentier layers 120345 Feb  2 16:08 Figure6_ac_metrics_map_centroids_tile_mod_kr_global_analyses_overall_assessment_reg4_01272016.png
839
-rw-r--r-- 1 parmentier layers  88938 Feb  2 16:09 Figure7a_ac_metrics_map_centroids_tile_mod1_missing_day_367_global_analyses_overall_assessment_reg4_01272016.png
840
-rw-r--r-- 1 parmentier layers  89437 Feb  2 16:09 Figure7a_ac_metrics_map_centroids_tile_mod1_missing_day_365_global_analyses_overall_assessment_reg4_01272016.png
841
-rw-r--r-- 1 parmentier layers  89284 Feb  2 16:10 Figure7a_ac_metrics_map_centroids_tile_mod1_missing_day_300_global_analyses_overall_assessment_reg4_01272016.png
842
-rw-r--r-- 1 parmentier layers  32506 Feb  2 16:10 Figure7b_number_daily_predictions_per_models_global_analyses_overall_assessment_reg4_01272016.png
843
-rw-r--r-- 1 parmentier layers  13970 Feb  2 16:10 Figure7c_histogram_number_daily_predictions_per_models_global_analyses_overall_assessment_reg4_01272016.png
844
-rw-r--r-- 1 parmentier layers  12726 Feb  2 16:11 Figure8a_boxplot_overall_separated_by_region_with_oultiers__global_analyses_overall_assessment_reg4_01272016.png
845
-rw-r--r-- 1 parmentier layers  12061 Feb  2 16:11 Figure8b_boxplot_overall_separated_by_region_scaling__global_analyses_overall_assessment_reg4_01272016.png
846
-rw-r--r-- 1 parmentier layers  10851 Feb  2 16:11 Figure8c_boxplot_overall_separated_by_region_with_oultiers_mod1_global_analyses_overall_assessment_reg4_01272016.png
847
-rw-r--r-- 1 parmentier layers   9814 Feb  2 16:11 Figure8d_boxplot_overall_separated_by_region_scaling_mod1_global_analyses_overall_assessment_reg4_01272016.png
848
-rw-r--r-- 1 parmentier layers  11599 Feb  2 16:11 Figure8c_boxplot_overall_separated_by_region_with_oultiers_mod_kr_global_analyses_overall_assessment_reg4_01272016.png
849
-rw-r--r-- 1 parmentier layers   9597 Feb  2 16:11 Figure8d_boxplot_overall_separated_by_region_scaling_mod_kr_global_analyses_overall_assessment_reg4_01272016.png
850

  
851
  
852
  col_reg <- rep(region_name,length(list_outfiles))
853
  col_year_predicted <- rep(year_predicted,length(list_outfiles))
854
  
855
  #This data.frame contains all the files from the assessment
856
  df_assessment_figures_files <- data.frame(figure_no=figure_no,
857
                                            comment = comments_str,
858
                                            model_name=col_model_name,
859
                                            reg=col_reg,
860
                                            year_predicted=col_year_predicted,
861
                                            filename=unlist(list_outfiles))
794
  #r1 <-c("figure_1","Tiles processed for the region",NA,NA,region_name,year_predicted,list_outfiles[[1]])
795
  #r2 <-c("figure_2a","Boxplot of accuracy with outliers by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[2]]) 
796
  #r3 <-c("figure_2a","boxplot of accuracy with outliers by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[3]])
797
  #r4 <-c("figure_2b","Boxplot of accuracy with scaling by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[4]])  
798
  #r5 <-c("figure_2b","Boxplot of accuracy with scaling by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[5]])  
799
  #r6 <-c("figure_3a","Boxplot overall accuracy with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[6]])  
800
  #r7 <-c("figure_3b","Boxplot overall accuracy with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[7]])  
801
  #r8 <-c("figure_3a","Boxplot overall accuracy with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[8]])
802
  #r9 <-c("figure_3b","Boxplot overall accuracy with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[9]])  
803
  #r10 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[10]])
804
  #r11 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[11]])  
805
  #r12 <-c("figure_6","Average accuracy metrics map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[12]])
806
  #r13 <-c("figure_6","Average accuracy metrics map at centroids","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[13]])  
807
  #r14 <-c("figure_7","Number of missing days threshold1 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[14]])
808
  #r15 <-c("figure_7","Number of missing days threshold2 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[15]])  
809
  #r16 <-c("figure_7","Number of missing days threshold3 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[16]])
810
  #r17 <-c("figure_7","Number of missing days threshold4 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[17]])  
811
  #r18 <-c("figure_7b","Number of daily predictions per_models","mod1",metric_name,region_name,year_predicted,list_outfiles[[18]])  
812
  #r19 <-c("figure_7c","Histogram number daily predictions per models","mod1",metric_name,region_name,year_predicted,list_outfiles[[19]])  
813
  #r20 <-c("figure 8a","Boxplot overall accuracy by model separated by region with outliers",NA,metric_name,region_name,year_predicted,list_outfiles[[20]])  
814
  #r21 <-c("figure 8b","Boxplot overall accuracy by model separated by region with scaling",NA,metric_name,region_name,year_predicted,list_outfiles[[21]])  
815
  #r22 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[22]])  
816
  #r23 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[23]])  
817
  #r24 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[24]])  
818
  #r25 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[25]])  
819

  
820
  #Assemble all the figures description and information in a data.frame for later use
821
  list_rows <-list(r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25)
822
  df_assessment_figures_files <- as.data.frame(do.call(rbind,list_rows))
823
  names(df_assessment_figures_files) <- c("figure_no","comment","model_name","reg","metric_name","year_predicted","filename")
862 824
  
863 825
  ###Prepare files for copying back?
864 826
  df_assessment_figures_files_names <- file.path(out_dir,paste("df_assessment_figures_files_",region_name,"_",year_predicted,"_",out_suffix,".txt",sep=""))
......
888 850

  
889 851
#CALLED FROM MASTER SCRIPT:
890 852

  
891
script_path <- "/nobackupp8/bparmen1/env_layers_scripts" #path to script
892
function_assessment_part1_functions <- "global_run_scalingup_assessment_part1_functions_02112015.R" #PARAM12
893
function_assessment_part1a <-"global_run_scalingup_assessment_part1a_01042016.R"
894
function_assessment_part2 <- "global_run_scalingup_assessment_part2_01062016.R"
895
function_assessment_part2_functions <- "global_run_scalingup_assessment_part2_functions_01032016.R"
896
source(file.path(script_path,function_assessment_part1_functions)) #source all functions used in this script 
897
source(file.path(script_path,function_assessment_part1a)) #source all functions used in this script 
898
source(file.path(script_path,function_assessment_part2)) #source all functions used in this script 
899
source(file.path(script_path,function_assessment_part2_functions)) #source all functions used in this script 
900

  
901
### Parameters and arguments ###
902
  
903
var<-"TMAX" # variable being interpolated
904
if (var == "TMAX") {
905
  y_var_name <- "dailyTmax"
906
  y_var_month <- "TMax"
907
}
908
if (var == "TMIN") {
909
  y_var_name <- "dailyTmin"
910
  y_var_month <- "TMin"
911
}
912

  
913
#interpolation_method<-c("gam_fusion") #other otpions to be added later
914
interpolation_method<-c("gam_CAI")
915
CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs";
916
#CRS_interp <-"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs";
917
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
918

  
919
out_region_name<-""
920
list_models<-c("y_var ~ s(lat,lon,k=5) + s(elev_s,k=3) + s(LST,k=3)")
921

  
922
#reg1 (North Am), reg2(Europe),reg3(Asia), reg4 (South Am), reg5 (Africa), reg6 (Australia-Asia)
923
#master directory containing the definition of tile size and tiles predicted
924
in_dir1 <- "/nobackupp6/aguzman4/climateLayers/out/"
925
#/nobackupp6/aguzman4/climateLayers/out_15x45/1982
926

  
927
#region_names <- c("reg23","reg4") #selected region names, #PARAM2
928
region_name <- c("reg4") #run assessment by region, this is a unique region only
929
#region_names <- c("reg1","reg2","reg3","reg4","reg5","reg6") #selected region names, #PARAM2
930
interpolation_method <- c("gam_CAI") #PARAM4
931
out_prefix <- "run_global_analyses_pred_12282015" #PARAM5
932
#out_dir <- "/nobackupp8/bparmen1/" #PARAM6
933
out_dir <- "/nobackupp8/bparmen1/output_run_global_analyses_pred_12282015"
934
#out_dir <-paste(out_dir,"_",out_prefix,sep="")
935
create_out_dir_param <- FALSE #PARAM7
936

  
937
#CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs";
938
#CRS_interp <-"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs";
939
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
940

  
941
#list_year_predicted <- 1984:2004
942
list_year_predicted <- c("2014")
943
#year_predicted <- list_year_predicted[1]
944

  
945
file_format <- ".tif" #format for mosaiced files #PARAM10
946
NA_flag_val <- -9999  #No data value, #PARAM11
947
num_cores <- 6 #number of cores used #PARAM13
948
plotting_figures <- TRUE #running part2 of assessment to generate figures...
949
  
950
##Additional parameters used in part 2, some these may be removed as code is simplified
951
mosaic_plot <- FALSE #PARAM14
952
day_to_mosaic <- c("19920102","19920103","19920103") #PARAM15
953
multiple_region <- TRUE #PARAM16
954
countries_shp <- "/nobackupp8/bparmen1/NEX_data/countries.shp" #PARAM17
955
#countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp" #Atlas
956
plot_region <- TRUE  #PARAM18
957
threshold_missing_day <- c(367,365,300,200)#PARAM19
958

  
959
year_predicted <- list_year_predicted[1]
960
in_dir <- out_dir #PARAM 0
961
#y_var_name <- "dailyTmax" #PARAM1 , already set
962
#interpolation_method <- c("gam_CAI") #PARAM2, already set
963
out_suffix <- out_prefix #PARAM3
964
#out_dir <-  #PARAM4, already set
965
create_out_dir_param <- FALSE #PARAM 5, already created and set
966
#mosaic_plot <- FALSE #PARAM6
967
#if daily mosaics NULL then mosaicas all days of the year
968
#day_to_mosaic <- c("19920101","19920102","19920103") #PARAM7
969
#CRS_locs_WGS84 already set
970
proj_str <- CRS_locs_WGS84 #PARAM 8 #check this parameter
971
#file_format <- ".rst" #PARAM 9, already set
972
#NA_flag_val <- -9999 #PARAM 11, already set
973
#multiple_region <- TRUE #PARAM 12
974
#countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp" #PARAM 13, copy this on NEX too
975
#plot_region <- TRUE
976
#num_cores <- 6 #PARAM 14, already set
977
#region_name <- c("reg4") #reference region to merge if necessary, if world all the regions are together #PARAM 16
978
#use previous files produced in step 1a and stored in a data.frame
979
df_assessment_files_name <- "df_assessment_files_reg4_2014_run_global_analyses_pred_12282015.txt"# #PARAM 17, set in the script
980
df_assessment_files <- read.table(df_assessment_files_name,stringsAsFactors=F,sep=",")
981
#threshold_missing_day <- c(367,365,300,200) #PARM18
982

  
983
list_param_run_assessment_plotting <-list(
984
    in_dir,y_var_name, interpolation_method, out_suffix,
985
    out_dir, create_out_dir_param, mosaic_plot, proj_str, file_format, NA_flag_val,
986
    multiple_region, countries_shp, plot_region, num_cores,
987
    region_name, df_assessment_files_name, threshold_missing_day,year_predicted
988
  )
989

  
990
names(list_param_run_assessment_plotting) <- c(
991
    "in_dir","y_var_name","interpolation_method","out_suffix",
992
    "out_dir","create_out_dir_param","mosaic_plot","proj_str","file_format","NA_flag_val",
993
    "multiple_region","countries_shp","plot_region","num_cores",
994
    "region_name","df_assessment_files_name","threshold_missing_day","year_predicted"
995
  )
996

  
997
#function_assessment_part2 <- "global_run_scalingup_assessment_part2_01032016.R"
998
#source(file.path(script_path,function_assessment_part2)) #source all functions used in this script
999

  
1000
debug(run_assessment_plotting_prediction_fun)
1001
df_assessment_figures_files <-
1002
  run_assessment_plotting_prediction_fun(list_param_run_assessment_plotting)
1003

  
1004

  
1005

  
1006

  
1007

  
1008

  
1009

  
1010

  
1011

  
1012

  
1013

  
1014

  
1015

  
1016

  
1017

  
1018

  
1019

  
1020

  
1021

  
1022

  
1023

  
1024

  
1025

  
1026

  
1027

  
1028

  
1029

  
1030

  
1031

  
1032

  
1033

  
1034

  
1035
#### CURRENT ERROR ON NEX
1036

  
1037
# #comments                                                                     #figure_no    #region   #models       
1038
# tile processed for the region                                           figure_1           reg4        NA
1039
# boxplot with outlier                                                        figure_2a          reg4        mod1
1040
# boxplot with outlier                                                        figure_2a          reg4        mod_kr
1041
# boxplot scaling by tiles                                                   figure_2b          reg4        mod1
1042
# boxplot scaling by tiles                                                   figure_2b          reg4        mod_kr
1043
# boxplot overall region with outliers                              figure_3a          reg4        NA
1044
# boxplot overall region with scaling                               figure_3b          reg4        NA
1045
# Barplot of metrics ranked by tile                                  Figure_5            
1046
# boxplot overall region with scaling                               figure_3b          reg4        NA
1047
# Barplot of metrics ranked by tile                                  Figure_5            
1048
# Barplot of metrics ranked by tile                                  Figure_5
1049
# Average metrics map centroids                                  Figure_6
1050
# Average metrics map centroids                                  Figure_6
1051
# Number of missing day threshold1 map centroids                                    Figure_7a
1052
# Number of missing day threshold1 map centroids                                    Figure_7a
1053
# Number of missing day threshold1 map centroids                                    Figure_7a
1054
# Number of missing day threshold1 map centroids                                    Figure_7a
1055
# number_daily_predictions_per_model                                                        Figure_7b
1056
# histogram number_daily_predictions_per_models                                    Figure_7c
1057
# boxplot_overall_separated_by_region_with_oultiers_                              Figure 8a
1058
# boxplot_overall_separated_by_region_with_scaling                                 Figure 8b
1059

  
1060
# Browse[3]> c
1061
# Error in text.default(coordinates(pt)[1], coordinates(pt)[2], labels = i,  : 
1062
#                         X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 2 at size 16 could not be loaded
1063
#                       In addition: Warning message:
1064
#                         In polypath(x = mcrds[, 1], y = mcrds[, 2], border = border, col = col,  :
1065
#                                       Path drawing not available for this device
853
# script_path <- "/nobackupp8/bparmen1/env_layers_scripts" #path to script
854
# function_assessment_part1_functions <- "global_run_scalingup_assessment_part1_functions_02112015.R" #PARAM12
855
# function_assessment_part1a <-"global_run_scalingup_assessment_part1a_01042016.R"
856
# function_assessment_part2 <- "global_run_scalingup_assessment_part2_01062016.R"
857
# function_assessment_part2_functions <- "global_run_scalingup_assessment_part2_functions_01032016.R"
858
# source(file.path(script_path,function_assessment_part1_functions)) #source all functions used in this script 
859
# source(file.path(script_path,function_assessment_part1a)) #source all functions used in this script 
860
# source(file.path(script_path,function_assessment_part2)) #source all functions used in this script 
861
# source(file.path(script_path,function_assessment_part2_functions)) #source all functions used in this script 
862
# 
863
# ### Parameters and arguments ###
864
#   
865
# var<-"TMAX" # variable being interpolated
866
# if (var == "TMAX") {
867
#   y_var_name <- "dailyTmax"
868
#   y_var_month <- "TMax"
869
# }
870
# if (var == "TMIN") {
871
#   y_var_name <- "dailyTmin"
872
#   y_var_month <- "TMin"
873
# }
874
# 
875
# #interpolation_method<-c("gam_fusion") #other otpions to be added later
876
# interpolation_method<-c("gam_CAI")
877
# CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs";
878
# #CRS_interp <-"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs";
879
# CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
880
# 
881
# out_region_name<-""
882
# list_models<-c("y_var ~ s(lat,lon,k=5) + s(elev_s,k=3) + s(LST,k=3)")
883
# 
884
# #reg1 (North Am), reg2(Europe),reg3(Asia), reg4 (South Am), reg5 (Africa), reg6 (Australia-Asia)
885
# #master directory containing the definition of tile size and tiles predicted
886
# in_dir1 <- "/nobackupp6/aguzman4/climateLayers/out/"
887
# #/nobackupp6/aguzman4/climateLayers/out_15x45/1982
888
# 
889
# #region_names <- c("reg23","reg4") #selected region names, #PARAM2
890
# region_name <- c("reg4") #run assessment by region, this is a unique region only
891
# #region_names <- c("reg1","reg2","reg3","reg4","reg5","reg6") #selected region names, #PARAM2
892
# interpolation_method <- c("gam_CAI") #PARAM4
893
# out_prefix <- "run_global_analyses_pred_12282015" #PARAM5
894
# #out_dir <- "/nobackupp8/bparmen1/" #PARAM6
895
# out_dir <- "/nobackupp8/bparmen1/output_run_global_analyses_pred_12282015"
896
# #out_dir <-paste(out_dir,"_",out_prefix,sep="")
897
# create_out_dir_param <- FALSE #PARAM7
898
# 
899
# #CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs";
900
# #CRS_interp <-"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs";
901
# CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
902
# 
903
# #list_year_predicted <- 1984:2004
904
# list_year_predicted <- c("2014")
905
# #year_predicted <- list_year_predicted[1]
906
# 
907
# file_format <- ".tif" #format for mosaiced files #PARAM10
908
# NA_flag_val <- -9999  #No data value, #PARAM11
909
# num_cores <- 6 #number of cores used #PARAM13
910
# plotting_figures <- TRUE #running part2 of assessment to generate figures...
911
#   
912
# ##Additional parameters used in part 2, some these may be removed as code is simplified
913
# mosaic_plot <- FALSE #PARAM14
914
# day_to_mosaic <- c("19920102","19920103","19920103") #PARAM15
915
# multiple_region <- TRUE #PARAM16
916
# countries_shp <- "/nobackupp8/bparmen1/NEX_data/countries.shp" #PARAM17
917
# #countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp" #Atlas
918
# plot_region <- TRUE  #PARAM18
919
# threshold_missing_day <- c(367,365,300,200)#PARAM19
920
# 
921
# year_predicted <- list_year_predicted[1]
922
# in_dir <- out_dir #PARAM 0
923
# #y_var_name <- "dailyTmax" #PARAM1 , already set
924
# #interpolation_method <- c("gam_CAI") #PARAM2, already set
925
# out_suffix <- out_prefix #PARAM3
926
# #out_dir <-  #PARAM4, already set
927
# create_out_dir_param <- FALSE #PARAM 5, already created and set
928
# #mosaic_plot <- FALSE #PARAM6
929
# #if daily mosaics NULL then mosaicas all days of the year
930
# #day_to_mosaic <- c("19920101","19920102","19920103") #PARAM7
931
# #CRS_locs_WGS84 already set
932
# proj_str <- CRS_locs_WGS84 #PARAM 8 #check this parameter
933
# #file_format <- ".rst" #PARAM 9, already set
934
# #NA_flag_val <- -9999 #PARAM 11, already set
935
# #multiple_region <- TRUE #PARAM 12
936
# #countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp" #PARAM 13, copy this on NEX too
937
# #plot_region <- TRUE
938
# #num_cores <- 6 #PARAM 14, already set
939
# #region_name <- c("reg4") #reference region to merge if necessary, if world all the regions are together #PARAM 16
940
# #use previous files produced in step 1a and stored in a data.frame
941
# df_assessment_files_name <- "df_assessment_files_reg4_2014_run_global_analyses_pred_12282015.txt"# #PARAM 17, set in the script
942
# df_assessment_files <- read.table(df_assessment_files_name,stringsAsFactors=F,sep=",")
943
# #threshold_missing_day <- c(367,365,300,200) #PARM18
944
# 
945
# list_param_run_assessment_plotting <-list(
946
#     in_dir,y_var_name, interpolation_method, out_suffix,
947
#     out_dir, create_out_dir_param, mosaic_plot, proj_str, file_format, NA_flag_val,
948
#     multiple_region, countries_shp, plot_region, num_cores,
949
#     region_name, df_assessment_files_name, threshold_missing_day,year_predicted
950
#   )
951
# 
952
# names(list_param_run_assessment_plotting) <- c(
953
#     "in_dir","y_var_name","interpolation_method","out_suffix",
954
#     "out_dir","create_out_dir_param","mosaic_plot","proj_str","file_format","NA_flag_val",
955
#     "multiple_region","countries_shp","plot_region","num_cores",
956
#     "region_name","df_assessment_files_name","threshold_missing_day","year_predicted"
957
#   )
958
# 
959
# #function_assessment_part2 <- "global_run_scalingup_assessment_part2_01032016.R"
960
# #source(file.path(script_path,function_assessment_part2)) #source all functions used in this script
961
# 
962
# debug(run_assessment_plotting_prediction_fun)
963
# df_assessment_figures_files <-
964
#   run_assessment_plotting_prediction_fun(list_param_run_assessment_plotting)
1066 965

  
1067 966

  
1068 967

  
1069
# Browse[2]>   for(i in 1:length(threshold_missing_day)){
1070
# +     
1071
# +     #summary_metrics_v$n_missing <- summary_metrics_v$n == 365
1072
# +     #summary_metrics_v$n_missing <- summary_metrics_v$n < 365
1073
# +     summary_metrics_v$n_missing <- summary_metrics_v$n < threshold_missing_day[i]
1074
# +     summary_metrics_v_subset <- subset(summary_metrics_v,model_name=="mod1")
1075
# +     
1076
# +     #res_pix <- 1200
1077
# +     res_pix <- 960
1078
# +     
1079
# +     col_mfrow <- 1
1080
# +     row_mfrow <- 1
1081
# +     fig_filename <- paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i],
1082
# +                        "_",out_suffix,".png",sep="")
1083
# +     png(filename=paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i],
1084
# +                        "_",out_suffix,".png",sep=""),
1085
# +         width=col_mfrow*res_pix,height=row_mfrow*res_pix)
1086
# +     
1087
# +     model_name[j]
1088
# +     
1089
# +     p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black'))
1090
# +     #title("(a) Mean for 1 January")
1091
# +     p <- bubble(summary_metrics_v_subset,"n_missing",main=paste("Missing per tile and by ",model_name[j]," for ",
1092
# +                                                                 threshold_missing_day[i]))
1093
# +     p1 <- p+p_shp
1094
# +     try(print(p1)) #error raised if number of missing values below a threshold does not exist
1095
# +     dev.off()
1096
# +     
1097
# +     list_outfiles[[counter_fig+i]] <- fig_filename
1098
# +   }
1099
# debug at /nobackupp8/bparmen1/env_layers_scripts/global_run_scalingup_assessment_part2_01042016.R#272: i
1100
# Browse[3]>   counter_fig <- counter_fig+length(threshold_missing_day) #currently 4 days...
1101
# Browse[3]> c
1102
# Error in grid.Call.graphics(L_setviewport, pvp, TRUE) : 
1103
#   non-finite location and/or size for viewport

Also available in: Unified diff