Project

General

Profile

« Previous | Next » 

Revision 31651cbb

Added by Benoit Parmentier over 8 years ago

mosaicing script, adding options to run accuracy layers, variable predicted and other options

View differences:

climate/research/oregon/interpolation/global_run_scalingup_mosaicing.R
1
##############################  INTERPOLATION OF TEMPERATURES  #######################################
2
#######################  Script for assessment of scaling up on NEX ##############################
1
####################################  INTERPOLATION OF TEMPERATURES  #######################################
2
#######################  Script for assessment of scaling up and mosaicing on NEX ##############################
3 3
#This script uses the worklfow code applied to the globe. Results currently reside on NEX/PLEIADES NASA.
4 4
#Different options to explore mosaicing are tested.
5 5
#Analyses, figures, tables and data are also produced in the script.
6 6
#AUTHOR: Benoit Parmentier 
7 7
#CREATED ON: 04/14/2015  
8
#MODIFIED ON: 04/05/2016            
9
#Version: 5
8
#MODIFIED ON: 04/07/2016            
9
#Version: 6
10 10
#PROJECT: Environmental Layers project     
11
#COMMENTS: analyses run for reg4 1992 for test of mosaicing using 1500x4500km and other tiles
11
#COMMENTS: analyses run for reg4 1991 for test of mosaicing using 1500x4500km and other tiles
12 12
#TODO:
13 13
#1) Make this is a script/function callable from the shell/bash
14 14
#2) clean up temporary files, it builds currently on the disk
......
37 37

  
38 38
#### FUNCTION USED IN SCRIPT
39 39

  
40
# function_mosaicing <-"global_run_scalingup_mosaicing_function_12192015.R"
41
# 
42
# #in_dir_script <-"/home/parmentier/Data/IPLANT_project/env_layers_scripts" #NCEAS UCSB
43
# in_dir_script <- "/nobackupp8/bparmen1/env_layers_scripts" #NASA NEX
44
# source(file.path(in_dir_script,function_mosaicing))
45
# 
46
# load_obj <- function(f)
47
# {
48
#   env <- new.env()
49
#   nm <- load(f, env)[1]
50
#   env[[nm]]
51
# }
52
# 
53
# create_dir_fun <- function(out_dir,out_suffix){
54
#   if(!is.null(out_suffix)){
55
#     out_name <- paste("output_",out_suffix,sep="")
56
#     out_dir <- file.path(out_dir,out_name)
57
#   }
58
#   #create if does not exists
59
#   if(!file.exists(out_dir)){
60
#     dir.create(out_dir)
61
#   }
62
#   return(out_dir)
63
# }
64 40

  
65 41
############################################
66 42
#### Parameters and constants  
67 43

  
68
#Data is on ATLAS or NASA NEX
69
#PARAM 1
70
# in_dir <- "/data/project/layers/commons/NEX_data/output_run10_1500x4500_global_analyses_pred_1992_12072015" #NCEAS
71
# #in_dir <- "/nobackupp8/bparmen1/output_run10_1500x4500_global_analyses_pred_1992_12072015" #NEX
72
# 
73
# in_dir_tiles <- file.path(in_dir,"tiles") #this is valid both for Atlas and NEX
74
# y_var_name <- "dailyTmax" #PARAM2
75
# interpolation_method <- c("gam_CAI") #PARAM3
76
# region_name <- "reg4" #PARAM 4 #reg4 South America, Africa reg5,Europe reg2, North America reg1, Asia reg3
77
# mosaicing_method <- c("unweighted","use_edge_weights") #PARAM5
78
# out_suffix <- paste(region_name,"_","run10_1500x4500_global_analyses_pred_1992_12072015",sep="") #PARAM 6
79
# out_suffix_str <- "run10_1500x4500_global_analyses_pred_1992_12072015" #PARAM 7
80
# metric_name <- "rmse" #RMSE, MAE etc. #PARAM 8
81
# pred_mod_name <- "mod1" #PARAM 9
82
# var_pred <- "res_mod1" #used in residuals mapping #PARAM 10
83
# 
84
# out_dir <- in_dir #PARAM 11
85
# create_out_dir_param <- FALSE #PARAM 12
86
# 
87
# #if daily mosaics NULL then mosaicas all days of the year #PARAM 13
88
# day_to_mosaic <- c("19920101","19920102","19920103") #,"19920104","19920105") #PARAM9, two dates note in /tiles for now on NEX
89
# 
90
# #CRS_WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 #CONSTANT1
91
# #CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
92
# #proj_str<- CRS_WGS84 #PARAM 8 #check this parameter
93
#  
94
# file_format <- ".tif" #PARAM 14
95
# NA_value <- -9999 #PARAM 15
96
# NA_flag_val <- NA_value #PARAM 16
97
#      
98
# num_cores <- 6 #PARAM 17                 
99
# region_names <- c("reg23","reg4") #selected region names, ##PARAM 18 
100
# use_autokrige <- F #PARAM 19
101
# 
102
# ###Separate folder for masks by regions, should be listed as just the dir!!... #PARAM 20
103
# #infile_mask <- "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_reg4.tif"
104
# infile_mask <- "/data/project/layers/commons/NEX_data/regions_input_files/r_mask_reg4.tif"
105
# ## All of this is interesting so use df_assessment!!
106
# df_assessment_files_name <- "df_assessment_files_reg4_1984_run_global_analyses_pred_12282015.txt" # data.frame with all files used in assessmnet, PARAM 21
107
# 
108
# #in_dir can be on NEX or Atlas
109
# 
110
# #python script and gdal on NEX NASA:
111
# #mosaic_python <- "/nobackupp6/aguzman4/climateLayers/sharedCode/"
112
# #python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin"
113
# #python script and gdal on Atlas NCEAS
114
# mosaic_python <- "/data/project/layers/commons/NEX_data/sharedCode" #PARAM 26
115
# python_bin <- "/usr/bin" #PARAM 27
116
# 
117
# algorithm <- "python" #PARAM 28 #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
118
# #algorithm <- "R" #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
119
# match_extent <- "FALSE" #PARAM 29 #try without matching!!!
120
# 
121
# #for residuals...
122
# list_models <- NULL #PARAM 30
123
# #list_models <- paste(var_pred,"~","1",sep=" ") #if null then this is the default...
124
# 
125
# list_param_run_mosaicing_prediction <- list(in_dir,y_var_name,interpolation_method,region_name,
126
#                  mosaicing_method,out_suffix,out_suffix_str,metric_name,pred_mod_name,var_pred,
127
#                  create_out_dir_param,day_to_mosaic,proj_str,file_format,NA_value,num_cores,
128
#                  region_name,use_autokrige,infile_mask,df_assessment_files_name,mosaic_python,
129
#                  python_bin,algorithm,match_extent,list_models)
130
# param_names <- c("in_dir","y_var_name","interpolation_method","region_name",
131
#                  "mosaicing_method","out_suffix","out_suffix_str","metric_name","pred_mod_name","var_pred",
132
#                  "create_out_dir_param","day_to_mosaic","proj_str","file_format","NA_value","num_cores",
133
#                  "region_name","use_autokrige","infile_mask","df_assessment_files_name","mosaic_python",
134
#                  "python_bin","algorithm","match_extent","list_models")
135
# names(list_param_run_mosaicing_prediction) <- param_names
136 44

  
137 45
########################## START SCRIPT ##############################
138 46

  
......
257 165
  #for residuals...
