Project

General

Profile

« Previous | Next » 

Revision 0a950be6

Added by Benoit Parmentier almost 9 years ago

editing script of main mosaicing for function call with parameters

View differences:

climate/research/oregon/interpolation/global_run_scalingup_mosaicing.R
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: 12/19/2015            
8
#MODIFIED ON: 12/30/2015            
9 9
#Version: 5
10 10
#PROJECT: Environmental Layers project     
11 11
#COMMENTS: analyses run for reg4 1992 for test of mosaicing using 1500x4500km and other tiles
......
33 33

  
34 34
#################################################################################################
35 35

  
36
### Loading R library and packages        
37
#library used in the workflow production:
38
library(gtools)                              # loading some useful tools 
39
library(mgcv)                                # GAM package by Simon Wood
40
library(sp)                                  # Spatial pacakge with class definition by Bivand et al.
41
library(spdep)                               # Spatial pacakge with methods and spatial stat. by Bivand et al.
42
library(rgdal)                               # GDAL wrapper for R, spatial utilities
43
library(gstat)                               # Kriging and co-kriging by Pebesma et al.
44
library(fields)                              # NCAR Spatial Interpolation methods such as kriging, splines
45
library(raster)                              # Hijmans et al. package for raster processing
46
library(gdata)                               # various tools with xls reading, cbindX
47
library(rasterVis)                           # Raster plotting functions
48
library(parallel)                            # Parallelization of processes with multiple cores
49
library(maptools)                            # Tools and functions for sp and other spatial objects e.g. spCbind
50
library(maps)                                # Tools and data for spatial/geographic objects
51
library(reshape)                             # Change shape of object, summarize results 
52
library(plotrix)                             # Additional plotting functions
53
library(plyr)                                # Various tools including rbind.fill
54
#library(spgwr)                               # GWR method
55
library(automap)                             # Kriging automatic fitting of variogram using gstat
56
library(rgeos)                               # Geometric, topologic library of functions
57
#RPostgreSQL                                 # Interface R and Postgres, not used in this script
58
library(gridExtra)
59
#Additional libraries not used in workflow
60
library(pgirmess)                            # Krusall Wallis test with mulitple options, Kruskalmc {pgirmess}  
61
library(colorRamps)
62
library(zoo)
63
library(xts)
64 36

  
65 37
#### FUNCTION USED IN SCRIPT
66 38

  
......
139 111
#df_tile_processed_name <- "/data/project/layers/commons/NEX_data/output_run10_1500x4500_global_analyses_pred_1992_12072015/df_tile_processed_run10_1500x4500_global_analyses_pred_1992_12072015.txt" ##PARAM 25
140 112

  
141 113
#in_dir can be on NEX or Atlas
142
tb_accuracy_name <- file.path(in_dir,"tb_diagnostic_v_NA_run10_1500x4500_global_analyses_pred_1992_12072015.txt") #PARAM 21
143
data_month_s_name <- file.path(in_dir,"data_month_s_NAM_run10_1500x4500_global_analyses_pred_1992_12072015.txt") #PARAM 22
144
data_day_v_name <- file.path(in_dir,"data_day_v_NAM_run10_1500x4500_global_analyses_pred_1992_12072015.txt") #PARAM 23
145
data_day_s_name <- file.path(in_dir,"data_day_s_NAM_run10_1500x4500_global_analyses_pred_1992_12072015.txt") ##PARAM 24
146
df_tile_processed_name <- file.path(in_dir,"df_tile_processed_run10_1500x4500_global_analyses_pred_1992_12072015.txt") ##PARAM 25
114
## All of this is interesting so use df_assessment!!
115
tb_v_accuracy_name <- file.path(in_dir, basename(df_assessment_files$files[2])) #PARAM 21
116
tb_s_accuracy_name <- file.path(in_dir, basename(df_assessment_files$files[4])) #PARAM 21
117
data_month_s_name <- file.path(in_dir,basename(df_assessment_files$files[5])) #PARAM 22
118
data_day_v_name <- file.path(in_dir, basename(df_assessment_files$files[6])) #PARAM 23
119
data_day_s_name <- file.path(in_dir, basename(df_assessment_files$files[7])) ##PARAM 24
120
df_tile_processed_name <- file.path(in_dir, basename(df_assessment_files$files[11]))
121
pred_data_month_info <- file.path(in_dir, basename(df_assessment_files$files[9]))
122
pred_data_day_info <- file.path(in_dir, basename(df_assessment_files$files[10]))
147 123

  
148 124
#python script and gdal on NEX NASA:
149 125
#mosaic_python <- "/nobackupp6/aguzman4/climateLayers/sharedCode/"
......
163 139

  
164 140
########################## START SCRIPT ##############################
165 141

  
166

  
167
####### PART 1: Read in data and process data ########
168

  
169
#in_dir <- file.path(in_dir,region_name)
170
out_dir <- in_dir
171
if(create_out_dir_param==TRUE){
172
  out_dir <- create_dir_fun(out_dir,out_suffix)
173
  setwd(out_dir)
174
}else{
175
  setwd(out_dir) #use previoulsy defined directory
176
}
177

  
178
setwd(out_dir)
179

  
180
# accuracy table by tiles
181
tb <- read.table(tb_accuracy_name,sep=",")
182
# textfiles of stations by month
183
data_month_s <- read.table(file.path(data_month_s_name),sep=",")
184
data_day_s <- read.table(file.path(data_day_s_name),sep=",") #daily testing/validation stations by dates and tiles
185
data_day_v <- read.table(file.path(data_day_v_name),sep=",") #daily training stations by dates and tiles
186

  
187
df_tile_processed <- read.table( df_tile_processed_name,sep=",")
188

  
189
#list all files to mosaic for a list of day
190
#Take into account multiple region in some cases!!!  
191
reg_lf_mosaic <- vector("list",length=length(region_names))
192
for(k in 1:length(region_names)){
193
  in_dir_tiles_tmp <- file.path(in_dir_tiles, region_names[k])
194
  reg_lf_mosaic[[k]] <- lapply(1:length(day_to_mosaic),FUN=function(i){list.files(path=file.path(in_dir_tiles_tmp),    
195
           pattern=paste(".*.",day_to_mosaic[i],".*.tif$",sep=""),full.names=T,recursive=F)})
196
}
197

  
198
##################### PART 2: produce the mosaic ##################
199

  
200
#This is is assuming a list of file for a region!! 
201
#this is where the main function for mosaicing region starts!!
202
#use reg4 to test the code for now, redo later for any regions!!!
203
k<-2
204
for(k in 1:length(region_names)){
205
  region_selected <- region_names[k]
206
  ##########################
207
  #### First generate rmse images for each date and tile for the region
208

  
209

  
210
  lf_mosaic <- reg_lf_mosaic[[k]] #list of files to mosaic by regions
211
                                #There a 28 files for reg4, South America
212

  
213
  #######################################
214
  ################### PART I: Accuracy layers by tiles #############
215
  #first generate accuracy layers using tiles definitions and output from the accuracy assessment
142
run_mosaicing_prediction_fun <-function(i,list_param_run_mosaicing_prediction){
143

  
144
  ##Function to predict temperature interpolation with 12 input parameters
145
  #12 parameters used in the data preparation stage and input in the current script
146
  #
147
  #Input Parameters:
148
  #1) in_dir <- list_param_run_mosaicing_prediction$in_dir #PARAM1
149
  #2) y_var_name <- list_param_run_mosaicing_prediction$y_var_name # #PARAM2
150
  #3) interpolation_method <- list_param_run_mosaicing_prediction$interpolation_method ##PARAM3
151
  #4) region_name: region_name e.g. reg4 South America #PARAM4
152
  #5) mosaicing_method: options include "unweighted","use_edge_weights" #PARAM5
153
  #6) out_suffix : output suffix #PARAM 6
154
  #7) out_suffix_str: additional output suffix with region name #PARAM 7
155
  #8) metric_name: metric or columns to use for additional mosaicing: "rmse" #RMSE, MAE etc. #PARAM 8
156
  #9) pred_mod_name : model name used e.g. "mod1" #PARAM 9
157
  #10) var_pred : variable for use in residuals mapping (e.g. "res_mod1") #PARAM 10
158
  #11) create_out_dir_param: if TRUE then create a new dir #PARAM 11
159
  #12) day_to_mosaic: daily mosaics NULL then mosaic all days of the year #PARAM 12
160
  #13) proj_str :porjection used by tiles e.g. CRS_WGS84 #PARAM 13
161
  #14) file_format: output file format used for raster eg ".tif" #PARAM 14
162
  #15) NA_value: NA value used e.g. -9999 #PARAM 15
163
  #16) num_cores: number of cores #PARAM 16                 
164
  #17) region_names: selected region names e.g. reg4 #PARAM 17 
165
  #18) use_autokrige: use_autokrige if FALSE use kriging from Fields package #PARAM 18
166
  #19) infile_mask: input file mask used for the region under process #PARAM 19
167
  #20) tb_accuracy_name: daily accuracy from testing/validation stations by tiles #PARAM 20
168
  #21) data_month_s_name: training stations for climatology time steps  #PARAM 21
169
  #22) data_day_v_name:  testing stations for daily predictions combined #PARAM 22
170
  #23) data_day_s_name: training stations for daily predictions cominbed #PARAM 23
171
  #24) df_tile_processed_name: processed tiles from the accuracy assessment ##PARAM 24
172
  #25) mosaic_python: python script used in the mosoicing (gdalmerge script from Alberto Guzmann) #PARAM 25
173
  #26) python_bin: directory for general python "/usr/bin" #PARAM 26
174
  #27) algorithm: python or R, if R use mosaic function for R, if python use modified gdal merge, PARAM 27
175
  #28) match_extent : if "FALSE" try without matching geographic extent #PARAM 28 
176
  #29) list_models : if NULL use y~1 formula #PARAM 29
177

  
178
  ###Loading R library and packages     
179
  #library used in the workflow production:
180
  library(gtools)                              # loading some useful tools 
181
  library(mgcv)                                # GAM package by Simon Wood
182
  library(sp)                                  # Spatial pacakge with class definition by Bivand et al.
183
  library(spdep)                               # Spatial pacakge with methods and spatial stat. by Bivand et al.
184
  library(rgdal)                               # GDAL wrapper for R, spatial utilities
185
  library(gstat)                               # Kriging and co-kriging by Pebesma et al.
186
  library(fields)                              # NCAR Spatial Interpolation methods such as kriging, splines
187
  library(raster)                              # Hijmans et al. package for raster processing
188
  library(gdata)                               # various tools with xls reading, cbindX
189
  library(rasterVis)                           # Raster plotting functions
190
  library(parallel)                            # Parallelization of processes with multiple cores
191
  library(maptools)                            # Tools and functions for sp and other spatial objects e.g. spCbind
192
  library(maps)                                # Tools and data for spatial/geographic objects
193
  library(reshape)                             # Change shape of object, summarize results 
194
  library(plotrix)                             # Additional plotting functions
195
  library(plyr)                                # Various tools including rbind.fill
196
  #library(spgwr)                               # GWR method
197
  library(automap)                             # Kriging automatic fitting of variogram using gstat
198
  library(rgeos)                               # Geometric, topologic library of functions
199
  #RPostgreSQL                                 # Interface R and Postgres, not used in this script
200
  library(gridExtra)
201
  #Additional libraries not used in workflow
202
  library(pgirmess)                            # Krusall Wallis test with mulitple options, Kruskalmc {pgirmess}  
203
  library(colorRamps)
204
  library(zoo)
205
  library(xts)
216 206
  
217
  #tb <- list_param$tb #fitting or validation table with all days
218
  #metric_name <- "rmse" #RMSE, MAE etc.
219
  #pred_mod_name <- "mod1"
220
  #y_var_name 
221
  #interpolation_method #c("gam_CAI") #PARAM3
222
  days_to_process <- day_to_mosaic
223
  #NA_flag_val <- list_param$NA_flag_val
224
  #file_format <- list_param$file_format
225
  out_dir_str <- out_dir
226
  out_suffix_str <- out_suffix
227
  lf <- lf_mosaic
228

  
229
  #Improved by adding multicores option
230
  num_cores_tmp <- num_cores
231
  list_param_accuracy_metric_raster <- list(lf,tb,metric_name,pred_mod_name,y_var_name,interpolation_method,
232
                    days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str,out_suffix_str) 
233
  names(list_param_accuracy_metric_raster) <- c("lf","tb","metric_name","pred_mod_name","y_var_name","interpolation_method",
234
                       "days_to_process","num_cores","NA_flag_val","file_format","out_dir_str","out_suffix_str") 
235
  list_raster_created_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_metric_raster,
236
                                  list_param=list_param_accuracy_metric_raster)
237

  
238
  #debug(create_accuracy_metric_raster)
239
  #list_raster_created_obj <- lapply(1:1,FUN=create_accuracy_metric_raster,
240
  #                                  list_param=list_param_accuracy_metric_raster)
241
  #raster_created_obj <- create_accuracy_metric_raster(1, list_param_accuracy_metric_raster)
242

  
243
  #Extract list of files for rmse and date 1 (19920101), there should be 28 raster images
244
  lf_accuracy_raster <- lapply(1:length(list_raster_created_obj),FUN=function(i){unlist(list_raster_created_obj[[i]]$list_raster_name)}) 
245

  
246
  #Plot as quick check
247
  #r1 <- raster(lf_mosaic[[1]][1]) 
248
  #plot(r1)
249

  
250
  ####################################
251
  ### Now create accuracy surfaces from residuals...
252

  
253
  ## Create accuracy surface by kriging
254

  
255
  num_cores_tmp <-num_cores
256
  lf_day_tiles  <- lf_mosaic #list of raster files by dates
257
  data_df <- data_day_v # data.frame table/spdf containing stations with residuals and variable
258
  #df_tile_processed  #tiles processed during assessment usually by region
259
  #var_pred  #variable being modeled
260
  #if not list of models is provided generate one
261
  if(is.null(list_models)){
262
    list_models <- paste(var_pred,"~","1",sep=" ")
207
  #Data is on ATLAS or NASA NEX
208
  #PARAM 1
209
  in_dir <- list_param_run_mosaicing_prediction$in_dir #PARAM1
210
  y_var_name <- list_param_run_mosaicing_prediction$y_var_name # #PARAM2
211
  interpolation_method <- list_param_run_mosaicing_prediction$interpolation_method ##PARAM3
212
  region_name <- list_param_run_mosaicing_prediction$region_name #"reg4" #PARAM 4 #reg4 South America, Africa reg5,Europe reg2, North America reg1, Asia reg3
213
  mosaicing_method <- list_param_run_mosaicing_prediction$mosaicing_method # c("unweighted","use_edge_weights") #PARAM5
214
  out_suffix <- list_param_run_mosaicing_prediction$out_suffix #paste(region_name,"_","run10_1500x4500_global_analyses_pred_1992_12072015",sep="") #PARAM 6
215
  out_suffix_str <- list_param_run_mosaicing_prediction$out_suffix_str #"run10_1500x4500_global_analyses_pred_1992_12072015" #PARAM 7
216
  metric_name <- list_param_run_mosaicing_prediction$metric_name # "rmse" #RMSE, MAE etc. #PARAM 8
217
  pred_mod_name <- list_param_run_mosaicing_prediction$pred_mod_name #"mod1" #PARAM 9
218
  var_pred <- list_param_run_mosaicing_prediction$var_pred # "res_mod1" #used in residuals mapping #PARAM 10
219
  create_out_dir_param <- list_param_run_mosaicing_prediction$create_out_dir_param # FALSE #PARAM 12
220
  
221
  #if daily mosaics NULL then mosaicas all days of the year #PARAM 13
222
  day_to_mosaic <- list_param_run_mosaicing_prediction$day_to_mosaic # c("19920101","19920102","19920103") #,"19920104","19920105") #PARAM9, two dates note in /tiles for now on NEX
223
  
224
  #CRS_WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 #CONSTANT1
225
  #CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
226
  proj_str <- list_param_run_mosaicing_prediction$proj_str# CRS_WGS84 #PARAM 8 #check this parameter
227
  
228
  file_format <- list_param_run_mosaicing_prediction$file_format # ".tif" #PARAM 14
229
  NA_value <- list_param_run_mosaicing_prediction$NA_value # -9999 #PARAM 15
230
  
231
  num_cores <- list_param_run_mosaicing_prediction$num_cores  #6 #PARAM 17                 
232
  region_names <- list_param_run_mosaicing_prediction$region_names # c("reg23","reg4") #selected region names, ##PARAM 18 
233
  use_autokrige <- list_param_run_mosaicing_prediction$use_autokrige # F #PARAM 19
234
  
235
  ###Separate folder for masks by regions, should be listed as just the dir!!... #PARAM 20
236
  #infile_mask <- "/nobackupp8/bparmen1/regions_input_files/r_mask_reg4.tif"
237
  infile_mask <- list_param_run_mosaicing_prediction$infile_mask #"/data/project/layers/commons/NEX_data/regions_input_files/r_mask_reg4.tif"
238
  
239
  #in_dir can be on NEX or Atlas
240
  tb_v_accuracy_name <- list_param_run_mosaicing_prediction$tb_accuracy_name #<- file.path(in_dir,"tb_diagnostic_v_NA_run10_1500x4500_global_analyses_pred_1992_12072015.txt") #PARAM 21
241
  tb_s_accuracy_name <- list_param_run_mosaicing_prediction$tb_accuracy_name #<- file.path(in_dir,"tb_diagnostic_v_NA_run10_1500x4500_global_analyses_pred_1992_12072015.txt") #PARAM 21
242
  data_month_s_name <- list_param_run_mosaicing_prediction$data_month_s_name # file.path(in_dir,"data_month_s_NAM_run10_1500x4500_global_analyses_pred_1992_12072015.txt") #PARAM 22
243
  data_day_v_name <- list_param_run_mosaicing_prediction$data_day_v_name # file.path(in_dir,"data_day_v_NAM_run10_1500x4500_global_analyses_pred_1992_12072015.txt") #PARAM 23
244
  data_day_s_name <- list_param_run_mosaicing_prediction$data_day_s_name # file.path(in_dir,"data_day_s_NAM_run10_1500x4500_global_analyses_pred_1992_12072015.txt") ##PARAM 24
245
  df_tile_processed_name <- list_param_run_mosaicing_prediction$df_tile_processed_name # file.path(in_dir,"df_tile_processed_run10_1500x4500_global_analyses_pred_1992_12072015.txt") ##PARAM 25
246
  
247
  #python script and gdal on NEX NASA:
248
  #mosaic_python <- "/nobackupp6/aguzman4/climateLayers/sharedCode/"
249
  #python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin"
250
  #python script and gdal on Atlas NCEAS
251
  mosaic_python <- list_param_run_mosaicing_prediction$mosaic_python # "/data/project/layers/commons/NEX_data/sharedCode" #PARAM 26
252
  python_bin <- list_param_run_mosaicing_prediction$python_bin # "/usr/bin" #PARAM 27
253
  
254
  algorithm <- list_param_run_mosaicing_prediction$algorithm #"python" #PARAM 28 #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
255
  #algorithm <- "R" #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
256
  
257
  match_extent <- list_param_run_mosaicing_prediction$match_extent #"FALSE" #PARAM 29 #try without matching!!!
258
  
259
  #for residuals...
260
  list_models <- list_param_run_mosaicing_prediction$list_models #  NULL #PARAM 30
261
  #list_models <- paste(var_pred,"~","1",sep=" ") #if null then this is the default...
262
  
263
  ####### PART 1: Read in data and process data ########
264
  
265
    
266
  out_dir <- in_dir #PARAM 11
267
  in_dir_tiles <- file.path(in_dir,"tiles") #this is valid both for Atlas and NEX
268
  NA_flag_val <- NA_value #PARAM 16
269

  
270
  #in_dir <- file.path(in_dir,region_name)
271
  out_dir <- in_dir
272
  if(create_out_dir_param==TRUE){
273
    out_dir <- create_dir_fun(out_dir,out_suffix)
274
    setwd(out_dir)
275
  }else{
276
    setwd(out_dir) #use previoulsy defined directory
263 277
  }
264

  
265
  #use_autokrige #if TRUE use automap/gstat package
266
  #y_var_name  #"dailyTmax" #PARAM2
267
  #interpolation_method #c("gam_CAI") #PARAM3, need to select reg!!
268
  #date_processed #can be a monthly layer
269
  #num_cores #number of cores used
270
  #NA_flag_val 
271
  #file_format 
272
  out_dir_str <- out_dir
273
  out_suffix_str <- out_suffix 
274
  days_to_process <- day_to_mosaic
275
  df_tile_processed$path_NEX <- as.character(df_tile_processed$path_NEX) 
276
  df_tile_processed$reg <- basename(dirname(df_tile_processed$path_NEX))
277

  
278
  ##By regions, selected earlier
279
  #for(k in 1:length(region_names)){
280
  df_tile_processed_reg <- subset(df_tile_processed,reg==region_selected)#use reg4
281
  #i<-1 #loop by days/date to process!!
282
  #test on the first day 
283
  list_param_create_accuracy_residuals_raster <- list(lf_day_tiles,data_df,df_tile_processed_reg,
284
                    var_pred,list_models,use_autokrige,y_var_name,interpolation_method,
285
                    days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str,
286
                    out_suffix_str) 
287
  names(list_param_create_accuracy_residuals_raster) <- c("lf_day_tiles","data_df","df_tile_processed_reg",
288
                    "var_pred","list_models","use_autokrige","y_var_name","interpolation_method",
289
                    "days_to_process","num_cores_tmp","NA_flag_val","file_format","out_dir_str",
290
                    "out_suffix_str") 
291

  
292
  list_create_accuracy_residuals_raster_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_residuals_raster,
293
                                  list_param=list_param_create_accuracy_residuals_raster)
294

  
295
  #undebug(create_accuracy_residuals_raster)
296
  #list_create_accuracy_residuals_raster_obj <- lapply(1:1,FUN=create_accuracy_residuals_raster,
297
  #                                list_param=list_param_create_accuracy_residuals_raster)
298

  
299
  #create_accuracy_residuals_raster_obj <- create_accuracy_metric_raster(1, list_param_create_accuracy_residuals_raster_obj)
300

  
301
  #note that three tiles did not produce a residuals surface!!! find out more later, join the output
302
  #to df_raste_tile to keep track of which one did not work...
303
  #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))) 
304
  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)
