Project

General

Profile

« Previous | Next » 

Revision 7506a985

Added by Benoit Parmentier over 11 years ago

Raster prediction, modifications to solve issues with calls and multiple sourcing

View differences:

climate/research/oregon/interpolation/GAM_fusion_analysis_raster_prediction_multisampling.R
11 11
#5)GAM fusion: possibilty of running GAM+FUSION or GAM+CAI and other options added
12 12
#The interpolation is done first at the monthly time scale then delta surfaces are added.
13 13
#AUTHOR: Benoit Parmentier                                                                        
14
#DATE: 03/18/2013                                                                                 
15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#568--                                   
14
#DATE: 03/27/2013                                                                                 
15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#568--     
16
#
17
# TO DO:
18
# 1) modidy to make it general for any method i.e. make call to method e.g. gam_fus, gam_cai etc.
19
# 2) simplify and bundle validation steps, make it general--method_mod_validation
20
# 3) solve issues with log file recordings
21
# 4) output location folder on the fly???
22

  
16 23
###################################################################################################
17 24

  
18 25
raster_prediction_gam_fusion<-function(list_param_raster_prediction){
19 26

  
20 27
  ##Function to predict temperature interpolation with 21 input parameters
21
  
22
  
28
  #9 parameters used in the data preparation stage and input in the current script
29
  #1)list_param_data_prep: used in earlier code for the query from the database and extraction for raster brick
30
  #2)infile_monthly:
31
  #3)infile_daily
32
  #4)infile_locs:
33
  #5)infile_covariates: raster covariate brick, tif file
34
  #6)covar_names: covar_names #remove at a later stage...
35
  #7)var: variable being interpolated-TMIN or TMAX
36
  #8)out_prefix
37
  #9)CRS_locs_WGS84
38
  #
39
  #6 parameters for sampling function
40
  #10)seed_number
41
  #11)nb_sample
42
  #12)step
43
  #13)constant
44
  #14)prop_minmax
45
  #15)dates_selected
46
  #
47
  #6 additional parameters for monthly climatology and more
48
  #16)list_models: model formulas in character vector
49
  #17)lst_avg: LST climatology name in the brick of covariate--change later
50
  #18)n_path
51
  #19)out_path
52
  #20)script_path: path to script
53
  #21)interpolation_method: c("gam_fusion","gam_CAI") #other otpions to be added later
23 54
  
24 55
  ###Loading R library and packages     
25 56
  
......
36 67
  library(reshape)
37 68
  library(plotrix)
38 69
  library(maptools)
70
  library(gdata) #Nesssary to use cbindX
39 71
  
40 72
  ### Parameters and arguments
41 73
  #PARSING INPUTS/ARGUMENTS
......
74 106
  
75 107
  setwd(in_path)
76 108
  
77
  source(file.path(script_path,"sampling_script_functions_03122013.R"))
78
  source(file.path(script_path,"GAM_fusion_function_multisampling_03122013.R"))
79
  source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_03182013.R"))
109
  #Sourcing in the master script to avoid confusion on the latest versions of scripts and functions!!!
110
  
111
  #source(file.path(script_path,"sampling_script_functions_03122013.R"))
112
  #source(file.path(script_path,"GAM_fusion_function_multisampling_03122013.R"))
113
  #source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_03182013.R"))
80 114
  
81 115
  
82 116
  ###################### START OF THE SCRIPT ########################
......
196 230
  names(list_param_runGAMFusion)<-c("list_index","clim_yearlist","sampling_obj","dst","var","y_var_name","out_prefix")
197 231
  #test<-mclapply(1:18, runGAMFusion,list_param=list_param_runGAMFusion,mc.preschedule=FALSE,mc.cores = 9)
198 232
  
233
  #MAKE IT GENERAL: for any method
234
  
199 235
  gam_fus_mod<-mclapply(1:length(sampling_obj$ghcn_data_day),list_param=list_param_runGAMFusion,runGAMFusion,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
200 236
  
201 237
  #gam_fus_mod<-mclapply(1:length(sampling_obj$ghcn_data_day),runGAMFusion,list_param_runGAMFusion,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
......
205 241
  t2<-proc.time()-t1
206 242
  writeLines(as.character(t2),con=log_file,sep="\n")
207 243
  #browser()
244
  
208 245
  ############### NOW RUN VALIDATION #########################
246
  #SIMPLIFY THIS PART: one call
209 247
  
210 248
  list_tmp<-vector("list",length(gam_fus_mod))
211 249
  for (i in 1:length(gam_fus_mod)){

Also available in: Unified diff