Project

General

Profile

« Previous | Next » 

Revision 2a9f3980

Added by Benoit Parmentier almost 9 years ago

debugging assessment part2 related to figures count and shapefile plotting

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/07/2016            
8
#MODIFIED ON: 02/10/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 
......
179 179

  
180 180
  setwd(out_dir)
181 181
  
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
182
  list_outfiles <- vector("list", length=29) #collect names of output files
183
  list_outfiles_names <- vector("list", length=29) #collect names of output files
184 184
  counter_fig <- 0 #index of figure to collect outputs
185 185
  
186 186
  #i <- year_predicted
......
419 419
    title(paste("RMSE with scaling for all tiles: ",model_name[i],sep=""))
420 420
    dev.off()
421 421
    list_outfiles[[counter_fig+2]] <- paste("Figure3b_boxplot_overall_region_scaling_",model_name[i],"_",out_suffix,".png",sep="")
422
    counter_fig <- counter_fig +2
422 423
  }
423
  counter_fig <- counter_fig + length(model_name)
424
  #counter_fig <- counter_fig + length(model_name)
424 425
  r6 <-c("figure_3a","Boxplot overall accuracy with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[6]])  
425 426
  r7 <-c("figure_3b","Boxplot overall accuracy with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[7]])  
426 427
  r8 <-c("figure_3a","Boxplot overall accuracy with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[8]])
......
429 430
  ################ 
430 431
  ### Figure 4: plot predicted tiff for specific date per model
431 432
  
432
  #y_var_name <-"dailyTmax"
433
  #index <-244 #index corresponding to Sept 1
434
  
435
  # if (mosaic_plot==TRUE){
436
  #   index  <- 1 #index corresponding to Jan 1
437
  #   date_selected <- "20100901"
438
  #   name_method_var <- paste(interpolation_method,"_",y_var_name,"_",sep="")
439
  # 
440
  #   pattern_str <- paste("mosaiced","_",name_method_var,"predicted",".*.",date_selected,".*.tif",sep="")
441
  #   lf_pred_list <- list.files(pattern=pattern_str)
442
  # 
443
  #   for(i in 1:length(lf_pred_list)){
444
  #     
445
  #   
446
  #     r_pred <- raster(lf_pred_list[i])
447
  #   
448
  #     res_pix <- 480
449
  #     col_mfrow <- 1
450
  #     row_mfrow <- 1
451
  #   
452
  #     png(filename=paste("Figure4_models_predicted_surfaces_",model_name[i],"_",name_method_var,"_",data_selected,"_",out_suffix,".png",sep=""),
453
  #        width=col_mfrow*res_pix,height=row_mfrow*res_pix)
454
  #   
455
  #     plot(r_pred)
456
  #     title(paste("Mosaiced",model_name[i],name_method_var,date_selected,sep=" "))
457
  #     dev.off()
458
  #   }
459
  #   #Plot Delta and clim...
460
  # 
461
  #    ## plotting of delta and clim for later scripts...
462
  # 
463
  # }
433
  for(i in 1:length(model_name)){
434
    
435
    tb_subset <- subset(tb,pred_mod==model_name[i])#mod1 is i=1, mod_kr is last
436
    labels <- month.abb # abbreviated names for each month
437
    
438
    ## Figure 4a
439
    fig_filename <- paste("Figure4a_boxplot_overall_accuracy_separated_by_month_with_outliers_",model_name[i],"_",out_suffix,".png",sep="")
440
    png(filename=fig_filename,
441
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
464 442
  
443
    boxplot(rmse~month_no,data=tb_subset,ylab=metric_name,xlab="averaged by month",axes=F)#,names=tb$pred_mod)
444
    axis(1, labels = FALSE)
445
    ## Plot x axis labels at default tick marks
446
    text(1:length(labels), par("usr")[3] - 0.25, srt = 45, adj = 1,cex=0.8,
447
           labels = labels, xpd = TRUE)
448
    axis(2)
449
    box()
450
    title(paste("Overall accuracy for ", model_name[i], " by month for ",region_name,sep=""))
451
    
452
    #p<- bwplot(rmse~year_predicted | reg , data=tb_subset,ylim=c(0,5),
453
             #main="RMSE per model and region over all tiles")
454
    #print(p)
455
    dev.off()
456
    
457
    list_outfiles[[counter_fig+1]] <- fig_filename
458
    counter_fig <- counter_fig + 1
459

  
460
    fig_filename <- paste("Figure4b_boxplot_overall_separated_by_month_scaling_",model_name[i],"_",out_suffix,".png",sep="")
461
    png(filename=fig_filename,
462
      width=col_mfrow*res_pix,height=row_mfrow*res_pix)
463
  
464
    boxplot(rmse~month_no,data=tb_subset,ylim=c(0,5),outline=FALSE,ylab=metric_name,
465
            xlab="averaged by month",axes=F)#,names=tb$pred_mod)
466
    axis(1, labels = FALSE)
467
    ## Plot x axis labels at default tick marks
468
    text(1:length(labels), par("usr")[3] - 0.25, srt = 45, adj = 1,cex=0.8,
469
           labels = labels, xpd = TRUE)
470
    axis(2)
471
    box()
472

  
473
    title(paste("Overall accuracy for ", model_name[i], " by month for ",region_name,sep=""))
474
    #p<- bwplot(rmse~year_predicted | reg , data=tb_subset,ylim=c(0,5),
475
             #main="RMSE per model and region over all tiles")
476
    #print(p)
477
    dev.off()
478

  
479
    list_outfiles[[counter_fig+1]] <- fig_filename
480
    counter_fig <- counter_fig + 1
481
  }
482
  #counter_fig <- counter_fig + length(model_name)
483
  r10 <-c("figure_4a","Boxplot overall accuracy by month with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[10]])  
484
  r11 <-c("figure_4b","Boxplot overall accuracy by month with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[11]])  
485
  r12 <-c("figure_4a","Boxplot overall accuracy by month with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[12]])
486
  r13 <-c("figure_4b","Boxplot overall accuracy by month with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[13]])  
465 487
  
466 488
  ######################
467 489
  ### Figure 5: plot accuracy ranked 
......
490 512
    title(paste("RMSE ranked by tile for ",model_name[i],sep=""))
491 513
    
492 514
    dev.off()
493
    list_outfiles[[counter_fig+i]] <- fig_filename
515
    list_outfiles[[counter_fig+1]] <- fig_filename
516
    counter_fig <- counter_fig + 1
494 517
  }
495 518
  
496
  counter_fig <- counter_fig + length(model_name)
519
  #counter_fig <- counter_fig + length(model_name)
497 520
  
498
  r10 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[8]])
499
  r11 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[9]])  
521
  r14 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[14]])
522
  r15 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[15]])  
