Project

General

Profile

« Previous | Next » 

Revision 0acf4ea3

Added by Benoit Parmentier about 8 years ago

changes to generate function to check missing tiles and predict gaps

View differences:

climate/research/oregon/interpolation/global_product_assessment_part0.R
338 338

  
339 339
#ffmpeg -f gif -i animation_frame_60_-2500_6000_.gif -vcodec libx264 -x264opts -pix_fmt yuv420p outfile.mp4
340 340

  
341
#combine polygon
342
#http://gis.stackexchange.com/questions/155328/merging-multiple-spatialpolygondataframes-into-1-spdf-in-r
343

  
344
#http://gis.stackexchange.com/questions/116388/count-overlapping-polygons-in-single-shape-file-with-r
345

  
346
#### Use the predictions directory
347
#By region
348
#For each polygon/tile find polygon overlapping with count and ID (like list w)
349
#for each polygon/tile and date find if there is a prediction using the tif (multiply number)
350
#for each date of year report data in table.
351

  
352
#go through table and hsow if there are missing data (no prediction) or report min predictions for tile set?
353

  
354
############################################
355
#### Parameters and constants  
356

  
357
#on ATLAS
358
#in_dir1 <- "/data/project/layers/commons/NEX_data/test_run1_03232014/output" #On Atlas
359
#parent output dir : contains subset of the data produced on NEX
360
#in_dir1 <- "/data/project/layers/commons/NEX_data/output_run6_global_analyses_09162014/output20Deg2"
361
# parent output dir for the curent script analyes
362
#out_dir <-"/data/project/layers/commons/NEX_data/output_run3_global_analyses_06192014/" #On NCEAS Atlas
363
# input dir containing shapefiles defining tiles
364
#in_dir_shp <- "/data/project/layers/commons/NEX_data/output_run5_global_analyses_08252014/output/subset/shapefiles"
365

  
366
#On NEX
367
#contains all data from the run by Alberto
368
#in_dir1 <- " /nobackupp6/aguzman4/climateLayers/out_15x45/" #On NEX
369
#parent output dir for the current script analyes
370
#out_dir <- "/nobackup/bparmen1/" #on NEX
371
#in_dir_shp <- "/nobackupp4/aguzman4/climateLayers/output4/subset/shapefiles/"
372

  
373
#in_dir <- "/data/project/layers/commons/NEX_data/reg4_assessment"
374
#list_in_dir_run <-
375
#in_dir_list <-  c("output_run_global_analyses_pred_2009_reg4","output_run_global_analyses_pred_2010_reg4",
376
#                  "output_run_global_analyses_pred_2011_reg4","output_run_global_analyses_pred_2012_reg4",
377
#                  "output_run_global_analyses_pred_2013_reg4","output_run_global_analyses_pred_2014_reg4")
378
#in_dir_list_filename <- "/data/project/layers/commons/NEX_data/reg4_assessment/stage6_reg4_in_dir_list_02072016.txt"
379
#in_dir <- "" #PARAM 0
380
#y_var_name <- "dailyTmax" #PARAM1
381
#interpolation_method <- c("gam_CAI") #PARAM2
382
#out_suffix <- "global_analyses_overall_assessment_reg4_02072016"
383
#out_suffix <- "output_run10_1000x3000_global_analyses_02102015"
384
#out_suffix <- "run10_1500x4500_global_analyses_pred_1992_10052015" #PARAM3
385
#out_dir <- "/data/project/layers/commons/NEX_data/output_run10_1500x4500_global_analyses_pred_1992_10052015" #PARAM4
386
#create_out_dir_param <- TRUE #PARAM 5
387
#mosaic_plot <- FALSE #PARAM6
388
#if daily mosaics NULL then mosaicas all days of the year
389
#day_to_mosaic <- c("19920101","19920102","19920103") #PARAM7
390
#CRS_WGS84 <-    CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 #CONSTANT1
391
#CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
392
#proj_str<- CRS_WGS84 #PARAM 8 #check this parameter
393
#file_format <- ".rst" #PARAM 9
394
#NA_value <- -9999 #PARAM10
395
#NA_flag_val <- NA_value
396
#multiple_region <- TRUE #PARAM 12
397
#region_name <- "world" #PARAM 13
398
#countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp" #PARAM 13, copy this on NEX too
399
#plot_region <- TRUE
400
#num_cores <- 6 #PARAM 14
401
#region_name <- c("reg4") #reference region to merge if necessary, if world all the regions are together #PARAM 16
402
#use previous files produced in step 1a and stored in a data.frame
403
#df_assessment_files <- "df_assessment_files_reg4_1984_run_global_analyses_pred_12282015.txt" #PARAM 17
404
#threshold_missing_day <- c(367,365,300,200) #PARM18
405

  
406
#list_param_run_assessment_plottingin_dir <- list(in_dir,y_var_name, interpolation_method, out_suffix, 
407
#                      out_dir, create_out_dir_param, mosaic_plot, proj_str, file_format, NA_value,
408
#                      multiple_region, countries_shp, plot_region, num_cores, 
409
#                      region_name, df_assessment_files, threshold_missing_day) 
410

  
411
#names(list_param_run_assessment_plottingin_dir) <- c("in_dir","y_var_name","interpolation_method","out_suffix", 
412
#                      "out_dir","create_out_dir_param","mosaic_plot","proj_str","file_format","NA_value",
413
#                      "multiple_region","countries_shp","plot_region","num_cores", 
414
#                      "region_name","df_assessment_files","threshold_missing_day") 
415

  
416
#run_assessment_plotting_prediction_fun(list_param_run_assessment_plottingin_dir) 
417

  
418
  ####### PARSE INPUT ARGUMENTS/PARAMETERS #####
