Project

General

Profile

« Previous | Next » 

Revision 0a5206c6

Added by Benoit Parmentier about 11 years ago

adding option for running every n days in a year and running kriging daily holdout 10%-70% every 2 days

View differences:

climate/research/oregon/interpolation/GAM_fusion_analysis_raster_prediction_multisampling.R
12 12
   # gam_daily, kriging_daily,gwr_daily,gam_CAI,gam_fusion,kriging_fusion,gwr_fusion and other options added.
13 13
#For multiple time scale methods, the interpolation is done first at the monthly time scale then delta surfaces are added.
14 14
#AUTHOR: Benoit Parmentier                                                                        
15
#DATE: 10/04/2013                                                                                 
15
#DATE: 10/11/2013                                                                                 
16 16
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#568--     
17 17
#
18 18
# TO DO:
......
162 162
  CRS_interp<-proj4string(ghcn)                       #Storing projection information (ellipsoid, datum,etc.)
163 163
  stat_loc<-readOGR(dsn=dirname(infile_locs),layer=sub(".shp","",basename(infile_locs)))
164 164
  #dates2 <-readLines(file.path(in_path,dates_selected)) #dates to be predicted, now read directly from the file
165
  
166
  #Should clean this up, reduce the number of if
165 167
  if (dates_selected==""){
166 168
    dates<-as.character(sort(unique(ghcn$date))) #dates to be predicted 
167 169
  }
168 170
  if (dates_selected!=""){
169 171
    dates<-dates_selected #dates to be predicted 
170 172
  }
171
  
173
  if(class(dates_selected)=="numeric"){ #select n every  observation, may change this later.
174
    dates<-as.character(sort(unique(ghcn$date))) #dates to be predicted 
175
    dates <- dates[seq(1, length(dates), dates_selected)]
176
  }
172 177
  #Reading in covariate brickcan be changed...
173 178
  
174 179
  s_raster<-brick(infile_covariates)                   #read in the data brck
......
298 303
    #test <- runGAM_day_fun(1,list_param_run_prediction_gam_daily)
299 304
    
300 305
    method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data),list_param=list_param_run_prediction_gam_daily,runGAM_day_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
301
    #method_mod_obj<-mclapply(1:11,list_param=list_param_run_prediction_gam_daily,runGAM_day_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
306
    #method_mod_obj<-mclapply(1:22,list_param=list_param_run_prediction_gam_daily,runGAM_day_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
302 307
    
303 308
    save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep="")))
304 309
    
......
310 315
    list_param_run_prediction_kriging_daily <-list(i,s_raster,covar_names,lst_avg,list_models,dst,var,y_var_name, sampling_obj,interpolation_method,out_prefix,out_path)
311 316
    names(list_param_run_prediction_kriging_daily)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","var","y_var_name","sampling_obj","interpolation_method","out_prefix","out_path")
312 317
    #test <- runKriging_day_fun(1,list_param_run_prediction_kriging_daily)
313
    method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data),list_param=list_param_run_prediction_kriging_daily,runKriging_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
318
    method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data),list_param=list_param_run_prediction_kriging_daily,runKriging_day_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
314 319
    #method_mod_obj<-mclapply(1:18,list_param=list_param_run_prediction_kriging_daily,runKriging_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
315 320
    
316 321
    save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep="")))
......
324 329
    names(list_param_run_prediction_gwr_daily)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","var","y_var_name","sampling_obj","interpolation_method","out_prefix","out_path")
325 330
    #test <- run_interp_day_fun(1,list_param_run_prediction_gwr_daily)
326 331
    method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data),list_param=list_param_run_prediction_gwr_daily,run_interp_day_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
327
    #method_mod_obj<-mclapply(1:9,list_param=list_param_run_prediction_gwr_daily,run_interp_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
332
    #method_mod_obj<-mclapply(1:22,list_param=list_param_run_prediction_gwr_daily,run_interp_day_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