305

  
306
  #Plot as quick check
307
  #r1 <- raster(lf_mosaic[[1]][1]) 
308
  #list_create_accuracy_residuals_raster_obj
309 278
  
310
  ######################################################
311
  #### PART 2: GENETATE MOSAIC FOR LIST OF FILES #####
312
  #################################
313
  #### Mosaic tiles for the variable predicted and accuracy metric
314

  
315
  #methods availbable:use_sine_weights,use_edge,use_linear_weights
316
  #only use edge method for now
317
  #loop to dates..., make this a function...
318
  list_mosaic_obj <- vector("list",length=length(day_to_mosaic))
319
  for(i in 1:length(day_to_mosaic)){
320
    #
321
    mosaic_method <- "use_edge_weights" #this is distance from edge
322
    out_suffix_tmp <- paste(interpolation_method,y_var_name,day_to_mosaic[i],out_suffix,sep="_")
323
    #debug(mosaicFiles)
324
    #can also loop through methods!!!
325
    #python_bin <- "/usr/bin/" #python gdal bin, on Atlas NCEAS
326
    #python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules/bin" #on NEX
327
    #gdal_merge_sum_noDataTest.py
328

  
329
    mosaic_edge_obj_prediction <- mosaicFiles(lf_mosaic[[i]],
330
                                        mosaic_method="use_edge_weights",
331
                                        num_cores=num_cores,
332
                                        r_mask_raster_name=infile_mask,
333
                                        python_bin=python_bin,
334
                                        mosaic_python=mosaic_python,
335
                                        algorithm=algorithm,
336
                                        match_extent=match_extent,
337
                                        df_points=NULL,
338
                                        NA_flag=NA_flag_val,
339
                                        file_format=file_format,
340
                                        out_suffix=out_suffix_tmp,
341
                                        out_dir=out_dir)
279
  setwd(out_dir)
342 280
  
343
    mosaic_method <- "use_edge_weights" #this is distance from edge
344
    out_suffix_tmp <- paste(interpolation_method,metric_name,day_to_mosaic[i],out_suffix,sep="_")
345

  
346
    #debug(mosaicFiles)
347
    #can also loop through methods!!!
348
    mosaic_edge_obj_accuracy <- mosaicFiles(lf_accuracy_raster[[i]],
349
                                        mosaic_method="use_edge_weights",
350
                                        num_cores=num_cores,
351
                                        r_mask_raster_name=infile_mask,
352
                                        python_bin=python_bin,
353
                                        mosaic_python=mosaic_python,
354
                                        algorithm=algorithm,
355
                                        df_points=NULL,
356
                                        NA_flag=NA_flag_val,
357
                                        file_format=file_format,
358
                                        out_suffix=out_suffix_tmp,
359
                                        out_dir=out_dir)
281
  # accuracy table by tiles
282
  tb <- read.table(tb_accuracy_name,sep=",")
283
  # textfiles of stations by month
284
  data_month_s <- read.table(file.path(data_month_s_name),sep=",")
285
  data_day_s <- read.table(file.path(data_day_s_name),sep=",") #daily testing/validation stations by dates and tiles
286
  data_day_v <- read.table(file.path(data_day_v_name),sep=",") #daily training stations by dates and tiles
360 287
  
361
    list_mosaic_obj[[i]] <- list(prediction=mosaic_edge_obj_prediction,accuracy=mosaic_edge_obj_accuracy)
362

  
363
    ### produce residuals mosaics
364
    mosaic_method <- "use_edge_weights" #this is distance from edge
365
    out_suffix_tmp <- paste(interpolation_method,"kriged_residuals",day_to_mosaic[i],out_suffix,sep="_")
366
    #lf_tmp<-list.files(pattern="*kriged_residuals.*.tif",full.names=T)
367
    lf_tmp <- lf_accuracy_residuals_raster[[i]]
368
    #lf_accuracy_residuals_raster[[i]]
369
    #debug(mosaicFiles)
370
    mosaic_edge_obj_residuals <- mosaicFiles(lf_tmp,
371
                                        mosaic_method="use_edge_weights",
372
                                        num_cores=num_cores,
373
                                        r_mask_raster_name=infile_mask,
374
                                        python_bin=python_bin,
375
                                        mosaic_python=mosaic_python,
376
                                        algorithm=algorithm,
377
                                        match_extent=match_extent,
378
                                        df_points=NULL,
379
                                        NA_flag=NA_flag_val,
380
                                        file_format=file_format,
381
                                        out_suffix=out_suffix_tmp,
382
                                        out_dir=out_dir)
288
  df_tile_processed <- read.table( df_tile_processed_name,sep=",")
383 289
  
384
    list_mosaic_obj[[i]] <- list(prediction=mosaic_edge_obj_prediction,accuracy=mosaic_edge_obj_accuracy,mosaic_edge_obj_residuals)
290
  #list all files to mosaic for a list of day
291
  #Take into account multiple region in some cases!!!  
292
  reg_lf_mosaic <- vector("list",length=length(region_names))
293
  for(k in 1:length(region_names)){
294
    in_dir_tiles_tmp <- file.path(in_dir_tiles, region_names[k])
295
    reg_lf_mosaic[[k]] <- lapply(1:length(day_to_mosaic),FUN=function(i){list.files(path=file.path(in_dir_tiles_tmp),    
296
                                                                                    pattern=paste(".*.",day_to_mosaic[i],".*.tif$",sep=""),full.names=T,recursive=F)})
385 297
  }
386

  
387
  ##End of mosaicing function for region predictions
298
  
299
  ##################### PART 2: produce the mosaic ##################
300
  
301
  #This is is assuming a list of file for a region!! 
302
  #this is where the main function for mosaicing region starts!!
303
  #use reg4 to test the code for now, redo later for any regions!!!
304
  k<-2
305
  for(k in 1:length(region_names)){
306
    region_selected <- region_names[k]
307
    ##########################
308
    #### First generate rmse images for each date and tile for the region
309
    
310
    
311
    lf_mosaic <- reg_lf_mosaic[[k]] #list of files to mosaic by regions
312
    #There a 28 files for reg4, South America
313
    
314
    #######################################
315
    ################### PART I: Accuracy layers by tiles #############
316
    #first generate accuracy layers using tiles definitions and output from the accuracy assessment
317
    
318
    #tb <- list_param$tb #fitting or validation table with all days
319
    #metric_name <- "rmse" #RMSE, MAE etc.
320
    #pred_mod_name <- "mod1"
321
    #y_var_name 
322
    #interpolation_method #c("gam_CAI") #PARAM3
323
    days_to_process <- day_to_mosaic
324
    #NA_flag_val <- list_param$NA_flag_val
325
    #file_format <- list_param$file_format
326
    out_dir_str <- out_dir
327
    out_suffix_str <- out_suffix
328
    lf <- lf_mosaic
329
    
330
    #Improved by adding multicores option
331
    num_cores_tmp <- num_cores
332
    list_param_accuracy_metric_raster <- list(lf,tb,metric_name,pred_mod_name,y_var_name,interpolation_method,
333
                                              days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str,out_suffix_str) 
334
    names(list_param_accuracy_metric_raster) <- c("lf","tb","metric_name","pred_mod_name","y_var_name","interpolation_method",
335
                                                  "days_to_process","num_cores","NA_flag_val","file_format","out_dir_str","out_suffix_str") 
336
    list_raster_created_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_metric_raster,
337
                                      list_param=list_param_accuracy_metric_raster)
338
    
339
    #debug(create_accuracy_metric_raster)
340
    #list_raster_created_obj <- lapply(1:1,FUN=create_accuracy_metric_raster,
341
    #                                  list_param=list_param_accuracy_metric_raster)
342
    #raster_created_obj <- create_accuracy_metric_raster(1, list_param_accuracy_metric_raster)
343
    
344
    #Extract list of files for rmse and date 1 (19920101), there should be 28 raster images
345
    lf_accuracy_raster <- lapply(1:length(list_raster_created_obj),FUN=function(i){unlist(list_raster_created_obj[[i]]$list_raster_name)}) 
346
    
347
    #Plot as quick check
348
    #r1 <- raster(lf_mosaic[[1]][1]) 
349
    #plot(r1)
350
    
351
    ####################################
352
    ### Now create accuracy surfaces from residuals...
353
    
354
    ## Create accuracy surface by kriging
355
    
356
    num_cores_tmp <-num_cores
357
    lf_day_tiles  <- lf_mosaic #list of raster files by dates
358
    data_df <- data_day_v # data.frame table/spdf containing stations with residuals and variable
359
    #df_tile_processed  #tiles processed during assessment usually by region
360
    #var_pred  #variable being modeled
361
    #if not list of models is provided generate one
362
    if(is.null(list_models)){
363
      list_models <- paste(var_pred,"~","1",sep=" ")
364
    }
365
    
366
    #use_autokrige #if TRUE use automap/gstat package
367
    #y_var_name  #"dailyTmax" #PARAM2
368
    #interpolation_method #c("gam_CAI") #PARAM3, need to select reg!!
369
    #date_processed #can be a monthly layer
370
    #num_cores #number of cores used
371
    #NA_flag_val 
372
    #file_format 
373
    out_dir_str <- out_dir
374
    out_suffix_str <- out_suffix 
375
    days_to_process <- day_to_mosaic
376
    df_tile_processed$path_NEX <- as.character(df_tile_processed$path_NEX) 
377
    df_tile_processed$reg <- basename(dirname(df_tile_processed$path_NEX))
378
    
379
    ##By regions, selected earlier
380
    #for(k in 1:length(region_names)){
381
    df_tile_processed_reg <- subset(df_tile_processed,reg==region_selected)#use reg4
382
    #i<-1 #loop by days/date to process!!
383
    #test on the first day 
384
    list_param_create_accuracy_residuals_raster <- list(lf_day_tiles,data_df,df_tile_processed_reg,
385
                                                        var_pred,list_models,use_autokrige,y_var_name,interpolation_method,
386
                                                        days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str,
387
                                                        out_suffix_str) 
388
    names(list_param_create_accuracy_residuals_raster) <- c("lf_day_tiles","data_df","df_tile_processed_reg",
389
                                                            "var_pred","list_models","use_autokrige","y_var_name","interpolation_method",
390
                                                            "days_to_process","num_cores_tmp","NA_flag_val","file_format","out_dir_str",
391
                                                            "out_suffix_str") 
392
    
393
    list_create_accuracy_residuals_raster_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_residuals_raster,
394
                                                        list_param=list_param_create_accuracy_residuals_raster)
