Revision 5631506b
Added by Benoit Parmentier almost 9 years ago
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: 11/03/2013 |
|
15 |
#CREATED ON: 04/01/2013 |
|
16 |
#MODIFIED ON: 12/21/2015 |
|
16 | 17 |
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#568-- |
17 | 18 |
# |
18 | 19 |
# TO DO: |
... | ... | |
30 | 31 |
#5)infile_covariates: raster covariate brick, tif file |
31 | 32 |
#6)covar_names: covar_names #remove at a later stage... |
32 | 33 |
#7)var: variable being interpolated-TMIN or TMAX |
33 |
#8)out_prefix |
|
34 |
#8)out_prefix: output suffix added to files
|
|
34 | 35 |
#9)CRS_locs_WGS84 |
35 | 36 |
#10)screen_data_training |
36 | 37 |
# |
... | ... | |
47 | 48 |
#19)prop_minmax_month |
48 | 49 |
#20)dates_selected |
49 | 50 |
# |
50 |
#6 additional parameters for monthly climatology and more
|
|
51 |
#13 additional parameters for monthly climatology and more
|
|
51 | 52 |
#21)list_models: model formulas in character vector |
52 | 53 |
#22)lst_avg: LST climatology name in the brick of covariate--change later |
53 |
#23)n_path |
|
54 |
#24)out_path |
|
54 |
#23)in_path |
|
55 |
#24)out_path: path to directory containing daily data |
|
56 |
#25)out_path_clim: path to the directory containing climatology data |
|
55 | 57 |
#25)script_path: path to script |
56 | 58 |
#26)interpolation_method: c("gam_fusion","gam_CAI") #other otpions to be added later |
57 | 59 |
#27) use_clim_image |
58 | 60 |
#28) join_daily |
59 | 61 |
#29)list_models2: models' formulas as string vector for daily devation |
60 | 62 |
#30)interp_method2: intepolation method for daily devation step |
63 |
#31)num_cores: How many cores to use |
|
64 |
#32)max_mem: Max memory to use for predict step |
|
65 |
#33)reg_outline: shapefile with region outline used to create nc output file |
|
61 | 66 |
|
62 | 67 |
###Loading R library and packages |
63 | 68 |
|
... | ... | |
118 | 123 |
interp_method2 <- list_param_raster_prediction$interp_method2 |
119 | 124 |
|
120 | 125 |
lst_avg<-list_param_raster_prediction$lst_avg |
121 |
out_path<-list_param_raster_prediction$out_path |
|
126 |
out_path<-list_param_raster_prediction$out_path #daily prediction path |
|
127 |
out_path_clim <- list_param_raster_prediction$out_path_clim #clim prediction path |
|
122 | 128 |
script_path<-list_param_raster_prediction$script_path |
123 | 129 |
interpolation_method<-list_param_raster_prediction$interpolation_method |
124 | 130 |
screen_data_training <-list_param_raster_prediction$screen_data_training |
125 | 131 |
|
126 | 132 |
use_clim_image <- list_param_raster_prediction$use_clim_image # use predicted image as a base...rather than average Tmin at the station for delta |
127 | 133 |
join_daily <- list_param_raster_prediction$join_daily # join monthly and daily station before calucating delta |
128 |
|
|
129 |
setwd(out_path) |
|
134 |
|
|
135 |
#cores and memory usage options |
|
136 |
num_cores <- list_param_raster_prediction$num_cores |
|
137 |
max_mem<- as.numeric(list_param_raster_prediction$max_mem) |
|
138 |
|
|
139 |
#Get the region outline |
|
140 |
reg_outline<-list_param_raster_prediction$reg_outline |
|
141 |
|
|
142 |
#rasterOptions(maxmemory=max_mem,timer=TRUE,chunksize=1e+08) |
|
143 |
rasterOptions(timer=TRUE,chunksize=5e+05) |
|
144 |
#rasterOptions(timer=TRUE) |
|
145 |
|
|
146 |
setwd(out_path) #note that this is now path to daily dir (with the name of the year...) |
|
130 | 147 |
|
131 | 148 |
###################### START OF THE SCRIPT ######################## |
132 | 149 |
|
... | ... | |
156 | 173 |
cat("Starting script process time:",file=log_fname,sep="\n",append=TRUE) |
157 | 174 |
cat(as.character(time1),file=log_fname,sep="\n",append=TRUE) |
158 | 175 |
|
176 |
############### Make nc file from outline ############ |
|
177 |
|
|
178 |
|
|
159 | 179 |
############### READING INPUTS: DAILY STATION DATA AND OTHER DATASETS ################# |
180 |
#Takes too long to read shapefiles. Let's try using saveRDS(object,*.rds) and readRDS() |
|
181 |
infile_daily_rds <-sub(".shp",".rds",infile_daily) |
|
182 |
|
|
183 |
if (file.exists(infile_daily_rds) == TRUE){ |
|
184 |
ghcn<-readRDS(infile_daily_rds) |
|
185 |
CRS_interp<-proj4string(ghcn) |
|
186 |
}else{ |
|
187 |
ghcn<-readOGR(dsn=dirname(infile_daily),layer=sub(".shp","",basename(infile_daily))) |
|
188 |
CRS_interp<-proj4string(ghcn) #Storing projection information (ellipsoid, datum,etc.) |
|
189 |
saveRDS(ghcn,infile_daily_rds) |
|
190 |
} |
|
191 |
|
|
192 |
infile_locs_rds<-sub(".shp",".rds",infile_locs) |
|
193 |
if (file.exists(infile_locs_rds) == TRUE){ |
|
194 |
stat_loc<-readRDS(infile_locs_rds) |
|
195 |
}else{ |
|
196 |
stat_loc<-readOGR(dsn=dirname(infile_locs),layer=sub(".shp","",basename(infile_locs))) |
|
197 |
saveRDS(stat_loc,infile_locs_rds) |
|
198 |
} |
|
160 | 199 |
|
161 |
ghcn<-readOGR(dsn=dirname(infile_daily),layer=sub(".shp","",basename(infile_daily))) |
|
162 |
CRS_interp<-proj4string(ghcn) #Storing projection information (ellipsoid, datum,etc.) |
|
163 |
stat_loc<-readOGR(dsn=dirname(infile_locs),layer=sub(".shp","",basename(infile_locs))) |
|
164 |
#dates2 <-readLines(file.path(in_path,dates_selected)) #dates to be predicted, now read directly from the file |
|
200 |
#dates2 <-readLines(file.path(in_path,dates_selected)) #dates to be predicted, now read directly from the file |
|
165 | 201 |
|
166 | 202 |
#Should clean this up, reduce the number of if |
167 | 203 |
if (dates_selected==""){ |
... | ... | |
180 | 216 |
names(s_raster)<-covar_names #Assigning names to the raster layers: making sure it is included in the extraction |
181 | 217 |
|
182 | 218 |
#Reading monthly data |
183 |
dst<-readOGR(dsn=dirname(infile_monthly),layer=sub(".shp","",basename(infile_monthly))) |
|
184 |
|
|
219 |
infile_monthly_rds<-sub(".shp",".rds",infile_monthly) |
|
220 |
if (file.exists(infile_monthly_rds) == TRUE) { |
|
221 |
dst<-readRDS(infile_monthly_rds) |
|
222 |
}else{ |
|
223 |
dst<-readOGR(dsn=dirname(infile_monthly),layer=sub(".shp","",basename(infile_monthly))) |
|
224 |
saveRDS(dst,infile_monthly_rds) |
|
225 |
} |
|
226 |
|
|
185 | 227 |
#construct date based on input end_year !!! |
186 | 228 |
day_tmp <- rep("15",length=nrow(dst)) |
187 | 229 |
year_tmp <- rep(as.character(end_year),length=nrow(dst)) |
... | ... | |
210 | 252 |
|
211 | 253 |
sampling_month_obj <- sampling_training_testing(list_param_sampling) |
212 | 254 |
|
255 |
#save(sampling_month_obj,file="/nobackupp4/aguzman4/climateLayers/output10Deg/reg1/35.0_-115.0/test.RData") |
|
256 |
|
|
213 | 257 |
########### PREDICT FOR MONTHLY SCALE ################## |
214 |
|
|
215 | 258 |
#First predict at the monthly time scale: climatology |
216 | 259 |
cat("Predictions at monthly scale:",file=log_fname,sep="\n", append=TRUE) |
217 | 260 |
cat(paste("Local Date and Time: ",as.character(Sys.time()),sep=""), |
218 | 261 |
file=log_fname,sep="\n") |
219 | 262 |
t1<-proc.time() |
220 | 263 |
j=12 |
264 |
|
|
265 |
###Changes 12/21/2015 |
|
221 | 266 |
#browser() #Missing out_path for gam_fusion list param!!! |
222 | 267 |
#if (interpolation_method=="gam_fusion"){ |
223 | 268 |
if (interpolation_method %in% c("gam_fusion","kriging_fusion","gwr_fusion")){ |
224 |
list_param_runClim_KGFusion<-list(j,s_raster,covar_names,lst_avg,list_models,dst,sampling_month_obj,var,y_var_name, out_prefix,out_path) |
|
225 |
names(list_param_runClim_KGFusion)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","sampling_month_obj","var","y_var_name","out_prefix","out_path") |
|
226 |
#debug(runClim_KGFusion) |
|
227 |
#test<-runClim_KGFusion(1,list_param=list_param_runClim_KGFusion) |
|
228 |
clim_method_mod_obj<-mclapply(1:length(sampling_month_obj$ghcn_data), list_param=list_param_runClim_KGFusion, runClim_KGFusion,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement |
|
229 |
save(clim_method_mod_obj,file= file.path(out_path,paste(interpolation_method,"_mod_",y_var_name,out_prefix,".RData",sep=""))) |
|
230 |
#Use function to extract list |
|
269 |
clim_method_mod_obj_file <- file.path(out_path_clim,paste(interpolation_method,"_mod_",y_var_name,out_prefix,".RData",sep="")) |
|
270 |
if(!file.exists(clim_method_mod_obj_file)){ |
|
271 |
list_param_runClim_KGFusion<-list(j,s_raster,covar_names,lst_avg,list_models,dst,sampling_month_obj,var,y_var_name, out_prefix,out_path) |
|
272 |
names(list_param_runClim_KGFusion)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","sampling_month_obj","var","y_var_name","out_prefix","out_path") |
|
273 |
#debug(runClim_KGFusion) |
|
274 |
#test<-runClim_KGFusion(1,list_param=list_param_runClim_KGFusion) |
|
275 |
clim_method_mod_obj<-mclapply(1:length(sampling_month_obj$ghcn_data), list_param=list_param_runClim_KGFusion, runClim_KGFusion,mc.preschedule=FALSE,mc.cores = num_cores) #This is the end bracket from mclapply(...) statement |
|
276 |
|
|
277 |
save(clim_method_mod_obj,file= file.path(out_path,paste(interpolation_method,"_mod_",y_var_name,out_prefix,".RData",sep=""))) |
|
278 |
#Use function to extract list |
|
279 |
}else{ |
|
280 |
clim_method_mod_obj <- load_obj(clim_method_mod_obj_file) #load the existing file |
|
281 |
} |
|
282 |
#Get relevant data |
|
231 | 283 |
list_tmp<-vector("list",length(clim_method_mod_obj)) |
284 |
|
|
232 | 285 |
for (i in 1:length(clim_method_mod_obj)){ |
233 | 286 |
tmp<-clim_method_mod_obj[[i]]$clim |
234 | 287 |
list_tmp[[i]]<-tmp |
235 | 288 |
} |
289 |
|
|
236 | 290 |
clim_yearlist<-list_tmp |
237 | 291 |
} |
238 | 292 |
|
239 | 293 |
if (interpolation_method %in% c("gam_CAI","kriging_CAI", "gwr_CAI")){ |
240 |
list_param_runClim_KGCAI<-list(j,s_raster,covar_names,lst_avg,list_models,dst,sampling_month_obj,var,y_var_name, out_prefix,out_path) |
|
241 |
names(list_param_runClim_KGCAI)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","sampling_month_obj","var","y_var_name","out_prefix","out_path") |
|
242 |
clim_method_mod_obj<-mclapply(1:length(sampling_month_obj$ghcn_data), list_param=list_param_runClim_KGCAI, runClim_KGCAI,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement |
|
243 |
#test<-runClim_KGCAI(1,list_param=list_param_runClim_KGCAI) |
|
244 |
save(clim_method_mod_obj,file= file.path(out_path,paste(interpolation_method,"_mod_",y_var_name,out_prefix,".RData",sep=""))) |
|
294 |
clim_method_mod_obj_file <- file.path(out_path_clim,paste(interpolation_method,"_mod_",y_var_name,out_prefix,".RData",sep="")) |
|
295 |
if(!file.exists(clim_method_mod_obj_file)){ |
|
296 |
num_cores2 = as.integer(num_cores) + 2 |
|
297 |
list_param_runClim_KGCAI<-list(j,s_raster,covar_names,lst_avg,list_models,dst,sampling_month_obj,var,y_var_name, out_prefix,out_path) |
|
298 |
names(list_param_runClim_KGCAI)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","sampling_month_obj","var","y_var_name","out_prefix","out_path") |
|
299 |
clim_method_mod_obj<-mclapply(1:length(sampling_month_obj$ghcn_data), list_param=list_param_runClim_KGCAI, runClim_KGCAI,mc.preschedule=FALSE,mc.cores = num_cores2) #This is the end bracket from mclapply(...) statement |
|
300 |
#test<-runClim_KGCAI(1,list_param=list_param_runClim_KGCAI) |
|
301 |
|
|
302 |
save(clim_method_mod_obj,file= file.path(out_path,paste(interpolation_method,"_mod_",y_var_name,out_prefix,".RData",sep=""))) |
|
303 |
}else{ |
|
304 |
clim_method_mod_obj <- load_obj(clim_method_mod_obj_file) #load the existing file |
|
305 |
} |
|
306 |
#Now get relevant data |
|
245 | 307 |
list_tmp<-vector("list",length(clim_method_mod_obj)) |
246 | 308 |
for (i in 1:length(clim_method_mod_obj)){ |
247 | 309 |
tmp<-clim_method_mod_obj[[i]]$clim |
... | ... | |
251 | 313 |
} |
252 | 314 |
t2<-proc.time()-t1 |
253 | 315 |
cat(as.character(t2),file=log_fname,sep="\n", append=TRUE) |
316 |
|
|
317 |
#Getting rid of raster temp files |
|
318 |
removeTmpFiles(h=0) |
|
319 |
|
|
254 | 320 |
|
255 | 321 |
################## PREDICT AT DAILY TIME SCALE ################# |
256 | 322 |
#Predict at daily time scale from single time scale or multiple time scale methods: 2 methods availabe now |
257 |
|
|
258 | 323 |
#put together list of clim models per month... |
259 | 324 |
#rast_clim_yearlist<-list_tmp |
260 | 325 |
|
261 | 326 |
#Second predict at the daily time scale: delta |
262 | 327 |
|
263 | 328 |
#method_mod_obj<-mclapply(1:1, runGAMFusion,mc.preschedule=FALSE,mc.cores = 1) #This is the end bracket from mclapply(...) statement |
329 |
|
|
330 |
#Set raster options for daily steps |
|
331 |
#rasterOptions(timer=TRUE,chunksize=1e+05) |
|
332 |
#This is for high station count areas |
|
333 |
rasterOptions(timer=TRUE,chunksize=1e+04) |
|
334 |
#rasterOptions(timer=TRUE,chunksize=1e+03) |
|
335 |
|
|
264 | 336 |
cat("Predictions at the daily scale:",file=log_fname,sep="\n", append=TRUE) |
265 | 337 |
t1<-proc.time() |
266 | 338 |
cat(paste("Local Date and Time: ",as.character(Sys.time()),sep=""), |
... | ... | |
289 | 361 |
#test <- run_prediction_daily_deviation(1,list_param=list_param_run_prediction_daily_deviation) #This is the end bracket from mclapply(...) statement |
290 | 362 |
#test <- mclapply(1:9,list_param=list_param_run_prediction_daily_deviation,run_prediction_daily_deviation,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement |
291 | 363 |
|
292 |
method_mod_obj<-mclapply(1:nrow(daily_dev_sampling_dat),list_param=list_param_run_prediction_daily_deviation,run_prediction_daily_deviation,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
|
|
364 |
method_mod_obj<-mclapply(1:nrow(daily_dev_sampling_dat),list_param=list_param_run_prediction_daily_deviation,run_prediction_daily_deviation,mc.preschedule=FALSE,mc.cores = num_cores) #This is the end bracket from mclapply(...) statement
|
|
293 | 365 |
save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep=""))) |
294 | 366 |
|
295 | 367 |
} |
296 | 368 |
|
369 |
removeTmpFiles(h=0) |
|
370 |
|
|
297 | 371 |
#TODO : Same call for all functions!!! Replace by one "if" for all daily single time scale methods... |
298 | 372 |
if (interpolation_method=="gam_daily"){ |
299 | 373 |
#input a list:note that ghcn.subsets is not sampling_obj$data_day_ghcn |
... | ... | |
302 | 376 |
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") |
303 | 377 |
#test <- runGAM_day_fun(1,list_param_run_prediction_gam_daily) |
304 | 378 |
|
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
|
|
379 |
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 = num_cores) #This is the end bracket from mclapply(...) statement
|
|
306 | 380 |
#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 |
307 | 381 |
|
308 | 382 |
save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep=""))) |
... | ... | |
315 | 389 |
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) |
316 | 390 |
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") |
317 | 391 |
#test <- runKriging_day_fun(1,list_param_run_prediction_kriging_daily) |
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
|
|
392 |
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 = num_cores) #This is the end bracket from mclapply(...) statement
|
|
319 | 393 |
#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 |
320 | 394 |
|
321 | 395 |
save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep=""))) |
... | ... | |
328 | 402 |
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) |
329 | 403 |
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") |
330 | 404 |
#test <- run_interp_day_fun(1,list_param_run_prediction_gwr_daily) |
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
|
|
405 |
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 = num_cores) #This is the end bracket from mclapply(...) statement
|
|
332 | 406 |
#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 |
333 | 407 |
#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 |
334 | 408 |
|
... | ... | |
341 | 415 |
|
342 | 416 |
############### NOW RUN VALIDATION ######################### |
343 | 417 |
#SIMPLIFY THIS PART: one call |
344 |
|
|
345 | 418 |
cat("Validation step:",file=log_fname,sep="\n", append=TRUE) |
346 | 419 |
t1<-proc.time() |
347 | 420 |
cat(paste("Local Date and Time: ",as.character(Sys.time()),sep=""), |
... | ... | |
361 | 434 |
#debug(calculate_accuracy_metrics) |
362 | 435 |
#test_val2 <-calculate_accuracy_metrics(1,list_param_validation) |
363 | 436 |
|
364 |
validation_mod_obj <-mclapply(1:length(method_mod_obj), list_param=list_param_validation, calculate_accuracy_metrics,mc.preschedule=FALSE,mc.cores = 9)
|
|
437 |
validation_mod_obj <-mclapply(1:length(method_mod_obj), list_param=list_param_validation, calculate_accuracy_metrics,mc.preschedule=FALSE,mc.cores = num_cores)
|
|
365 | 438 |
save(validation_mod_obj,file= file.path(out_path,paste(interpolation_method,"_validation_mod_obj_",y_var_name,out_prefix,".RData",sep=""))) |
366 | 439 |
t2<-proc.time()-t1 |
367 | 440 |
cat(as.character(t2),file=log_fname,sep="\n", append=TRUE) |
368 | 441 |
} |
369 | 442 |
|
370 | 443 |
### Run monthly validation if multi-time scale methods and add information to daily... |
371 |
|
|
372 | 444 |
if (interpolation_method %in% c("gam_CAI","kriging_CAI","gwr_CAI","gam_fusion","kriging_fusion","gwr_fusion")){ |
373 | 445 |
multi_time_scale <- TRUE |
374 | 446 |
i<-1 |
... | ... | |
385 | 457 |
#debug(calculate_accuracy_metrics) |
386 | 458 |
#test_val2 <-calculate_accuracy_metrics(1,list_param_validation) |
387 | 459 |
|
388 |
validation_mod_obj <-mclapply(1:length(method_mod_obj), list_param=list_param_validation, calculate_accuracy_metrics,mc.preschedule=FALSE,mc.cores = 9)
|
|
460 |
validation_mod_obj <-mclapply(1:length(method_mod_obj), list_param=list_param_validation, calculate_accuracy_metrics,mc.preschedule=FALSE,mc.cores = num_cores)
|
|
389 | 461 |
save(validation_mod_obj,file= file.path(out_path,paste(interpolation_method,"_validation_mod_obj_",y_var_name,out_prefix,".RData",sep=""))) |
390 | 462 |
|
391 | 463 |
### monthly time scale |
... | ... | |
403 | 475 |
#debug(calculate_accuracy_metrics) |
404 | 476 |
#test_val2 <-calculate_accuracy_metrics(1,list_param_validation_month) |
405 | 477 |
|
406 |
validation_mod_month_obj <- mclapply(1:length(clim_method_mod_obj), list_param=list_param_validation_month, calculate_accuracy_metrics,mc.preschedule=FALSE,mc.cores = 6)
|
|
478 |
validation_mod_month_obj <- mclapply(1:length(clim_method_mod_obj), list_param=list_param_validation_month, calculate_accuracy_metrics,mc.preschedule=FALSE,mc.cores = num_cores)
|
|
407 | 479 |
#test_val<-calculate_accuracy_metrics(1,list_param_validation) |
408 | 480 |
save(validation_mod_month_obj,file= file.path(out_path,paste(interpolation_method,"_validation_mod_month_obj_",y_var_name,out_prefix,".RData",sep=""))) |
409 | 481 |
|
... | ... | |
417 | 489 |
tb_month_diagnostic_s$method_interp <- interpolation_method #add type of interpolation...out_prefix too?? |
418 | 490 |
|
419 | 491 |
} |
492 |
|
|
493 |
#Cleaning raster temp files |
|
494 |
removeTmpFiles(h=0) |
|
495 |
|
|
420 | 496 |
#################### ASSESSMENT OF PREDICTIONS: PLOTS OF ACCURACY METRICS ########### |
421 |
|
|
422 | 497 |
##Create data.frame with validation and fit metrics for a full year/full numbe of runs |
423 | 498 |
tb_diagnostic_v<-extract_from_list_obj(validation_mod_obj,"metrics_v") |
424 | 499 |
#tb_diagnostic_v contains accuracy metrics for models sample and proportion for every run...if full year then 365 rows maximum |
... | ... | |
448 | 523 |
|
449 | 524 |
################### PREPARE RETURN OBJECT ############### |
450 | 525 |
#Will add more information to be returned |
451 |
|
|
452 | 526 |
if (interpolation_method %in% c("gam_CAI","kriging_CAI","gwr_CAI","gam_fusion","kriging_fusion","gwr_fusion")){ |
453 | 527 |
raster_prediction_obj<-list(clim_method_mod_obj,method_mod_obj,validation_mod_obj,validation_mod_month_obj, tb_diagnostic_v, |
454 | 528 |
tb_diagnostic_s,tb_month_diagnostic_v,tb_month_diagnostic_s,summary_metrics_v,summary_month_metrics_v) |
... | ... | |
467 | 541 |
save(raster_prediction_obj,file= file.path(out_path,paste("raster_prediction_obj_",interpolation_method,"_", y_var_name,out_prefix,".RData",sep=""))) |
468 | 542 |
|
469 | 543 |
} |
470 |
|
|
544 |
|
|
471 | 545 |
return(raster_prediction_obj) |
472 | 546 |
} |
473 | 547 |
|
474 | 548 |
#################################################################### |
475 |
######################## END OF SCRIPT/FUNCTION ##################### |
|
549 |
######################## END OF SCRIPT/FUNCTION ##################### |
Also available in: Unified diff
raster prediction stage modification of gam fusion script to take into acccount the existence of climatology layers