500 523

  
501 524
  ######################
502 525
  ### Figure 6: plot map of average RMSE per tile at centroids
......
522 545
    
523 546
    coordinates(ac_mod) <- ac_mod[,c("lon","lat")] 
524 547
    #coordinates(ac_mod) <- ac_mod[,c("lon.x","lat.x")] #solve this later
525
    p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black'))
548
    #p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black'))
549
    p_shp <- spplot(reg_layer,"ISO3" ,col.regions=NA, col="black") #ok problem solved!!
526 550
    #title("(a) Mean for 1 January")
527 551
    p <- bubble(ac_mod,"rmse",main=paste("Average RMSE per tile and by ",model_name[i]))
528 552
    p1 <- p+p_shp
......
535 559
    ### Ranking by tile...
536 560
    #df_ac_mod <- 
537 561
    list_df_ac_mod[[i]] <- arrange(as.data.frame(ac_mod),desc(rmse))[,c("rmse","mae","tile_id")]
538
    list_outfiles[[counter_fig+i]] <- fig_filename
562
    list_outfiles[[counter_fig+1]] <- fig_filename
563
    counter_fig <- counter_fig + 1
564
    #list_outfiles[[counter_fig+i]] <- fig_filename
539 565
  }
540
  counter_fig <- counter_fig+length(model_name)
566
  #counter_fig <- counter_fig+length(model_name)