395
    
396
    #undebug(create_accuracy_residuals_raster)
397
    #list_create_accuracy_residuals_raster_obj <- lapply(1:1,FUN=create_accuracy_residuals_raster,
398
    #                                list_param=list_param_create_accuracy_residuals_raster)
399
    
400
    #create_accuracy_residuals_raster_obj <- create_accuracy_metric_raster(1, list_param_create_accuracy_residuals_raster_obj)
401
    
402
    #note that three tiles did not produce a residuals surface!!! find out more later, join the output
403
    #to df_raste_tile to keep track of which one did not work...
404
    #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))) 
405
    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)
406
    
407
    #Plot as quick check
408
    #r1 <- raster(lf_mosaic[[1]][1]) 
409
    #list_create_accuracy_residuals_raster_obj
410
    
411
    ##Run for data_day_s
412
    ##
413
    data_df <- data_day_s # data.frame table/spdf containing stations with residuals and variable
414
    
415
    num_cores_tmp <-num_cores
416
    lf_day_tiles  <- lf_mosaic #list of raster files by dates
417
    #data_df <- data_day_v # data.frame table/spdf containing stations with residuals and variable
418
    #df_tile_processed  #tiles processed during assessment usually by region
419
    #var_pred  #variable being modeled
420
    #if not list of models is provided generate one
