Revision e8db2a0f
Added by Benoit Parmentier about 8 years ago
climate/research/oregon/interpolation/global_product_assessment_part0_functions.R | ||
---|---|---|
262 | 262 |
list_tiles_predicted_masked <- list_param$list_tiles_predicted_masked |
263 | 263 |
df_missing_tiles_day <- list_param$df_missing_tiles_day |
264 | 264 |
r_overlap_m <- list_param$r_overlap_m |
265 |
item_no <- list_param$item_no |
|
265 | 266 |
num_cores <- list_param$num_cores # 6 #PARAM 14 |
266 | 267 |
region_name <- list_param$region_name #<- "world" #PARAM 15 |
267 | 268 |
NA_flag_val <-list_param$NA_flag_val |
... | ... | |
363 | 364 |
in_dir1 <- list_param$in_dir1 |
364 | 365 |
region_name <- list_param$region_name #e.g. c("reg23","reg4") #run only for one region |
365 | 366 |
y_var_name <- list_param$y_var_name # e.g. dailyTmax" #PARAM3 |
366 |
interpolation_method <- list_param_run_assessment_prediction$interpolation_method #c("gam_CAI") #PARAM4
|
|
367 |
out_suffix <- list_param_run$out_suffix #output suffix e.g."run_global_analyses_pred_12282015" #PARAM5
|
|
367 |
interpolation_method <- list_param$interpolation_method #c("gam_CAI") #PARAM4 |
|
368 |
out_suffix <- list_param$out_suffix #output suffix e.g."run_global_analyses_pred_12282015" #PARAM5 |
|
368 | 369 |
out_dir <- list_param$out_dir #<- "/nobackupp8/bparmen1/" #PARAM6 |
369 | 370 |
create_out_dir_param <-list_param$create_out_dir_param #if TRUE output dir created #PARAM7 |
370 | 371 |
proj_str <- list_param$proj_str # CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84, #PARAM8 |
... | ... | |
376 | 377 |
|
377 | 378 |
##for plotting assessment function |
378 | 379 |
|
379 |
item_no <- list_param_run_assessment_prediction$mosaic_plot #PARAM14
|
|
380 |
item_no <- list_param$item_no #PARAM14
|
|
380 | 381 |
day_to_mosaic_range <- list_param$day_to_mosaic_range #PARAM15 |
381 | 382 |
countries_shp <- list_param$countries_shp #PARAM17 |
382 | 383 |
plotting_figures <- list_param$plotting_figures #PARAM18 |
... | ... | |
384 | 385 |
pred_mod_name <- list_param$pred_mod_name |
385 | 386 |
metric_name <- list_param$metric_name |
386 | 387 |
|
388 |
year_predicted <- list_param$list_year_predicted[i] #selected year |
|
389 |
|
|
387 | 390 |
########################## START SCRIPT ######################################### |
388 | 391 |
|
389 |
#system("ls /nobackup/bparmen1")
|
|
392 |
#system("ls /nobackup/bparmen1" |
|
390 | 393 |
out_dir <- in_dir |
391 | 394 |
if(create_out_dir_param==TRUE){ |
392 | 395 |
out_dir <- create_dir_fun(out_dir,out_suffix) |
... | ... | |
400 | 403 |
#list_outfiles <- vector("list", length=35) #collect names of output files, this should be dynamic? |
401 | 404 |
#list_outfiles_names <- vector("list", length=35) #collect names of output files |
402 | 405 |
|
403 |
year_predicted <- list_param_run_assessment_prediction$list_year_predicted[i] |
|
404 |
|
|
405 | 406 |
in_dir1_reg <- file.path(in_dir1,region_name) |
406 | 407 |
|
407 | 408 |
list_outfiles <- vector("list", length=14) #collect names of output files |
... | ... | |
475 | 476 |
#gam_CAI_dailyTmax_predicted_mod1_0_1_20001231_30_1-39.7_165.1.tif |
476 | 477 |
|
477 | 478 |
#undebug(check_missing) |
479 |
|
|
478 | 480 |
test_missing <- try(lapply(1:length(list_lf_raster_tif_tiles),function(i){check_missing(lf=list_lf_raster_tif_tiles[[i]], |
479 | 481 |
pattern_str=NULL, |
480 | 482 |
in_dir=out_dir, |
... | ... | |
486 | 488 |
out_dir=".")})) |
487 | 489 |
|
488 | 490 |
|
491 |
#test_missing <- try(lapply(1:1,function(i){check_missing(lf=list_lf_raster_tif_tiles[[i]], |
|
492 |
# pattern_str=NULL, |
|
493 |
# in_dir=out_dir, |
|
494 |
# date_start=start_date, |
|
495 |
# date_end=end_date, |
|
496 |
# item_no=item_no, #9 for predicted tiles |
|
497 |
# out_suffix=out_suffix, |
|
498 |
# num_cores=num_cores, |
|
499 |
# out_dir=".")})) |
|
500 |
|
|
501 |
#browser() |
|
502 |
|
|
489 | 503 |
df_time_series <- test_missing[[1]]$df_time_series |
490 | 504 |
head(df_time_series) |
491 | 505 |
|
492 | 506 |
table(df_time_series$missing) |
493 | 507 |
table(df_time_series$year) |
494 |
|
|
508 |
#browser() |
|
495 | 509 |
##### |
496 | 510 |
#Now combine df_time_series in one table |
497 | 511 |
|
... | ... | |
519 | 533 |
|
520 | 534 |
######################## |
521 | 535 |
#### Step 2: examine overlap |
536 |
#browser() |
|
522 | 537 |
|
523 | 538 |
path_to_shp <- dirname(countries_shp) |
524 | 539 |
layer_name <- sub(".shp","",basename(countries_shp)) |
... | ... | |
548 | 563 |
#centroids_pts <- tmp_pts |
549 | 564 |
|
550 | 565 |
r_mask <- raster(infile_mask) |
551 |
plot(r) |
|
552 |
plot(shps_tiles[[1]],add=T,border="blue",usePolypath = FALSE) #added usePolypath following error on brige and NEX |
|
566 |
#plot(r)
|
|
567 |
#plot(shps_tiles[[1]],add=T,border="blue",usePolypath = FALSE) #added usePolypath following error on brige and NEX
|
|
553 | 568 |
|
554 | 569 |
## find overlap |
555 | 570 |
#http://gis.stackexchange.com/questions/156660/loop-to-check-multiple-polygons-overlap-in-r |
... | ... | |
562 | 577 |
} |
563 | 578 |
# |
564 | 579 |
} |
580 |
|
|
581 |
#browser() |
|
565 | 582 |
|
566 | 583 |
names(shps_tiles) <- basename(unlist(in_dir_reg)) |
567 | 584 |
r_ref <- raster(list_lf_raster_tif_tiles[[1]][1]) |
... | ... | |
569 | 586 |
tile_spdf <- shps_tiles[[1]] |
570 | 587 |
tile_coord <- basename(in_dir_reg[1]) |
571 | 588 |
date_val <- df_missing$date[1] |
572 |
|
|
573 |
### use rasterize |
|
574 |
spdf_tiles <- do.call(bind, shps_tiles) #bind all tiles together in one shapefile |
|
575 | 589 |
|
576 |
#function_product_assessment_part0_functions <- "global_product_assessment_part0_functions_11052016.R" |
|
577 |
#source(file.path(script_path,function_product_assessment_part0_functions)) #source all functions used in this script |
|
590 |
### use rasterize |
|
591 |
#spdf_tiles <- do.call(bind, shps_tiles) #bind all tiles together in one shapefile |
|
592 |
#Error in (function (classes, fdef, mtable) : |
|
593 |
#unable to find an inherited method for function 'bind' for signature '"missing", "missing"' |
|
578 | 594 |
|
579 | 595 |
#undebug(rasterize_tile_day) |
580 |
list_predicted <- rasterize_tile_day(1, |
|
581 |
list_spdf=shps_tiles,
|
|
582 |
df_missing=df_missing, |
|
583 |
list_r_ref=list_r_ref, |
|
584 |
col_name="overlap", |
|
585 |
date_val=df_missing$date[1]) |
|
596 |
#list_predicted <- rasterize_tile_day(1,
|
|
597 |
# list_spdf=shps_tiles,
|
|
598 |
# df_missing=df_missing,
|
|
599 |
# list_r_ref=list_r_ref,
|
|
600 |
# col_name="overlap",
|
|
601 |
# date_val=df_missing$date[1])
|
|
586 | 602 |
#list_predicted <- mclapply(1:6, |
587 | 603 |
# FUN=rasterize_tile_day, |
588 | 604 |
# list_spdf=shps_tiles, |
... | ... | |
604 | 620 |
mc.cores = num_cores) |
605 | 621 |
|
606 | 622 |
##check that everything is correct: |
607 |
plot(r_mask) |
|
608 |
plot(raster(list_predicted[[1]]),add=T) |
|
609 |
plot(spdf_tiles_test,add=T,border="green",usePolypath = FALSE) #added usePolypath following error on brige and NEX |
|
623 |
#plot(r_mask)
|
|
624 |
#plot(raster(list_predicted[[1]]),add=T)
|
|
625 |
#plot(spdf_tiles_test,add=T,border="green",usePolypath = FALSE) #added usePolypath following error on brige and NEX
|
|
610 | 626 |
|
611 | 627 |
### Make a list of file |
612 | 628 |
out_suffix_str_tmp <- paste0(region_name,"_",out_suffix) |
... | ... | |
618 | 634 |
|
619 | 635 |
writeLines(unlist(list_predicted),con=filename_list_predicted) #weights files to mosaic |
620 | 636 |
|
637 |
browser() |
|
638 |
|
|
621 | 639 |
#out_mosaic_name_weights_m <- r_weights_sum_raster_name <- file.path(out_dir,paste("r_weights_sum_m_",mosaic_method,"_weighted_mean_",out_suffix,".tif",sep="")) |
622 | 640 |
#out_mosaic_name_prod_weights_m <- r_weights_sum_raster_name <- file.path(out_dir,paste("r_prod_weights_sum_m_",mosaic_method,"_weighted_mean_",out_suffix,".tif",sep="")) |
623 | 641 |
out_mosaic_name_predicted_m <- file.path(out_dir_str,paste("r_overlap_sum_m_",out_suffix_str_tmp,".tif",sep="")) |
Also available in: Unified diff
adding figures and fixing item number of date files