541 567

  
542
  r12 <-c("figure_6","Average accuracy metrics map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[8]])
543
  r13 <-c("figure_6","Average accuracy metrics map at centroids","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[9]])  
568
  r16 <-c("figure_6","Average accuracy metrics map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[16]])
569
  r17 <-c("figure_6","Average accuracy metrics map at centroids","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[17]])  
544 570

  
545 571
  ######################
546 572
  ### Figure 7: Number of predictions: daily and monthly
......
580 606
    
581 607
    fig_filename <- paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i],
582 608
                       "_",out_suffix,".png",sep="")
583

  
609
    list_outfiles[[counter_fig+i]] <- fig_filename
584 610
    if(sum(summary_metrics_v_subset$n_missing) > 0){#then there are centroids to plot!!!
585 611
      
586 612
      #res_pix <- 1200
......
594 620
    
595 621
      model_name[j]
596 622
    
597
      p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black'))
623
      #p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black'))
624
      p_shp <- spplot(reg_layer,"ISO3" ,col.regions=NA, col="black") #ok problem solved!!
598 625
      #title("(a) Mean for 1 January")
599 626
      p <- bubble(summary_metrics_v_subset,"n_missing",main=paste("Missing per tile and by ",model_name[j]," for ",
600 627
                                                                threshold_missing_day[i]))
......
604 631

  
605 632
    } 
606 633
     
607
    list_outfiles[[counter_fig+i]] <- fig_filename
608 634
  }
609 635
  counter_fig <- counter_fig+length(threshold_missing_day) #currently 4 days...
610 636

  
611
  r14 <-c("figure_7","Number of missing days threshold1 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[8]])
612
  r15 <-c("figure_7","Number of missing days threshold2 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[9]])  
613
  r16 <-c("figure_7","Number of missing days threshold3 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[8]])
614
  r17 <-c("figure_7","Number of missing days threshold4 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[9]])  
637
  r18 <-c("figure_7","Number of missing days threshold1 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[18]])
638
  r19 <-c("figure_7","Number of missing days threshold2 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[19]])  
639
  r20 <-c("figure_7","Number of missing days threshold3 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[20]])
640
  r21 <-c("figure_7","Number of missing days threshold4 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[21]])  
615 641

  
616 642
  ### Potential
617 643
  png(filename=paste("Figure7b_number_daily_predictions_per_models","_",out_suffix,".png",sep=""),
......
623 649
  
624 650
  list_outfiles[[counter_fig+1]] <- paste("Figure7b_number_daily_predictions_per_models","_",out_suffix,".png",sep="")
625 651
  counter_fig <- counter_fig + 1
626
  r18 <-c("figure_7b","Number of daily predictions per_models","mod1",metric_name,region_name,year_predicted,list_outfiles[[9]])  
652
  r22 <-c("figure_7b","Number of daily predictions per_models","mod1",metric_name,region_name,year_predicted,list_outfiles[[22]])  
627 653
  
628 654
  table(tb$pred_mod)
629 655
  table(tb$index_d)
......
651 677
  
652 678
  list_outfiles[[counter_fig+1]] <- paste("Figure7c_histogram_number_daily_predictions_per_models","_",out_suffix,".png",sep="")
653 679
  counter_fig <- counter_fig + 1
654
  r19 <-c("figure_7c","Histogram number daily predictions per models","mod1",metric_name,region_name,year_predicted,list_outfiles[[9]])  
655

  
656
  
657
  #table(tb)
658
  ## Figure 7b
659
  #png(filename=paste("Figure7b_number_daily_predictions_per_models","_",out_suffix,".png",sep=""),
660
  #    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
661
  
662
  #xyplot(n~month | tile_id + pred_mod,data=subset(as.data.frame(tb_month_s),
663
  #                                           pred_mod!="mod_kr"),type="h")
664
  #xyplot(n~month | tile_id,data=subset(as.data.frame(tb_month_s),
665
  #                                           pred_mod="mod_1"),type="h")
666
  #test=subset(as.data.frame(tb_month_s),pred_mod="mod_1")
667
  #table(tb_month_s$month)
668
  #dev.off()
669
  #
680
  r23 <-c("figure_7c","Histogram number daily predictions per models","mod1",metric_name,region_name,year_predicted,list_outfiles[[23]])  
670 681
  
671 682
  ##########################################################
672 683
  ##### Figure 8: Breaking down accuracy by regions!! #####
......
709 720
  counter_fig <- counter_fig + 1
710 721
  
711 722
  
712
  r20 <-c("figure 8a","Boxplot overall accuracy by model separated by region with outliers",NA,metric_name,region_name,year_predicted,list_outfiles[[20]])  
713
  r21 <-c("figure 8b","Boxplot overall accuracy by model separated by region with scaling",NA,metric_name,region_name,year_predicted,list_outfiles[[21]])  
723
  r24 <-c("figure 8a","Boxplot overall accuracy by model separated by region with outliers",NA,metric_name,region_name,year_predicted,list_outfiles[[24]])  
724
  r25 <-c("figure 8b","Boxplot overall accuracy by model separated by region with scaling",NA,metric_name,region_name,year_predicted,list_outfiles[[25]])  
714 725

  
715 726
  #######
716 727
  ##Second, plot for each model separately
......
753 764

  
754 765
  }
755 766
  
756
  r22 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[22]])  
757
  r23 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[23]])  
758
  r24 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[24]])  
759
  r25 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[25]])  
767
  r26 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[26]])  