421
    if(is.null(list_models)){
422
      list_models <- paste(var_pred,"~","1",sep=" ")
423
    }
424
    
425
    #use_autokrige #if TRUE use automap/gstat package
426
    #y_var_name  #"dailyTmax" #PARAM2
427
    #interpolation_method #c("gam_CAI") #PARAM3, need to select reg!!
428
    #date_processed #can be a monthly layer
429
    #num_cores #number of cores used
430
    #NA_flag_val 
431
    #file_format 
432
    out_dir_str <- out_dir
433
    out_suffix_str <- paste("data_day_s_",out_suffix,sep="") 
434
    days_to_process <- day_to_mosaic
435
    df_tile_processed$path_NEX <- as.character(df_tile_processed$path_NEX) 
436
    df_tile_processed$reg <- basename(dirname(df_tile_processed$path_NEX))
437
    
438
    ##By regions, selected earlier
439
    #for(k in 1:length(region_names)){
440
    df_tile_processed_reg <- subset(df_tile_processed,reg==region_selected)#use reg4
441
    #i<-1 #loop by days/date to process!!
442
    #test on the first day 
443
    list_param_create_accuracy_residuals_raster <- list(lf_day_tiles,data_df,df_tile_processed_reg,
444
                                                        var_pred,list_models,use_autokrige,y_var_name,interpolation_method,
445
                                                        days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str,
446
                                                        out_suffix_str) 