328 333
    #method_mod_obj<-mclapply(1:18,list_param=list_param_run_prediction_kriging_daily,runKriging_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
329 334
    
330 335
    save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep="")))
climate/research/oregon/interpolation/master_script_temp.R
10 10
#STAGE 5: Output analyses: assessment of results for specific dates...
11 11
#
12 12
#AUTHOR: Benoit Parmentier                                                                       
13
#DATE: 10/10/2013                                                                                 
13
#DATE: 10/11/2013                                                                                 
14 14

  
15 15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568--   
16 16

  
......
58 58
#source(file.path(script_path,"download_and_produce_MODIS_LST_climatology_06112013.R"))
59 59
source(file.path(script_path,"covariates_production_temperatures_08052013.R"))
60 60
source(file.path(script_path,"Database_stations_covariates_processing_function_06112013.R"))
61
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_10042013.R"))
61
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_10112013.R"))
62 62
source(file.path(script_path,"results_interpolation_date_output_analyses_08052013.R"))
63 63
#source(file.path(script_path,"results_covariates_database_stations_output_analyses_04012013.R")) #to be completed
64 64

  
......
66 66

  
67 67
source(file.path(script_path,"sampling_script_functions_08252013.R"))
68 68
source(file.path(script_path,"GAM_fusion_function_multisampling_10042013.R")) #Includes Fusion and CAI methods
69
source(file.path(script_path,"interpolation_method_day_function_multisampling_07052013.R")) #Include GAM_day
69
source(file.path(script_path,"interpolation_method_day_function_multisampling_10112013.R")) #Include GAM_day
70 70
source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_10102013.R"))
71 71

  
72 72
#stages_to_run<-c(1,2,3,4,5) #May decide on antoher strategy later on...
......
80 80
#met_stations_outfiles_obj_file<-"met_stations_outfiles_obj_gam_CAI__365d_gam_CAI_lst_comb3_08252013.RData"
81 81

  
82 82
var<-"TMAX" # variable being interpolated
83
out_prefix<-"_365d_gam_cai_lst_comb3_10102013"                #User defined output prefix
84
#out_prefix<-"_365d_kriging_daily_mults1_lst_comb3_10102013"                #User defined output prefix
83
#out_prefix<-"_365d_gam_cai_lst_comb3_10102013"                #User defined output prefix
84
out_prefix<-"_365d_kriging_daily_mults1_lst_comb3_10112013"                #User defined output prefix
85 85

  
86
out_suffix<-"_OR_10102013"                                       #Regional suffix
86
out_suffix<-"_OR_10112013"                                       #Regional suffix
87 87
out_suffix_modis <-"_05302013"                       #pattern to find tiles produced previously     
88 88

  
89 89
#interpolation_method<-c("gam_fusion","gam_CAI","gam_daily") #other otpions to be added later
90
interpolation_method<-c("gam_CAI") #other otpions to be added later
90
#interpolation_method<-c("gam_CAI") #other otpions to be added later
91 91
#interpolation_method<-c("gam_fusion") #other otpions to be added later
92 92
#interpolation_method<-c("kriging_fusion") #other otpions to be added later
93 93
#interpolation_method<-c("gwr_fusion") #other otpions to be added later
......
95 95
#interpolation_method<-c("kriging_CAI") 
96 96

  
97 97
#interpolation_method<-c("gam_daily") #other otpions to be added later
98
#interpolation_method<-c("kriging_daily") #other otpions to be added later
98
interpolation_method<-c("kriging_daily") #other otpions to be added later
99 99
#interpolation_method<-c("gwr_daily") #other otpions to be added later
100 100

  
101 101
#out_path<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/output_data"
......
248 248
seed_number<- 100  #if seed zero then no seed?     
249 249

  
250 250
nb_sample<-1           #number of time random sampling must be repeated for every hold out proportion
251
step<-0         
251
step<- 0.1         
252 252
constant<-0             #if value 1 then use the same samples as date one for the all set of dates
253
prop_minmax<-c(0.3,0.3)  #if prop_min=prop_max and step=0 then predictions are done for the number of dates...
253
#prop_minmax<-c(0.3,0.3)  #if prop_min=prop_max and step=0 then predictions are done for the number of dates...
254
prop_minmax<-c(0.1,0.7)  #if prop_min=prop_max and step=0 then predictions are done for the number of dates...
254 255

  
255 256
seed_number_month <- 100
256 257
nb_sample_month <-1           #number of time random sampling must be repeated for every hold out proportion
......
261 262
#dates_selected<-c("20100101","20100102","20100103","20100901") # Note that the dates set must have a specific format: yyymmdd
262 263
#dates_selected<-c("20100101","20100102","20100301","20100302","20100501","20100502","20100701","20100702","20100901","20100902","20101101","20101102")
263 264
dates_selected<-"" # if empty string then predict for the full year specified earlier
265
dates_selected <- 2 # if empty string then predict for the full year specified earlier
266

  
264 267
screen_data_training<- FALSE #screen training data for NA and use same input training for all models fitted
265 268
use_clim_image <- TRUE # use predicted image as a base...rather than average Tmin at the station for delta
266 269
join_daily <- FALSE # join monthly and daily station before calucating delta
......
292 295
#           "y_var ~ s(lat,lon) + s(LST) + ti(LST,CANHGHT)")
293 296

  
294 297
#Combination 5: for paper baseline=s(lat,lon)+s(elev)
295
list_models<-c("y_var ~ s(lat,lon) + s(elev_s)",
296
                "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w)",
297
                "y_var ~ s(lat,lon) + s(elev_s) + s(LST)",
298
                "y_var ~ s(lat,lon) + s(elev_s) + s(DISTOC)",
299
                "y_var ~ s(lat,lon) + s(elev_s) + s(LC1)",
300
                "y_var ~ s(lat,lon) + s(elev_s) + s(CANHGHT)",
301
                "y_var ~ s(lat,lon) + s(elev_s) + s(LST) + ti(LST,LC1)")#,