768
  r27 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[27]])  
769
  r28 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[28]])  
770
  r29 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[29]])  
760 771

  
761 772
  #####################################################
762 773
  #### Figure 9: plotting boxplot by year and regions ###########
......
795 806
  # This is hard coded and can be improved later on for flexibility. It works for now...                                                                 
796 807
  #This data.frame contains all the files from the assessment
797 808

  
798
  #Should have this at the location of the figures!!! will be done later?    
799
  #r1 <-c("figure_1","Tiles processed for the region",NA,NA,region_name,year_predicted,list_outfiles[[1]])
800
  #r2 <-c("figure_2a","Boxplot of accuracy with outliers by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[2]]) 
801
  #r3 <-c("figure_2a","boxplot of accuracy with outliers by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[3]])
802
  #r4 <-c("figure_2b","Boxplot of accuracy with scaling by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[4]])  
803
  #r5 <-c("figure_2b","Boxplot of accuracy with scaling by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[5]])  
804
  #r6 <-c("figure_3a","Boxplot overall accuracy with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[6]])  
805
  #r7 <-c("figure_3b","Boxplot overall accuracy with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[7]])  
806
  #r8 <-c("figure_3a","Boxplot overall accuracy with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[8]])
807
  #r9 <-c("figure_3b","Boxplot overall accuracy with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[9]])  
808
  #r10 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod1",metric_name,region_name,year_predicted,list_outfiles[[10]])
809
  #r11 <-c("figure_5","Barplot of accuracy metrics ranked by tiles","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[11]])  
810
  #r12 <-c("figure_6","Average accuracy metrics map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[12]])
811
  #r13 <-c("figure_6","Average accuracy metrics map at centroids","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[13]])  
812
  #r14 <-c("figure_7","Number of missing days threshold1 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[14]])
813
  #r15 <-c("figure_7","Number of missing days threshold2 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[15]])  
814
  #r16 <-c("figure_7","Number of missing days threshold3 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[16]])
815
  #r17 <-c("figure_7","Number of missing days threshold4 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[17]])  
816
  #r18 <-c("figure_7b","Number of daily predictions per_models","mod1",metric_name,region_name,year_predicted,list_outfiles[[18]])  
817
  #r19 <-c("figure_7c","Histogram number daily predictions per models","mod1",metric_name,region_name,year_predicted,list_outfiles[[19]])  
818
  #r20 <-c("figure 8a","Boxplot overall accuracy by model separated by region with outliers",NA,metric_name,region_name,year_predicted,list_outfiles[[20]])  
819
  #r21 <-c("figure 8b","Boxplot overall accuracy by model separated by region with scaling",NA,metric_name,region_name,year_predicted,list_outfiles[[21]])  
820
  #r22 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod1",metric_name,region_name,year_predicted,list_outfiles[[22]])  
821
  #r23 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod1",metric_name,region_name,year_predicted,list_outfiles[[23]])  
822
  #r24 <-c("figure 8c","Boxplot overall accuracy separated by region with outliers","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[24]])  
823
  #r25 <-c("figure 8d","Boxplot overall accuracy separated by region with scaling","mod_kr",metric_name,region_name,year_predicted,list_outfiles[[25]])  
824

  
825 809
  #Assemble all the figures description and information in a data.frame for later use
826
  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)
810
  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,
811
                   r23,r24,r25,r26,r27,r28,r29)
827 812
  df_assessment_figures_files <- as.data.frame(do.call(rbind,list_rows))
828 813
  names(df_assessment_figures_files) <- c("figure_no","comment","model_name","reg","metric_name","year_predicted","filename")
829 814
  

Also available in: Unified diff