447
    names(list_param_create_accuracy_residuals_raster) <- c("lf_day_tiles","data_df","df_tile_processed_reg",
448
                                                            "var_pred","list_models","use_autokrige","y_var_name","interpolation_method",
449
                                                            "days_to_process","num_cores_tmp","NA_flag_val","file_format","out_dir_str",
450
                                                            "out_suffix_str") 
451
    
452
    list_create_accuracy_residuals_raster_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_residuals_raster,
453
                                                        list_param=list_param_create_accuracy_residuals_raster)
454
    
455
    #undebug(create_accuracy_residuals_raster)
456
    #list_create_accuracy_residuals_raster_obj <- lapply(1:1,FUN=create_accuracy_residuals_raster,
457
    #                                list_param=list_param_create_accuracy_residuals_raster)
458
    
459
    #create_accuracy_residuals_raster_obj <- create_accuracy_metric_raster(1, list_param_create_accuracy_residuals_raster_obj)
460
    
461
    #note that three tiles did not produce a residuals surface!!! find out more later, join the output
462
    #to df_raste_tile to keep track of which one did not work...
463
    #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))) 
464
    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)
465
    
466
    ##took 31 minutes to generate the residuals maps for each tiles (28) for region 4
467
    
468
    ######################################################
469
    #### PART 2: GENETATE MOSAIC FOR LIST OF FILES #####
