Revision f682ea83
Added by Benoit Parmentier over 8 years ago
climate/research/oregon/interpolation/global_run_scalingup_assessment_part5.R | ||
---|---|---|
283 | 283 |
stat_val <- c(std_dev_val,mean_val,median_val,max_val,min_val,n_val) |
284 | 284 |
df_stat <- data.frame(stat_name=stat_name,stat_val=stat_val) |
285 | 285 |
|
286 |
threshol_val <- c(5,6,10) |
|
287 |
n_threshold_val <- sum((tb_subset[[metric_name]]) > threshol_val[1]) |
|
286 |
threshold_val <- c(5,6,10)
|
|
287 |
n_threshold_val <- sum((tb_subset[[metric_name]]) > threshold_val[1])
|
|
288 | 288 |
100*n_threshold_val/n_val |
289 | 289 |
|
290 |
n_threshold_val <- sum((tb_subset[[metric_name]]) > threshol_val[2]) |
|
290 |
n_threshold_val <- sum((tb_subset[[metric_name]]) > threshold_val[2])
|
|
291 | 291 |
100*n_threshold_val/n_val |
292 | 292 |
|
293 |
n_threshold_val <- sum((tb_subset[[metric_name]]) > threshol_val[3]) |
|
293 |
n_threshold_val <- sum((tb_subset[[metric_name]]) > threshold_val[3])
|
|
294 | 294 |
100*n_threshold_val/n_val |
295 | 295 |
|
296 | 296 |
#Find out where these values are located...by mapping extremes! |
297 | 297 |
|
298 | 298 |
|
299 | 299 |
|
300 |
|
|
301 |
|
|
302 |
|
|
303 | 300 |
########################### |
304 | 301 |
### Figure 1: plot location of the study area with tiles processed |
305 | 302 |
|
... | ... | |
408 | 405 |
r1 <-c("figure_1","Tiles processed for the region",NA,NA,region_name,year_predicted,list_outfiles[[1]]) |
409 | 406 |
|
410 | 407 |
|
408 |
###################### |
|
409 |
### Figure 2: Number of predictions: daily and monthly |
|
410 |
|
|
411 |
## Figure 2a |
|
412 |
|
|
413 |
#Plot location of extremes and select them for further analyses? |
|
414 |
|
|
415 |
|
|
416 |
## Number of tiles with information: |
|
417 |
sum(df_tile_processed$metrics_v) #26,number of tiles with raster object |
|
418 |
length(df_tile_processed$metrics_v) #26,number of tiles in the region |
|
419 |
sum(df_tile_processed$metrics_v)/length(df_tile_processed$metrics_v) #80 of tiles with info |
|
420 |
|
|
421 |
#coordinates |
|
422 |
try(coordinates(summary_metrics_v) <- c("lon","lat")) |
|
423 |
#try(coordinates(summary_metrics_v) <- c("lon.y","lat.y")) |
|
424 |
|
|
425 |
#threshold_missing_day <- c(367,365,300,200) |
|
426 |
|
|
427 |
nb<-nrow(subset(summary_metrics_v,model_name=="mod1")) |
|
428 |
sum(subset(summary_metrics_v,model_name=="mod1")$n_missing)/nb #33/35 |
|
429 |
|
|
430 |
|
|
431 |
j<-1 #for model name 1,mod1 |
|
432 |
model_name <- c("mod1","mod_kr") |
|
433 |
for(i in 1:length(threshold_val)){ |
|
434 |
|
|
435 |
|
|
436 |
tb_subset <- subset(tb_subset,tb_subset[[metric_name]]>threshold_val[i]) |
|
437 |
|
|
438 |
df_extremes <- as.data.frame(table(tb_subset$tile_id)) |
|
439 |
names(df_extremes)<- c("tile_id","freq_extremes") |
|
440 |
tb_sorted <- merge(tb_subset,df_extremes,"tile_id") |
|
441 |
tb_sorted <- arrange(tb_sorted,desc(freq_extremes)) #[,c("pred_mod","rmse","mae","tile_id")] |
|
442 |
coordinates(tb_sorted) <- c("lon","lat") |
|
443 |
|
|
444 |
fig_filename <- paste("Figure2a_barplot_extremes_val_centroids_tile_",model_name[j],"_",threshold_val[i], |
|
445 |
"_",out_suffix,".png",sep="") |
|
446 |
|
|
447 |
barplot(table(tb_subset$tile_id),main=paste("Extremes threshold val for ",threshold_val[i],sep=""), |
|
448 |
ylab="frequency",xlab="tile_id",las=2) |
|
449 |
dev.off() |
|
450 |
|
|
451 |
test<-(subset(tb,tb$tile_id==unique(tb_subset$tile_id))) |
|
452 |
#df_ac_mod <- arrange(as.data.frame(ac_mod),desc(rmse))[,c("pred_mod","rmse","mae","tile_id")] |
|
453 |
|
|
454 |
#plot top three, then all,and histogram...make this a function... |
|
455 |
list_df_ac_mod[[i]] <- arrange(as.data.frame(ac_mod),desc(rmse))[,c("rmse","mae","tile_id")] |
|
456 |
|
|
457 |
#summary_metrics_v$n_missing <- summary_metrics_v$n == 365 |
|
458 |
#summary_metrics_v$n_missing <- summary_metrics_v$n < 365 |
|
459 |
#summary_metrics_v$n_missing <- as.numeric(summary_metrics_v$n < threshold_missing_day[i]) |
|
460 |
#summary_metrics_v_subset <- subset(summary_metrics_v,model_name=="mod1") |
|
461 |
|
|
462 |
fig_filename <- paste("Figure7a_ac_metrics_extremes_map_centroids_tile_",model_name[j],"_",threshold_val[i], |
|
463 |
"_",out_suffix,".png",sep="") |
|
464 |
list_outfiles[[counter_fig+i]] <- fig_filename |
|
465 |
|
|
466 |
if(sum(summary_metrics_v_subset$n_missing) > 0){#then there are centroids to plot!!! |
|
467 |
|
|
468 |
#res_pix <- 1200 |
|
469 |
res_pix <- 960 |
|
470 |
col_mfrow <- 1 |
|
471 |
row_mfrow <- 1 |
|
472 |
#only mod1 right now |
|
473 |
png(filename=paste("Figure7a_ac_metrics_map_centroids_tile_",model_name[j],"_","missing_day_",threshold_missing_day[i], |
|
474 |
"_",out_suffix,".png",sep=""), |
|
475 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
476 |
|
|
477 |
model_name[j] |
|
478 |
|
|
479 |
#p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black')) |
|
480 |
p_shp <- spplot(reg_layer,"ISO3" ,col.regions=NA, col="black") #ok problem solved!! |
|
481 |
#title("(a) Mean for 1 January") |
|
482 |
p <- bubble(tb_sorted,"freq_extremes",main=paste("Extremes per tile and by ",model_name[j]," for ", |
|
483 |
threshold_val[i])) |
|
484 |
p1 <- p+p_shp |
|
485 |
try(print(p1)) #error raised if number of missing values below a threshold does not exist |
|
486 |
dev.off() |
|
487 |
|
|
488 |
} |
|
489 |
|
|
490 |
#list_outfiles[[counter_fig+i]] <- fig_filename |
|
491 |
} |
|
492 |
counter_fig <- counter_fig+length(threshold_missing_day) #currently 4 days... |
|
493 |
|
|
494 |
r18 <-c("figure_7","Number of missing days threshold1 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[18]]) |
|
495 |
r19 <-c("figure_7","Number of missing days threshold2 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[19]]) |
|
496 |
r20 <-c("figure_7","Number of missing days threshold3 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[20]]) |
|
497 |
r21 <-c("figure_7","Number of missing days threshold4 map at centroids","mod1",metric_name,region_name,year_predicted,list_outfiles[[21]]) |
|
498 |
|
|
411 | 499 |
###################################################### |
412 | 500 |
##### Prepare objet to return #### |
413 | 501 |
|
Also available in: Unified diff
analyses of extreme values, part 5 assessment script adding section for missing values