419
  in_dir_list_filename <- list_param_run_assessment_plotting$in_dir_list_filename #PARAM 0
420
  in_dir <- list_param_run_assessment_plotting$in_dir #PARAM 1
421
  y_var_name <- list_param_run_assessment_plotting$y_var_name #PARAM2
422
  interpolation_method <- list_param_run_assessment_plotting$interpolation_method #c("gam_CAI") #PARAM3
423
  out_suffix <- list_param_run_assessment_plotting$out_suffix #PARAM4
424
  out_dir <- list_param_run_assessment_plotting$out_dir # PARAM5
425
  create_out_dir_param <- list_param_run_assessment_plotting$create_out_dir_param # FALSE #PARAM 6
426
  mosaic_plot <- list_param_run_assessment_plotting$mosaic_plot #FALSE #PARAM7
427
  proj_str<- list_param_run_assessment_plotting$proj_str #CRS_WGS84 #PARAM 8 #check this parameter
428
  file_format <- list_param_run_assessment_plotting$file_format #".rst" #PARAM 9
429
  NA_flag_val <- list_param_run_assessment_plotting$NA_flag_val #-9999 #PARAM10
430
  multiple_region <- list_param_run_assessment_plotting$multiple_region # <- TRUE #PARAM 11
431
  countries_shp <- list_param_run_assessment_plotting$countries_shp #<- "world" #PARAM 12
432
  plot_region <- list_param_run_assessment_plotting$plot_region # PARAM13 
433
  num_cores <- list_param_run_assessment_plotting$num_cores # 6 #PARAM 14
434
  region_name <- list_param_run_assessment_plotting$region_name #<- "world" #PARAM 15
435
  #df_assessment_files_name <- list_param_run_assessment_plotting$df_assessment_files_name #PARAM 16
436
  threshold_missing_day <- list_param_run_assessment_plotting$threshold_missing_day #PARM17
437
  year_predicted <- list_param_run_assessment_plotting$year_predicted
438
 
439
  NA_value <- NA_flag_val 
440
  metric_name <- "rmse" #to be added to the code later...
441
  
442
  ##################### START SCRIPT #################
443
  
444
  ####### PART 1: Read in data ########
445
  out_dir <- in_dir
446
  if(create_out_dir_param==TRUE){
447
    out_dir <- create_dir_fun(out_dir,out_suffix)
448
    setwd(out_dir)
449
  }else{
450
    setwd(out_dir) #use previoulsy defined directory
451
  }
341 452

  
453
  setwd(out_dir)
454
  
455
  list_outfiles <- vector("list", length=35) #collect names of output files, this should be dynamic?
456
  list_outfiles_names <- vector("list", length=35) #collect names of output files
457
  counter_fig <- 0 #index of figure to collect outputs
458
  
459
  #i <- year_predicted
460
  ###Table 1: Average accuracy metrics
461
  ###Table 2: daily accuracy metrics for all tiles