470
    #################################
471
    #### Mosaic tiles for the variable predicted and accuracy metric
472
    
473
    #methods availbable:use_sine_weights,use_edge,use_linear_weights
474
    #only use edge method for now
475
    #loop to dates..., make this a function...
476
    list_mosaic_obj <- vector("list",length=length(day_to_mosaic))
477
    for(i in 1:length(day_to_mosaic)){
478
      #
479
      mosaic_method <- "use_edge_weights" #this is distance from edge
480
      out_suffix_tmp <- paste(interpolation_method,y_var_name,day_to_mosaic[i],out_suffix,sep="_")
481
      #debug(mosaicFiles)
482
      #can also loop through methods!!!
483
      #python_bin <- "/usr/bin/" #python gdal bin, on Atlas NCEAS
484
      #python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules/bin" #on NEX
485
      #gdal_merge_sum_noDataTest.py
486
      
487
      mosaic_edge_obj_prediction <- mosaicFiles(lf_mosaic[[i]],
488
                                                mosaic_method="use_edge_weights",
489
                                                num_cores=num_cores,
490
                                                r_mask_raster_name=infile_mask,
491
                                                python_bin=python_bin,
492
                                                mosaic_python=mosaic_python,
493
                                                algorithm=algorithm,
494
                                                match_extent=match_extent,
495
                                                df_points=NULL,
496
                                                NA_flag=NA_flag_val,
497
                                                file_format=file_format,
498
                                                out_suffix=out_suffix_tmp,
499
                                                out_dir=out_dir)
500
      
501
      mosaic_method <- "use_edge_weights" #this is distance from edge
502
      out_suffix_tmp <- paste(interpolation_method,metric_name,day_to_mosaic[i],out_suffix,sep="_")
503
      
504
      #debug(mosaicFiles)
505
      #can also loop through methods!!!
506
      mosaic_edge_obj_accuracy <- mosaicFiles(lf_accuracy_raster[[i]],
507
                                              mosaic_method="use_edge_weights",
508
                                              num_cores=num_cores,
509
                                              r_mask_raster_name=infile_mask,
510
                                              python_bin=python_bin,
511
                                              mosaic_python=mosaic_python,
512
                                              algorithm=algorithm,
513
                                              df_points=NULL,
514
                                              NA_flag=NA_flag_val,
515
                                              file_format=file_format,
516
                                              out_suffix=out_suffix_tmp,
517
                                              out_dir=out_dir)
518
      
519
      list_mosaic_obj[[i]] <- list(prediction=mosaic_edge_obj_prediction,accuracy=mosaic_edge_obj_accuracy)
520
      
521
      ### produce residuals mosaics
522
      #for now add data_day_s in the name!!
523
      mosaic_method <- "use_edge_weights" #this is distance from edge
524
      out_suffix_tmp <- paste(interpolation_method,"kriged_residuals","data_day_s",day_to_mosaic[i],out_suffix,sep="_")
525
      #lf_tmp<-list.files(pattern="*kriged_residuals.*.tif",full.names=T)
526
      lf_tmp <- lf_accuracy_residuals_raster[[i]]
527
      #lf_accuracy_residuals_raster[[i]]
528
      #debug(mosaicFiles)
529
      mosaic_edge_obj_residuals <- mosaicFiles(lf_tmp,
530
                                               mosaic_method="use_edge_weights",
531
                                               num_cores=num_cores,
532
                                               r_mask_raster_name=infile_mask,
533
                                               python_bin=python_bin,
534
                                               mosaic_python=mosaic_python,
535
                                               algorithm=algorithm,
536
                                               match_extent=match_extent,
537
                                               df_points=NULL,
538
                                               NA_flag=NA_flag_val,
539
                                               file_format=file_format,
540
                                               out_suffix=out_suffix_tmp,
541
                                               out_dir=out_dir)
542
      
543
      list_mosaic_obj[[i]] <- list(prediction=mosaic_edge_obj_prediction,accuracy=mosaic_edge_obj_accuracy,mosaic_edge_obj_residuals)
544
    }