302
                #"y_var ~ s(lat,lon) + s(elev_s) + s(LST) + ti(LST,CANHGHT)")
303

  
304
list_models2<-c("y_var ~ s(lat,lon) + s(DISTOC)")
305

  
306
interp_method2 <- "gam" #other options are "gwr" and "kriging"
298
#list_models<-c("y_var ~ s(lat,lon) + s(elev_s)",
299
#                "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w)",
300
#                "y_var ~ s(lat,lon) + s(elev_s) + s(LST)",
301
#                "y_var ~ s(lat,lon) + s(elev_s) + s(DISTOC)",
302
#                "y_var ~ s(lat,lon) + s(elev_s) + s(LC1)",
303
#                "y_var ~ s(lat,lon) + s(elev_s) + s(CANHGHT)",
304
#                "y_var ~ s(lat,lon) + s(elev_s) + s(LST) + ti(LST,LC1)")#,
305
#                #"y_var ~ s(lat,lon) + s(elev_s) + s(LST) + ti(LST,CANHGHT)")
306

  
307
#list_models2<-c("y_var ~ s(lat,lon) + s(DISTOC)")
308
list_models2 <- NULL
309
interp_method2 <- NULL #other options are "gwr" and "kriging"
310

  
311
#interp_method2 <- "gam" #other options are "gwr" and "kriging"
307 312
#list_models<-c("y_var ~ lat*lon + elev_s")
308 313

  
309 314
#list_models<-c("y_var ~ s(lat,lon) + s(elev_s)")
310 315

  
311
#list_models<-c("y_var ~ lat*lon + elev_s",
316
list_models<-c("y_var ~ lat*lon + elev_s") #,
312 317
#               "y_var ~ lat*lon + elev_s + N_w",
313 318
#               "y_var ~ lat*lon + elev_s + E_w",
314 319
#               "y_var ~ lat*lon + elev_s + LST",

Also available in: Unified diff