Revision c8354a28
Added by Benoit Parmentier over 11 years ago
climate/research/oregon/interpolation/GAM_fusion_analysis_raster_prediction_multisampling.R | ||
---|---|---|
11 | 11 |
#5)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: 06/08/2013
|
|
14 |
#DATE: 07/16/2013
|
|
15 | 15 |
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#568-- |
16 | 16 |
# |
17 | 17 |
# TO DO: |
... | ... | |
35 | 35 |
#7)var: variable being interpolated-TMIN or TMAX |
36 | 36 |
#8)out_prefix |
37 | 37 |
#9)CRS_locs_WGS84 |
38 |
#10)screen_data_training |
|
38 | 39 |
# |
39 | 40 |
#6 parameters for sampling function |
40 | 41 |
#10)seed_number |
... | ... | |
89 | 90 |
var<-list_param_data_prep$var |
90 | 91 |
out_prefix<-list_param_data_prep$out_prefix |
91 | 92 |
CRS_locs_WGS84<-list_param_data_prep$CRS_locs_WGS84 |
93 |
|
|
92 | 94 |
|
93 | 95 |
#6 parameters for sampling function |
94 | 96 |
seed_number<-list_param_raster_prediction$seed_number |
... | ... | |
104 | 106 |
out_path<-list_param_raster_prediction$out_path |
105 | 107 |
script_path<-list_param_raster_prediction$script_path |
106 | 108 |
interpolation_method<-list_param_raster_prediction$interpolation_method |
109 |
screen_data_training <-list_param_raster_prediction$screen_data_training |
|
107 | 110 |
|
108 | 111 |
setwd(out_path) |
109 | 112 |
|
... | ... | |
112 | 115 |
if (var=="TMAX"){ |
113 | 116 |
y_var_name<-"dailyTmax" |
114 | 117 |
} |
118 |
|
|
115 | 119 |
if (var=="TMIN"){ |
116 | 120 |
y_var_name<-"dailyTmin" |
117 | 121 |
} |
... | ... | |
134 | 138 |
|
135 | 139 |
############### READING INPUTS: DAILY STATION DATA AND OTEHR DATASETS ################# |
136 | 140 |
|
137 |
ghcn<-readOGR(dsn=out_path,layer=sub(".shp","",basename(infile_daily)))
|
|
141 |
ghcn<-readOGR(dsn=dirname(infile_daily),layer=sub(".shp","",basename(infile_daily)))
|
|
138 | 142 |
CRS_interp<-proj4string(ghcn) #Storing projection information (ellipsoid, datum,etc.) |
139 |
stat_loc<-readOGR(dsn=out_path,layer=sub(".shp","",basename(infile_locs)))
|
|
143 |
stat_loc<-readOGR(dsn=dirname(infile_locs),layer=sub(".shp","",basename(infile_locs)))
|
|
140 | 144 |
#dates2 <-readLines(file.path(in_path,dates_selected)) #dates to be predicted, now read directly from the file |
141 | 145 |
if (dates_selected==""){ |
142 | 146 |
dates<-as.character(sort(unique(ghcn$date))) #dates to be predicted |
... | ... | |
151 | 155 |
names(s_raster)<-covar_names #Assigning names to the raster layers: making sure it is included in the extraction |
152 | 156 |
|
153 | 157 |
#Reading monthly data |
154 |
dst<-readOGR(dsn=out_path,layer=sub(".shp","",basename(infile_monthly)))
|
|
158 |
dst<-readOGR(dsn=dirname(infile_monthly),layer=sub(".shp","",basename(infile_monthly)))
|
|
155 | 159 |
|
156 | 160 |
########### CREATE SAMPLING -TRAINING AND TESTING STATIONS ########### |
157 | 161 |
|
... | ... | |
240 | 244 |
if (interpolation_method=="gam_daily"){ |
241 | 245 |
#input a list:note that ghcn.subsets is not sampling_obj$data_day_ghcn |
242 | 246 |
i<-1 |
243 |
list_param_run_prediction_gam_daily <-list(i,s_raster,covar_names,lst_avg,list_models,dst,var,y_var_name, sampling_obj,interpolation_method,out_prefix,out_path) |
|
244 |
names(list_param_run_prediction_gam_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") |
|
247 |
list_param_run_prediction_gam_daily <-list(i,s_raster,covar_names,lst_avg,list_models,dst,screen_data_training,var,y_var_name, sampling_obj,interpolation_method,out_prefix,out_path)
|
|
248 |
names(list_param_run_prediction_gam_daily)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","screen_data_training","var","y_var_name","sampling_obj","interpolation_method","out_prefix","out_path")
|
|
245 | 249 |
#test <- runGAM_day_fun(1,list_param_run_prediction_gam_daily) |
246 | 250 |
|
247 |
method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data_day),list_param=list_param_run_prediction_gam_daily,runGAM_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
|
|
248 |
#method_mod_obj<-mclapply(1:18,list_param=list_param_run_prediction_gam_daily,runGAM_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
|
|
251 |
method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data_day),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
|
|
252 |
#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
|
|
249 | 253 |
|
250 | 254 |
save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep=""))) |
251 | 255 |
|
... | ... | |
270 | 274 |
list_param_run_prediction_gwr_daily <-list(i,s_raster,covar_names,lst_avg,list_models,dst,var,y_var_name, sampling_obj,interpolation_method,out_prefix,out_path) |
271 | 275 |
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") |
272 | 276 |
#test <- run_interp_day_fun(1,list_param_run_prediction_gwr_daily) |
273 |
method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data_day),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
|
|
277 |
method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data_day),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
|
|
274 | 278 |
#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 |
275 | 279 |
#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 |
276 | 280 |
|
... | ... | |
340 | 344 |
save(raster_prediction_obj,file= file.path(out_path,paste("raster_prediction_obj_",interpolation_method,"_", y_var_name,out_prefix,".RData",sep=""))) |
341 | 345 |
|
342 | 346 |
} |
347 |
|
|
343 | 348 |
#use %in% instead of "|" operator |
344 | 349 |
if (interpolation_method=="gam_daily" | interpolation_method=="kriging_daily" | interpolation_method=="gwr_daily"){ |
345 | 350 |
raster_prediction_obj<-list(method_mod_obj,validation_mod_obj,tb_diagnostic_v, |
Also available in: Unified diff
raster prediction, modification for screening of training, runs by stage