258 166
  list_models <- list_param_run_mosaicing_prediction$list_models #  NULL #PARAM 26
259 167
  #list_models <- paste(var_pred,"~","1",sep=" ") #if null then this is the default...
168
  layers_option <- list_param_run_mosaicing_prediction$layers_option
260 169
  
261 170
  ####### PART 1: Read in data and process data ########
262 171
  
......
340 249
  ################### PART I: Accuracy layers by tiles #############
341 250
  #first generate accuracy layers using tiles definitions and output from the accuracy assessment
342 251
    
343
  #tb <- list_param$tb #fitting or validation table with all days
344
  #metric_name <- "rmse" #RMSE, MAE etc.
345
  #pred_mod_name <- "mod1"
346
  #y_var_name 
347
  #interpolation_method #c("gam_CAI") #PARAM3
348
  days_to_process <- day_to_mosaic
349
  #NA_flag_val <- list_param$NA_flag_val
350
  #file_format <- list_param$file_format
351
  out_dir_str <- out_dir
352
  out_suffix_str <- out_suffix
353
  lf <- lf_mosaic
354
    
355
  #Improved by adding multicores option
356
  num_cores_tmp <- num_cores
357
  list_param_accuracy_metric_raster <- list(lf,tb,metric_name,pred_mod_name,y_var_name,interpolation_method,
252
  if(layers_option=="ac_testing"){
253
    #this takes about 1 minute and 35 seconds for 3 days and 28 tiles...
254
    #add options to clean up file after use!!
255
    #tb <- list_param$tb #fitting or validation table with all days
256
    #metric_name <- "rmse" #RMSE, MAE etc.
257
    #pred_mod_name <- "mod1"
258
    #y_var_name 
259
    #interpolation_method #c("gam_CAI") #PARAM3
260
    days_to_process <- day_to_mosaic
261
    #NA_flag_val <- list_param$NA_flag_val
262
    #file_format <- list_param$file_format
263
    out_dir_str <- out_dir
264
    out_suffix_str <- out_suffix
265
    lf <- lf_mosaic
266
    
267
    #Improved by adding multicores option
268
    num_cores_tmp <- num_cores
269
    list_param_accuracy_metric_raster <- list(lf,tb,metric_name,pred_mod_name,y_var_name,interpolation_method,
358 270
                                              days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str,out_suffix_str) 
359
  names(list_param_accuracy_metric_raster) <- c("lf","tb","metric_name","pred_mod_name","y_var_name","interpolation_method",
271
    names(list_param_accuracy_metric_raster) <- c("lf","tb","metric_name","pred_mod_name","y_var_name","interpolation_method",
360 272
                                                  "days_to_process","num_cores","NA_flag_val","file_format","out_dir_str","out_suffix_str") 
361
  list_raster_created_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_metric_raster,
273
    list_raster_created_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_metric_raster,
362 274
                                      list_param=list_param_accuracy_metric_raster)
363 275
    
364
  #debug(create_accuracy_metric_raster)
365
  #list_raster_created_obj <- lapply(1:1,FUN=create_accuracy_metric_raster,
366
  #                                  list_param=list_param_accuracy_metric_raster)
367
  #raster_created_obj <- create_accuracy_metric_raster(1, list_param_accuracy_metric_raster)
276
    #debug(create_accuracy_metric_raster)
277
    #list_raster_created_obj <- lapply(1:1,FUN=create_accuracy_metric_raster,
278
    #                                  list_param=list_param_accuracy_metric_raster)
279
    #raster_created_obj <- create_accuracy_metric_raster(1, list_param_accuracy_metric_raster)
368 280
    
369
  #Extract list of files for rmse and date 1 (19920101), there should be 28 raster images
370
  lf_accuracy_raster <- lapply(1:length(list_raster_created_obj),FUN=function(i){unlist(list_raster_created_obj[[i]]$list_raster_name)}) 
281
    #Extract list of files for rmse and date 1 (19920101), there should be 28 raster images
282
    lf_accuracy_raster <- lapply(1:length(list_raster_created_obj),FUN=function(i){unlist(list_raster_created_obj[[i]]$list_raster_name)}) 
371 283
    
372
  #Plot as quick check
373
  #r1 <- raster(lf_mosaic[[1]][1]) 
374
  #plot(r1)
375
  #browser()
284
    #Plot as quick check
285
    #r1 <- raster(lf_mosaic[[1]][1]) 
286
    #plot(r1)
287
    #browser()
288
    
289
  }
376 290
    
377 291
  ####################################
378 292
  ### Now create accuracy surfaces from residuals...
379 293
    
380
  ## Create accuracy surface by kriging
381
    
382
  num_cores_tmp <-num_cores
383
  lf_day_tiles  <- lf_mosaic #list of raster files by dates
384
  data_df <- data_day_v # data.frame table/spdf containing stations with residuals and variable
385
  #df_tile_processed  #tiles processed during assessment usually by region
386
  #var_pred  #variable being modeled
387
  #if not list of models is provided generate one
388
  if(is.null(list_models)){
389
    list_models <- paste(var_pred,"~","1",sep=" ")
390
  }
294
  if(layers_option=="res_testing"){
295

  
296
    ## Create accuracy surface by kriging
297
    num_cores_tmp <-num_cores
298
    lf_day_tiles  <- lf_mosaic #list of raster files by dates
299
    data_df <- data_day_v # data.frame table/spdf containing stations with residuals and variable
300
    #df_tile_processed  #tiles processed during assessment usually by region
301
    #var_pred  #variable being modeled
302
    #if not list of models is provided generate one
303
    if(is.null(list_models)){
304
      list_models <- paste(var_pred,"~","1",sep=" ")
305
    }
391 306
    
392
  #use_autokrige #if TRUE use automap/gstat package
393
  #y_var_name  #"dailyTmax" #PARAM2
394
  #interpolation_method #c("gam_CAI") #PARAM3, need to select reg!!
395
  #date_processed #can be a monthly layer
396
  #num_cores #number of cores used
397
  #NA_flag_val 
398
  #file_format 
399
  out_dir_str <- out_dir
400
  #out_suffix_str <- out_suffix 
401
  days_to_process <- day_to_mosaic
402
  out_suffix_str <- paste("data_day_v_",out_suffix,sep="") 
403
    
404
  #browser()
405
  df_tile_processed$path_NEX <- as.character(df_tile_processed$path_NEX) 
406
  df_tile_processed$reg <- basename(dirname(df_tile_processed$path_NEX))
407
    
408
  ##By regions, selected earlier
409
  #for(k in 1:length(region_names)){
410
  df_tile_processed_reg <- subset(df_tile_processed,reg==region_selected)#use reg4
411
  #i<-1 #loop by days/date to process!!
412
  #test on the first day 
413
  list_param_create_accuracy_residuals_raster <- list(lf_day_tiles,data_df,df_tile_processed_reg,
307
    #use_autokrige #if TRUE use automap/gstat package
308
    #y_var_name  #"dailyTmax" #PARAM2
309
    #interpolation_method #c("gam_CAI") #PARAM3, need to select reg!!
310
    #date_processed #can be a monthly layer
311
    #num_cores #number of cores used
312
    #NA_flag_val 
313
    #file_format 
314
    out_dir_str <- out_dir #change to specific separate dir??
315
    #out_suffix_str <- out_suffix 
316
    days_to_process <- day_to_mosaic
317
    out_suffix_str <- paste("data_day_v_",out_suffix,sep="") 
318
    #browser()
319
    df_tile_processed$path_NEX <- as.character(df_tile_processed$path_NEX) 
320
    df_tile_processed$reg <- basename(dirname(df_tile_processed$path_NEX))
321
    
322
    ##By regions, selected earlier
323
    #for(k in 1:length(region_names)){
324
    df_tile_processed_reg <- subset(df_tile_processed,reg==region_selected)#use reg4
325
    #i<-1 #loop by days/date to process!!
326
    #test on the first day 
327
    list_param_create_accuracy_residuals_raster <- list(lf_day_tiles,data_df,df_tile_processed_reg,
414 328
                                                        var_pred,list_models,use_autokrige,y_var_name,interpolation_method,
415 329
                                                        days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str,
416 330
                                                        out_suffix_str) 
417
  names(list_param_create_accuracy_residuals_raster) <- c("lf_day_tiles","data_df","df_tile_processed_reg",
331
    names(list_param_create_accuracy_residuals_raster) <- c("lf_day_tiles","data_df","df_tile_processed_reg",
418 332
                                                            "var_pred","list_models","use_autokrige","y_var_name","interpolation_method",
419 333
                                                            "days_to_process","num_cores_tmp","NA_flag_val","file_format","out_dir_str",
420 334
                                                            "out_suffix_str") 
421
  #browser()  
422
  list_create_accuracy_residuals_raster_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_residuals_raster,
335
    #browser()  
336
    list_create_accuracy_residuals_raster_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_residuals_raster,
423 337
                                                        list_param=list_param_create_accuracy_residuals_raster)
424 338
    
425
  #undebug(create_accuracy_residuals_raster)
426
  #list_create_accuracy_residuals_raster_obj <- lapply(1:1,FUN=create_accuracy_residuals_raster,
427
  #                                list_param=list_param_create_accuracy_residuals_raster)
339
    #undebug(create_accuracy_residuals_raster)
340
    #list_create_accuracy_residuals_raster_obj <- lapply(1:1,FUN=create_accuracy_residuals_raster,
341
    #                                list_param=list_param_create_accuracy_residuals_raster)
428 342
    
429
  #create_accuracy_residuals_raster_obj <- create_accuracy_residuals_raster(1, list_param_create_accuracy_residuals_raster_obj)
343
    #create_accuracy_residuals_raster_obj <- create_accuracy_residuals_raster(1, list_param_create_accuracy_residuals_raster_obj)
430 344
    
431
  #note that three tiles did not produce a residuals surface!!! find out more later, join the output
432
  #to df_raste_tile to keep track of which one did not work...
433
  #lf_accuracy_residuals_raster <- as.character(unlist(lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name"))},x=list_create_accuracy_residuals_raster_obj))) 
434
  lf_accuracy_residuals_raster <- lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){as.character(unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name")))},x=list_create_accuracy_residuals_raster_obj)
345
    #note that three tiles did not produce a residuals surface!!! find out more later, join the output
346
    #to df_raste_tile to keep track of which one did not work...
347
    #lf_accuracy_residuals_raster <- as.character(unlist(lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name"))},x=list_create_accuracy_residuals_raster_obj))) 
348
    lf_accuracy_residuals_raster <- lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){as.character(unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name")))},x=list_create_accuracy_residuals_raster_obj)
435 349
    
436
  #Plot as quick check
437
  #r1 <- raster(lf_mosaic[[1]][1]) 
438
  #list_create_accuracy_residuals_raster_obj
439
  #browser()  
350
    #Plot as quick check
351
    #r1 <- raster(lf_mosaic[[1]][1]) 
352
    #list_create_accuracy_residuals_raster_obj
353
    #browser()  
354
  }
440 355
  
441 356
  #########################################
442 357
  ##Run for data_day_s
443 358
  ##
444
  data_df <- data_day_s # data.frame table/spdf containing stations with residuals and variable
445
    
446
  num_cores_tmp <-num_cores
447
  lf_day_tiles  <- lf_mosaic #list of raster files by dates
448
  #data_df <- data_day_v # data.frame table/spdf containing stations with residuals and variable
449
  #df_tile_processed  #tiles processed during assessment usually by region
450
  #var_pred  #variable being modeled
451
  #if not list of models is provided generate one
452
  if(is.null(list_models)){
453
    list_models <- paste(var_pred,"~","1",sep=" ")
454
  }
359
  
360
  if(layers_option=="res_testing"){
361
    
362
    data_df <- data_day_s # data.frame table/spdf containing stations with residuals and variable
363
    
364
    num_cores_tmp <-num_cores
365
    lf_day_tiles  <- lf_mosaic #list of raster files by dates
366
    #data_df <- data_day_v # data.frame table/spdf containing stations with residuals and variable
367
    #df_tile_processed  #tiles processed during assessment usually by region
368
    #var_pred  #variable being modeled
369
    #if not list of models is provided generate one
370
    if(is.null(list_models)){
371
      list_models <- paste(var_pred,"~","1",sep=" ")
372
    }
455 373
    
456
  #use_autokrige #if TRUE use automap/gstat package
457
  #y_var_name  #"dailyTmax" #PARAM2
458
  #interpolation_method #c("gam_CAI") #PARAM3, need to select reg!!
459
  #date_processed #can be a monthly layer
460
  #num_cores #number of cores used
461
  #NA_flag_val 
462
  #file_format 
463
  out_dir_str <- out_dir
464
  out_suffix_str <- paste("data_day_s_",out_suffix,sep="") 
465
  days_to_process <- day_to_mosaic
466
  df_tile_processed$path_NEX <- as.character(df_tile_processed$path_NEX) 
467
  df_tile_processed$reg <- basename(dirname(df_tile_processed$path_NEX))
468
    
469
  ##By regions, selected earlier
470
  #for(k in 1:length(region_names)){
471
  df_tile_processed_reg <- subset(df_tile_processed,reg==region_selected)#use reg4
472
  #i<-1 #loop by days/date to process!!
473
  #test on the first day 
474
  list_param_create_accuracy_residuals_raster <- list(lf_day_tiles,data_df,df_tile_processed_reg,
374
    #use_autokrige #if TRUE use automap/gstat package
375
    #y_var_name  #"dailyTmax" #PARAM2
376
    #interpolation_method #c("gam_CAI") #PARAM3, need to select reg!!
377
    #date_processed #can be a monthly layer
378
    #num_cores #number of cores used
379
    #NA_flag_val 
380
    #file_format 
381
    out_dir_str <- out_dir
382
    out_suffix_str <- paste("data_day_s_",out_suffix,sep="") 
383
    days_to_process <- day_to_mosaic
384
    df_tile_processed$path_NEX <- as.character(df_tile_processed$path_NEX) 
385
    df_tile_processed$reg <- basename(dirname(df_tile_processed$path_NEX))
386
    
387
    ##By regions, selected earlier
388
    #for(k in 1:length(region_names)){
389
    df_tile_processed_reg <- subset(df_tile_processed,reg==region_selected)#use reg4
390
    #i<-1 #loop by days/date to process!!
391
    #test on the first day 
392
    list_param_create_accuracy_residuals_raster <- list(lf_day_tiles,data_df,df_tile_processed_reg,
475 393
                                                        var_pred,list_models,use_autokrige,y_var_name,interpolation_method,
476 394
                                                        days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str,
477 395
                                                        out_suffix_str) 
478
  names(list_param_create_accuracy_residuals_raster) <- c("lf_day_tiles","data_df","df_tile_processed_reg",
396
    names(list_param_create_accuracy_residuals_raster) <- c("lf_day_tiles","data_df","df_tile_processed_reg",
479 397
                                                            "var_pred","list_models","use_autokrige","y_var_name","interpolation_method",
480 398
                                                            "days_to_process","num_cores_tmp","NA_flag_val","file_format","out_dir_str",
481 399
                                                            "out_suffix_str") 
482
  browser()  
483
  list_create_accuracy_residuals_raster_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_residuals_raster,
400
    #browser()  #21 minutes and 40 second to get here
401
    list_create_accuracy_residuals_raster_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_residuals_raster,
484 402
                                                        list_param=list_param_create_accuracy_residuals_raster)
485 403
    
486
  #undebug(create_accuracy_residuals_raster)
487
  #list_create_accuracy_residuals_raster_obj <- lapply(1:1,FUN=create_accuracy_residuals_raster,
488
  #                                list_param=list_param_create_accuracy_residuals_raster)
404
    #undebug(create_accuracy_residuals_raster)
405
    #list_create_accuracy_residuals_raster_obj <- lapply(1:1,FUN=create_accuracy_residuals_raster,
406
    #                                list_param=list_param_create_accuracy_residuals_raster)
489 407
    
490
  #create_accuracy_residuals_raster_obj <- create_accuracy_metric_raster(1, list_param_create_accuracy_residuals_raster_obj)
408
    #create_accuracy_residuals_raster_obj <- create_accuracy_metric_raster(1, list_param_create_accuracy_residuals_raster_obj)
491 409
    
492
  #note that three tiles did not produce a residuals surface!!! find out more later, join the output
493
  #to df_raste_tile to keep track of which one did not work...
494
  #lf_accuracy_residuals_raster <- as.character(unlist(lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name"))},x=list_create_accuracy_residuals_raster_obj))) 
495
  lf_accuracy_residuals_data_s_raster <- lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){as.character(unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name")))},x=list_create_accuracy_residuals_raster_obj)
410
    #note that three tiles did not produce a residuals surface!!! find out more later, join the output
411
    #to df_raste_tile to keep track of which one did not work...
412
    #lf_accuracy_residuals_raster <- as.character(unlist(lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name"))},x=list_create_accuracy_residuals_raster_obj))) 
413
    lf_accuracy_residuals_data_s_raster <- lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){as.character(unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name")))},x=list_create_accuracy_residuals_raster_obj)
496 414
    
415
  }
497 416
  ##took 31 minutes to generate the residuals maps for each tiles (28) for region 4
498
    
417
  ##Revised on 04/07 for three dates, it took 40 minutes
418
  
499 419
  ######################################################
500 420
  #### PART 2: GENERATE MOSAIC FOR LIST OF FILES #####
501 421
  #################################
......
528 448
                                                file_format=file_format,
529 449
                                                out_suffix=out_suffix_tmp,
530 450
                                                out_dir=out_dir)
531
      
451
    #runs in 15-16 minutes for 3 dates and mosaicing of 28 tiles...  
452
    
453
    ## Now accuracy based on center of centroids
532 454
    mosaic_method <- "use_edge_weights" #this is distance from edge
455
    #Adding metric name in the name...
533 456
    out_suffix_tmp <- paste(interpolation_method,metric_name,day_to_mosaic[i],out_suffix,sep="_")
534 457
      
535 458
    #debug(mosaicFiles)
......
546 469
                                              file_format=file_format,
547 470
                                              out_suffix=out_suffix_tmp,
548 471
                                              out_dir=out_dir)
549
      
472
    ##Took 39 minutes for 28 tiles and one date...!!!  
550 473
    list_mosaic_obj[[i]] <- list(prediction=mosaic_edge_obj_prediction,accuracy=mosaic_edge_obj_accuracy)
551 474
      
552 475
    ### produce residuals mosaics
......
570 493
                                               file_format=file_format,
571 494
                                               out_suffix=out_suffix_tmp,
572 495
                                               out_dir=out_dir)
573
      
496
    #Took 11 to 12 minues for one day and 28 tiles in region 4
574 497
    list_mosaic_obj[[i]] <- list(prediction=mosaic_edge_obj_prediction,accuracy=mosaic_edge_obj_accuracy,mosaic_edge_obj_residuals)
575 498
    #}
576 499
    

Also available in: Unified diff