462

  
463
  if(!is.null(in_dir_list_filename)){
464
    in_dir_list <- as.list(read.table(in_dir_list_filename,stringsAsFactors=F)[,1])
465
  }else{
466
    pattern_str <- paste0("^output_",region_name,".*.")
467
    in_dir_list_all <- list.dirs(path=in_dir,recursive = T)
468
    in_dir_list <- in_dir_list_all[grep(pattern_str,basename(in_dir_list_all),invert=FALSE)] #select directory with shapefiles...
469
    #in_dir_shp <- file.path(in_dir_list_all,"shapefiles")
470
  }
471
  #pattern_str <- file.path(in_dir,paste0("output_",region_name,".*."))
472
  #test <- Sys.glob(pattern_str,FALSE)
473
  #  searchStr = paste(in_dir_tiles_tmp,"/*/",year_processed,"/gam_CAI_dailyTmax_predicted_",pred_mod_name,"*",day_to_mosaic[i],"*.tif",sep="")
474
  #  #print(searchStr)
475
  #  Sys.glob(searchStr)})
476

  
477
  #lf_mosaic <- lapply(1:length(day_to_mosaic),FUN=function(i){
478
  #  searchStr = paste(in_dir_tiles_tmp,"/*/",year_processed,"/gam_CAI_dailyTmax_predicted_",pred_mod_name,"*",day_to_mosaic[i],"*.tif",sep="")
479
  #  #print(searchStr)
480
  #  Sys.glob(searchStr)})
481

  
482
  ##Read in data list from in_dir_list
483
  #list_tb_fname <- list.files(path=file.path(in_dir,in_dir_list),"tb_diagnostic_v_NA_.*.txt",full.names=T)
484
  #list_df_fname <- list.files(path=file.path(in_dir,in_dir_list),"df_tile_processed_.*..txt",full.names=T)
485
  #list_summary_metrics_v_fname <- list.files(path=file.path(in_dir,in_dir_list),"summary_metrics_v2_NA_.*.txt",full.names=T)
486
  #list_tb_s_fname <- list.files(path=file.path(in_dir,in_dir_list),"tb_diagnostic_s_NA.*.txt",full.names=T)
487
  #list_tb_month_s_fname <- list.files(path=file.path(in_dir,in_dir_list),"tb_month_diagnostic_s.*.txt",full.names=T)
488
  #list_data_month_s_fname <- list.files(path=file.path(in_dir,in_dir_list),"data_month_s.*.txt",full.names=T)
489
  #list_data_s_fname <- list.files(path=file.path(in_dir,in_dir_list),"data_day_s.*.txt",full.names=T)
490
  #list_data_v_fname <- list.files(path=file.path(in_dir,in_dir_list),"data_day_v.*.txt",full.names=T)
491
  #list_pred_data_month_info_fname <- list.files(path=file.path(in_dir,in_dir_list),"pred_data_month_info.*.txt",full.names=T)
492
  #list_pred_data_day_info_fname <- list.files(path=file.path(in_dir,in_dir_list),"pred_data_day_info.*.txt",full.names=T)
493
  
494
  list_tb_fname <- list.files(path=in_dir_list,"tb_diagnostic_v_NA_.*.txt",full.names=T)
495
  list_df_fname <- list.files(path=in_dir_list,"df_tile_processed_.*..txt",full.names=T)
496
  list_summary_metrics_v_fname <- list.files(path=in_dir_list,"summary_metrics_v2_NA_.*.txt",full.names=T)
497
  list_tb_s_fname <- list.files(path=in_dir_list,"tb_diagnostic_s_NA.*.txt",full.names=T)
498
  list_tb_month_s_fname <- list.files(path=in_dir_list,"tb_month_diagnostic_s.*.txt",full.names=T)
499
  list_data_month_s_fname <- list.files(path=in_dir_list,"data_month_s.*.txt",full.names=T)
500
  list_data_s_fname <- list.files(path=in_dir_list,"data_day_s.*.txt",full.names=T)
501
  list_data_v_fname <- list.files(path=in_dir_list,"data_day_v.*.txt",full.names=T)
502
  list_pred_data_month_info_fname <- list.files(path=in_dir_list,"pred_data_month_info.*.txt",full.names=T)
503
  list_pred_data_day_info_fname <- list.files(path=in_dir_list,"pred_data_day_info.*.txt",full.names=T)
504
  
505
  #need to fix this !! has all of the files in one list (for a region)
506
  #list_shp <- list.files(path=file.path(in_dir,file.path(in_dir_list,"shapefiles")),"*.shp",full.names=T)
342 507

  
343 508
############################ END OF SCRIPT ##################################

Also available in: Unified diff