545
    
546
    ##End of mosaicing function for region predictions
547
  }
548
  
549
  
550
  #####################
551
  ###### PART 2: Analysis and figures for the outputs of mosaic function #####
552
  
553
  #### compute and aspect and slope with figures
554
  #list_lf_mosaic_obj <- vector("list",length(day_to_mosaic))
555
  #lf_mean_mosaic <- vector("list",length(mosaicing_method))#2methods only
556
  #l_method_mosaic <- vector("list",length(mosaicing_method))
557
  #list_out_suffix <- vector("list",length(mosaicing_method))
558
  
559
  #for(i in 1:length(day_to_mosaic)){
560
  #  list_lf_mosaic_obj[[i]] <- list.files(path=out_dir,pattern=paste("*",day_to_mosaic[i],
561
  #                                                                   "_.*.RData",sep=""))
562
  #  lf_mean_mosaic[[i]] <- unlist(lapply(list_lf_mosaic_obj[[i]],function(x){load_obj(x)[["mean_mosaic"]]}))
563
  #  l_method_mosaic[[i]] <- paste(unlist(lapply(list_lf_mosaic_obj[[i]],function(x){load_obj(x)[["method"]]})),day_to_mosaic[i],sep="_")
564
  #  list_out_suffix[[i]] <- unlist(paste(l_method_mosaic[[i]],day_to_mosaic[[i]],out_suffix,sep="_"))
565
  #}
566
  
567
  #if(plot_figures==TRUE){
568
    
569
    #list_param_plot_mosaic <- list(lf_mosaic=unlist(lf_mean_mosaic),
