Project

General

Profile

« Previous | Next » 

Revision 5adb2c5c

Added by Benoit Parmentier over 11 years ago

GAM fusion, modidified daily and monthly functions to pass explicitly multiple arguments

View differences:

climate/research/oregon/interpolation/GAM_fusion_function_multisampling.R
1
#Function to be used with GAM_fusion_analysis_raster_prediction_mutlisampling.R
2
#runClimFusion<-function(r_stack,data_training,data_testing,data_training){
1
##################  Functions for use in the raster prediction stage   #######################################
2
############################ Interpolation in a given tile/region ##########################################
3
#This script contains 5 functions used in the interpolation of temperature in the specfied study/processing area:                             
4
# 1)predict_raster_model<-function(in_models,r_stack,out_filename)                                                             
5
# 2)fit_models<-function(list_formulas,data_training)           
6
# 3)runClimCAI<-function(j) : not working yet
7
# 4)runClim_KGFusion<-function(j,list_param)
8
# 5)runGAMFusion <- function(i,list_param) 
9
#
10
#AUTHOR: Benoit Parmentier                                                                       
11
#DATE: 03/12/2013                                                                                 
12
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363--   
13

  
14
##Comments and TODO:
15
#This script is meant to be for general processing tile by tile or region by region.
16
# Note that the functions are called from GAM_fusion_analysis_raster_prediction_mutlisampling.R.
17
# This will be expanded to other methods.
18

  
19
##################################################################################################
3 20

  
4
#Functions used in the script
5 21

  
6 22
predict_raster_model<-function(in_models,r_stack,out_filename){
7 23
  #This functions performs predictions on a raster grid given input models.
......
131 147
}
132 148
#
133 149

  
134
runClim_KGFusion<-function(j){
150
runClim_KGFusion<-function(j,list_param){
135 151
  
136 152
  #Make this a function with multiple argument that can be used by mcmapply??
137
  #This creates clim fusion layers...
138
  #Parameters:
139
  
140
  #1)s_raster: brick of covariates   : could pass as argument only specific variables??
141
  #2)dst: monthly data (infile_monthly): could pass only the subset from the month??
142
  #3)list_models
143
  #4)brick names covarnames
144
  #5)out_prefix
145
  
153
  #Arguments: 
154
  #1)list_index: j 
155
  #2)covar_rast: covariates raster images used in the modeling
156
  #3)covar_names: names of input variables 
157
  #4)lst_avg: list of LST climatogy names, may be removed later on
158
  #5)list_models: list input models for bias calculation
159
  #6)dst: data at the monthly time scale
160
  #7)var: TMAX or TMIN, variable being interpolated
161
  #8)y_var_name: output name, not used at this stage
162
  #9)out_prefix
163
  #
164
  #The output is a list of four shapefile names produced by the function:
165
  #1) clim: list of output names for raster climatogies 
166
  #2) data_month: monthly training data for bias surface modeling
167
  #3) mod: list of model objects fitted 
168
  #4) formulas: list of formulas used in bias modeling
146 169
  
147
  ## STEP 1: PARSE PARAMETERS AND ARGUMENTS
170
  ### PARSING INPUT ARGUMENTS
171
  #list_param_runGAMFusion<-list(i,clim_yearlist,sampling_obj,var,y_var_name, out_prefix)
148 172
  
173
  index<-list_param$j
174
  s_raster<-list_param$covar_rast
175
  covar_names<-list_param$covar_names
176
  lst_avg<-list_param$lst_avg
177
  list_models<-list_param$list_models
178
  dst<-list_param$dst #monthly station dataset
179
  var<-list_param$var
180
  y_var_name<-list_param$y_var_name
181
  out_prefix<-list_param$out_prefix
182

  
149 183
  #Model and response variable can be changed without affecting the script
150 184
  prop_month<-0 #proportion retained for validation
151
  run_samp<-1
185
  run_samp<-1 #This option can be added later on if/when neeeded
152 186
  
153
  ## STEP 2: PREPARE DATA
187
  #### STEP 2: PREPARE DATA
154 188
  
155 189
  data_month<-dst[dst$month==j,] #Subsetting dataset for the relevant month of the date being processed
156 190
  LST_name<-lst_avg[j] # name of LST month to be matched
......
158 192
  
159 193
  #Adding layer LST to the raster stack  
160 194
  covar_rast<-s_raster
195
  #names(s_raster)<-covar_names
161 196
  pos<-match("LST",names(s_raster)) #Find the position of the layer with name "LST", if not present pos=NA
162 197
  s_raster<-dropLayer(s_raster,pos)      # If it exists drop layer
163 198
  LST<-subset(s_raster,LST_name)
......
250 285
runGAMFusion <- function(i,list_param) {            # loop over dates
251 286
    #### Change this to allow explicitly arguments...
252 287
  #Arguments: 
253
  #1)list of climatology files for all models...(12*nb of models)
254
  #2)sampling_obj$data_day_gcn: ghcn.subsets (data per date )
255
  #4)sampling_dat: list of sampling information for every run (proporation, month,sample)
256
  #5)ampling_index : list of training
257
  #6)dst: data at the monthly time scale
258
  #7)var:
259
  #8)y_var_name:
260
  #9)out_prefix
288
  #1)index: loop list index for individual run/fit
289
  #2)clim_year_list: list of climatology files for all models...(12*nb of models)
290
  #3)sampling_obj: contains, data per date/fit, sampling information
291
  #4)dst: data at the monthly time scale
292
  #5)var: variable predicted -TMAX or TMIN
293
  #6)y_var_name: name of the variable predicted - dailyTMax, dailyTMin
294
  #7)out_prefix
295
  #
296
  #The output is a list of four shapefile names produced by the function:
297
  #1) list_temp: y_var_name
298
  #2) rast_clim_list: list of files for temperature climatology predictions
299
  #3) delta: list of files for temperature delta predictions
300
  #4) data_s: training data
301
  #5) data_v: testing data
302
  #6) sampling_dat: sampling information for the current prediction (date,proportion of holdout and sample number)
303
  #7) mod_kr: kriging delta fit, field package model object
261 304
  
262 305
  ### PARSING INPUT ARGUMENTS
263 306
  

Also available in: Unified diff