Revision e62bc941
Added by Benoit Parmentier almost 9 years ago
climate/research/oregon/interpolation/global_run_scalingup_assessment_part3.R | ||
---|---|---|
330 | 330 |
for(i in 1:length(shps_tiles)){ |
331 | 331 |
shp1 <- shps_tiles[[i]] |
332 | 332 |
pt <- centroids_pts[[i]] |
333 |
#if(!inherits(shp1,"try-error")){ |
|
334 |
# plot(shp1,add=T,border="blue") |
|
335 |
# #plot(pt,add=T,cex=2,pch=5) |
|
336 |
# label_id <- df_tile_processed$tile_id[i] |
|
337 |
# text(coordinates(pt)[1],coordinates(pt)[2],labels=i,cex=1.3,font=2,col=c("red")) |
|
338 |
#} |
|
339 |
#to be able to run on NEX set font and usePolypath, maybe add option NEX? |
|
333 | 340 |
if(!inherits(shp1,"try-error")){ |
334 |
plot(shp1,add=T,border="blue")
|
|
341 |
plot(shp1,add=T,border="blue",usePolypath = FALSE) #added usePolypath following error on brige and NEX
|
|
335 | 342 |
#plot(pt,add=T,cex=2,pch=5) |
336 | 343 |
label_id <- df_tile_processed$tile_id[i] |
337 |
text(coordinates(pt)[1],coordinates(pt)[2],labels=i,cex=1.3,font=2,col=c("red")) |
|
344 |
text(coordinates(pt)[1],coordinates(pt)[2],labels=i,cex=1.3,font=2,col=c("red"),family="HersheySerif")
|
|
338 | 345 |
} |
346 |
|
|
339 | 347 |
} |
340 | 348 |
#title(paste("Tiles ", tile_size,region_name,sep="")) |
341 | 349 |
|
... | ... | |
567 | 575 |
|
568 | 576 |
#summary_metrics_v$n_missing <- summary_metrics_v$n == 365 |
569 | 577 |
#summary_metrics_v$n_missing <- summary_metrics_v$n < 365 |
570 |
summary_metrics_v$n_missing <- summary_metrics_v$n < threshold_missing_day[i]
|
|
578 |
summary_metrics_v$n_missing <- as.numeric(summary_metrics_v$n < threshold_missing_day[i])
|
|
571 | 579 |
summary_metrics_v_subset <- subset(summary_metrics_v,model_name=="mod1") |
572 | 580 |
|
573 |
#res_pix <- 1200 |
|
574 |
res_pix <- 960 |
|
575 |
|
|
576 |
col_mfrow <- 1 |
|
577 |
row_mfrow <- 1 |
|
578 | 581 |
fig_filename <- paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i], |
579 | 582 |
"_",out_suffix,".png",sep="") |
580 |
png(filename=paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i], |
|
583 |
|
|
584 |
if(sum(summary_metrics_v_subset$n_missing) > 0){#then there are centroids to plot!!! |
|
585 |
|
|
586 |
#res_pix <- 1200 |
|
587 |
res_pix <- 960 |
|
588 |
col_mfrow <- 1 |
|
589 |
row_mfrow <- 1 |
|
590 |
png(filename=paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i], |
|
581 | 591 |
"_",out_suffix,".png",sep=""), |
582 | 592 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
583 | 593 |
|
584 |
model_name[j] |
|
594 |
model_name[j]
|
|
585 | 595 |
|
586 |
p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black')) |
|
587 |
#title("(a) Mean for 1 January") |
|
588 |
p <- bubble(summary_metrics_v_subset,"n_missing",main=paste("Missing per tile and by ",model_name[j]," for ", |
|
596 |
p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black'))
|
|
597 |
#title("(a) Mean for 1 January")
|
|
598 |
p <- bubble(summary_metrics_v_subset,"n_missing",main=paste("Missing per tile and by ",model_name[j]," for ",
|
|
589 | 599 |
threshold_missing_day[i])) |
590 |
p1 <- p+p_shp |
|
591 |
try(print(p1)) #error raised if number of missing values below a threshold does not exist |
|
592 |
dev.off() |
|
593 |
|
|
600 |
p1 <- p+p_shp |
|
601 |
try(print(p1)) #error raised if number of missing values below a threshold does not exist |
|
602 |
dev.off() |
|
603 |
|
|
604 |
} |
|
605 |
|
|
594 | 606 |
list_outfiles[[counter_fig+i]] <- fig_filename |
595 | 607 |
} |
596 | 608 |
counter_fig <- counter_fig+length(threshold_missing_day) #currently 4 days... |
... | ... | |
718 | 730 |
##################################################### |
719 | 731 |
#### Figure 9: plotting boxplot by year and regions ########### |
720 | 732 |
|
721 |
#Ok fixed..now selection of model but should also offer an option for using both models!! so make this a function!! |
|
722 |
for(i in 1:length(model_name)){ #there are two models!! |
|
733 |
## Figure 9a |
|
734 |
res_pix <- 480 |
|
735 |
col_mfrow <- 1 |
|
736 |
row_mfrow <- 1 |
|
737 |
|
|
738 |
png(filename=paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep=""), |
|
739 |
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") |
|
743 |
p<- bwplot(rmse~pred_mod | reg + year_predicted, data=tb, |
|
744 |
main="RMSE per model and region over all tiles") |
|
745 |
print(p) |
|
746 |
dev.off() |
|
747 |
|
|
748 |
## Figure 9b |
|
749 |
png(filename=paste("Figure8b_boxplot_overall_separated_by_region_year_scaling_",model_name[i],"_",out_suffix,".png",sep=""), |
|
750 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
751 |
|
|
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") |
|
754 |
p<- bwplot(rmse~pred_mod | reg + year_predicted, data=tb,ylim=c(0,5), |
|
755 |
main="RMSE per model and region over all tiles") |
|
756 |
print(p) |
|
757 |
dev.off() |
|
723 | 758 |
|
724 |
## Figure 9a |
|
725 |
res_pix <- 480 |
|
726 |
col_mfrow <- 1 |
|
727 |
row_mfrow <- 1 |
|
728 |
|
|
729 |
png(filename=paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep=""), |
|
730 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
731 |
|
|
732 |
#p<- bwplot(rmse~pred_mod | reg + year_predicted, data=tb, |
|
733 |
# main="RMSE per model and region over all tiles") |
|
734 |
#p<- bwplot(rmse~year_predicted | reg , subset(tb,tb$pred_mod==model_name[i]), |
|
735 |
#main="RMSE per model and region over all tiles") |
|
736 |
#p<- bwplot(rmse~year_predicted , subset(tb,tb$pred_mod==model_name[i]), |
|
737 |
# main="RMSE per model and region over all tiles") |
|
738 |
boxplot(rmse~year_predicted , subset(tb,tb$pred_mod==model_name[i])) |
|
739 |
title(paste("RMSE with outliers and by year for all tiles: ",model_name[i],sep="")) |
|
740 |
#print(p) |
|
741 |
dev.off() |
|
742 |
|
|
743 |
## Figure 9b |
|
744 |
png(filename=paste("Figure9b_boxplot_overall_separated_by_region_year_scaling_",model_name[i],"_",out_suffix,".png",sep=""), |
|
745 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
746 |
|
|
747 |
#boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod) |
|
748 |
#title("RMSE per model over all tiles") |
|
749 |
#p<- bwplot(rmse~pred_mod | reg + year_predicted, data=tb,ylim=c(0,5), |
|
750 |
# main="RMSE per model and region over all tiles") |
|
751 |
boxplot(rmse~year_predicted,subset(tb,tb$pred_mod==model_name[i]),ylim=c(0,5),outline=FALSE) |
|
752 |
title(paste("RMSE with scaling and by year for all tiles: ",model_name[i],sep="")) |
|
759 |
list_outfiles[[counter_fig+1]] <- paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="") |
|
760 |
counter_fig <- counter_fig + 1 |
|
753 | 761 |
|
754 |
#print(p) |
|
755 |
dev.off() |
|
756 |
|
|
757 |
list_outfiles[[counter_fig+1]] <- paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep="") |
|
758 |
counter_fig <- counter_fig + 1 |
|
759 |
} |
|
760 | 762 |
############################################################## |
761 | 763 |
############## Prepare object to return |
762 | 764 |
############## Collect information from assessment ########## |
... | ... | |
1044 | 1046 |
# Browse[3]> c |
1045 | 1047 |
# Error in grid.Call.graphics(L_setviewport, pvp, TRUE) : |
1046 | 1048 |
# non-finite location and/or size for viewport |
1049 |
#Error in grid.Call.graphics(L_setviewport, vp, TRUE) : |
|
1050 |
# non-finite location and/or size for viewport |
Also available in: Unified diff
debugging of figures and adding figure 9 to produce yearly comparison of RMSE