570
    #                               method=unlist(l_method_mosaic),
571
    #                               out_suffix=unlist(list_out_suffix))
572
    
573
    #plot and produce png movie...
574
    #plot_mosaic(1,list_param=list_param_plot_mosaic)
575
    #num_cores <- 1
576
    #l_png_files <- mclapply(1:length(unlist(lf_mean_mosaic)),FUN=plot_mosaic,
577
    #                        list_param= list_param_plot_mosaic,
578
    #                        mc.preschedule=FALSE,mc.cores = num_cores)
579
    
580
    #lf_plot<- list.files(pattern="r_m_use.*.mask.*.tif$")
581
    #lf_mean_mosaic <- lf_plot
582
    
583
    
584
    #list_param_plot_mosaic <- list(lf_raster_fname=unlist(lf_mean_mosaic[1:2]),
585
    #                               screenRast=TRUE,
586
    #                               l_dates=day_to_mosaic,
587
    #                               out_dir_str=out_dir,
588
    #                               out_prefix_str <- "dailyTmax_",
589
    #                               out_suffix_str=out_suffix)
590
    #debug(plot_screen_raster_val)
591
    #plot_screen_raster_val(1,list_param_plot_mosaic)
592
    
593
    
594
    #num_cores <- 2
595
    #l_png_files <- mclapply(1:length(unlist(lf_mean_mosaic)[1:2]),FUN=plot_screen_raster_val,
596
    #                        list_param= list_param_plot_mosaic,
597
    #                        mc.preschedule=FALSE,mc.cores = num_cores)
598
    
599
    
600
    #list_param_plot_mosaic <- list(lf_raster_fname=unlist(lf_mean_mosaic[4:6]),
601
    #                               screenRast=FALSE,
602
    #                               l_dates=day_to_mosaic,
603
    #                               out_dir_str=out_dir,
604
    #                               out_prefix_str <- paste("rmse_",out_suffix,sep=""),
605
    #                               out_suffix_str=paste("rmse_",out_suffix,sep=""))
606
    #num_cores <- 3
607
    #l_png_files_rmse <- mclapply(1:length(unlist(lf_mean_mosaic)[4:6]),FUN=plot_screen_raster_val,
608
    #                             list_param= list_param_plot_mosaic,
609
    #                             mc.preschedule=FALSE,mc.cores = num_cores)
610
    
611
  #}
612
  
613
  ##Create return object
614
  #list of mosaiced files
615
  
616
  return(run_mosaicing_prediction_obj)
388 617
}
389 618

  
390

  
391
#####################
392
###### PART 2: Analysis and figures for the outputs of mosaic function #####
393

  
394
#### compute and aspect and slope with figures
395
#list_lf_mosaic_obj <- vector("list",length(day_to_mosaic))
396
#lf_mean_mosaic <- vector("list",length(mosaicing_method))#2methods only
397
#l_method_mosaic <- vector("list",length(mosaicing_method))
398
#list_out_suffix <- vector("list",length(mosaicing_method))
399

  
400
#for(i in 1:length(day_to_mosaic)){
401
#  list_lf_mosaic_obj[[i]] <- list.files(path=out_dir,pattern=paste("*",day_to_mosaic[i],
402
#                                                                   "_.*.RData",sep=""))
403
#  lf_mean_mosaic[[i]] <- unlist(lapply(list_lf_mosaic_obj[[i]],function(x){load_obj(x)[["mean_mosaic"]]}))
404
#  l_method_mosaic[[i]] <- paste(unlist(lapply(list_lf_mosaic_obj[[i]],function(x){load_obj(x)[["method"]]})),day_to_mosaic[i],sep="_")
405
#  list_out_suffix[[i]] <- unlist(paste(l_method_mosaic[[i]],day_to_mosaic[[i]],out_suffix,sep="_"))
406
#}
407

  
408

  
409
#list_param_plot_mosaic <- list(lf_mosaic=unlist(lf_mean_mosaic),
410
#                               method=unlist(l_method_mosaic),
411
#                               out_suffix=unlist(list_out_suffix))
412

  
413
#plot and produce png movie...
414
#plot_mosaic(1,list_param=list_param_plot_mosaic)
415
num_cores <- 1
416
l_png_files <- mclapply(1:length(unlist(lf_mean_mosaic)),FUN=plot_mosaic,
417
                        list_param= list_param_plot_mosaic,
418
                        mc.preschedule=FALSE,mc.cores = num_cores)
419

  
420
lf_plot<- list.files(pattern="r_m_use.*.mask.*.tif$")
421
lf_mean_mosaic <- lf_plot
422

  
423

  
424
list_param_plot_mosaic <- list(lf_raster_fname=unlist(lf_mean_mosaic[1:2]),
425
                               screenRast=TRUE,
426
                               l_dates=day_to_mosaic,
427
                               out_dir_str=out_dir,
428
                               out_prefix_str <- "dailyTmax_",
429
                               out_suffix_str=out_suffix)
430
debug(plot_screen_raster_val)
431
plot_screen_raster_val(1,list_param_plot_mosaic)
432

  
433

  
434
num_cores <- 2
435
l_png_files <- mclapply(1:length(unlist(lf_mean_mosaic)[1:2]),FUN=plot_screen_raster_val,
436
                        list_param= list_param_plot_mosaic,
437
                        mc.preschedule=FALSE,mc.cores = num_cores)
438

  
439

  
440
list_param_plot_mosaic <- list(lf_raster_fname=unlist(lf_mean_mosaic[4:6]),
441
                               screenRast=FALSE,
442
                               l_dates=day_to_mosaic,
443
                               out_dir_str=out_dir,
444
                               out_prefix_str <- paste("rmse_",out_suffix,sep=""),
445
                               out_suffix_str=paste("rmse_",out_suffix,sep=""))
446
num_cores <- 3
447
l_png_files_rmse <- mclapply(1:length(unlist(lf_mean_mosaic)[4:6]),FUN=plot_screen_raster_val,
448
                        list_param= list_param_plot_mosaic,
449
                        mc.preschedule=FALSE,mc.cores = num_cores)
450

  
451 619
###############
452 620

  
453 621
##################### END OF SCRIPT ######################

Also available in: Unified diff