Project

General

Profile

« Previous | Next » 

Revision e63d760c

Added by Benoit Parmentier over 11 years ago

GAM fusion raster prediction, debugging of validation and change in passing of date parameter

View differences:

climate/research/oregon/interpolation/GAM_fusion_analysis_raster_prediction_multisampling.R
39 39
  
40 40
  ### Parameters and arguments
41 41
  #PARSING INPUTS/ARGUMENTS
42
  #list_param_data_prep<-c(infile_monthly,infile_daily,infile_locs,infile_covariates,covar_names,var,out_prefix,CRS_locs_WGS84)
43
  #list_param_raster_prediction<-c(list_param_data_prep,
44
  #                                seed_number,nb_sample,step,constant,prop_minmax,infile_dates,
45
  #                                list_models,lst_avg,in_path,out_path,script_path,
46
  #                                interpolation_method)
42
#   
43
#   names(list_param_raster_prediction)<-c("list_param_data_prep",
44
#                                          "seed_number","nb_sample","step","constant","prop_minmax","dates_selected",
45
#                                          "list_models","lst_avg","in_path","out_path","script_path",
46
#                                          "interpolation_method")
47 47
  
48 48
  #9 parameters used in the data preparation stage and input in the current script
49 49
  list_param_data_prep<-list_param_raster_prediction$list_param_data_prep
......
62 62
  step<-list_param_raster_prediction$step
63 63
  constant<-list_param_raster_prediction$constant
64 64
  prop_minmax<-list_param_raster_prediction$prop_minmax
65
  infile_dates<-list_param_raster_prediction$infile_dates
65
  dates_selected<-list_param_raster_prediction$dates_selected
66 66
  
67 67
  #6 additional parameters for monthly climatology and more
68 68
  list_models<-list_param_raster_prediction$list_models
......
114 114
  ghcn<-readOGR(dsn=in_path,layer=sub(".shp","",basename(infile_daily)))
115 115
  CRS_interp<-proj4string(ghcn)                       #Storing projection information (ellipsoid, datum,etc.)
116 116
  stat_loc<-readOGR(dsn=in_path,layer=sub(".shp","",basename(infile_locs)))
117
  dates <-readLines(file.path(in_path,infile_dates)) #dates to be predicted
117
  #dates2 <-readLines(file.path(in_path,dates_selected)) #dates to be predicted, now read directly from the file
118
  if (dates_selected==""){
119
    dates<-as.character(sort(unique(ghcn$date))) #dates to be predicted 
120
  }
121
  if (dates_selected!=""){
122
    dates<-dates_selected #dates to be predicted 
123
  }
118 124
  
119 125
  #Reading of covariate brick covariates can be changed...
120 126
  
......
147 153
  #list_param_sampling<-list(seed_number,nb_sample,step,constant,prop_minmax,dates,ghcn_name)
148 154
  names(list_param_sampling)<-c("seed_number","nb_sample","step","constant","prop_minmax","dates","ghcn")
149 155
  
150
  #run function
156
  #run function, note that dates must be a character vector!!
151 157
  sampling_obj<-sampling_training_testing(list_param_sampling)
152 158
  
153 159
  ########### PREDICT FOR MONTHLY SCALE  ##################
......
197 203
  save(gam_fus_mod,file= paste("gam_fus_mod",out_prefix,".RData",sep=""))
198 204
  t2<-proc.time()-t1
199 205
  writeLines(as.character(t2),con=log_file,sep="\n")
200
  browser()
206
  #browser()
201 207
  ############### NOW RUN VALIDATION #########################
202 208
  
203 209
  list_tmp<-vector("list",length(gam_fus_mod))
......
211 217
  t1<-proc.time()
212 218
  #calculate_accuary_metrics<-function(i)
213 219
  list_param_validation<-list(i,rast_day_yearlist,gam_fus_mod,y_var_name, out_prefix)
214
  names(list_param_validation)<-c("list_index","rast_day_year_list","gam_fus_mod","y_var_name","out_prefix")
220
  names(list_param_validation)<-c("list_index","rast_day_year_list","method_mod_obj","y_var_name","out_prefix") #same names for any method
215 221
  
216 222
  #gam_fus_validation_mod<-mclapply(1:length(gam_fus_mod), calculate_accuracy_metrics,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
217 223
  gam_fus_validation_mod<-mclapply(1:length(gam_fus_mod), list_param=list_param_validation, calculate_accuracy_metrics,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement

Also available in: Unified diff