Revision 3f6f5b88
Added by Benoit Parmentier almost 9 years ago
climate/research/oregon/interpolation/global_run_scalingup_mosaicing.R | ||
---|---|---|
5 | 5 |
#Analyses, figures, tables and data are also produced in the script. |
6 | 6 |
#AUTHOR: Benoit Parmentier |
7 | 7 |
#CREATED ON: 04/14/2015 |
8 |
#MODIFIED ON: 12/19/2015
|
|
8 |
#MODIFIED ON: 12/20/2015
|
|
9 | 9 |
#Version: 5 |
10 | 10 |
#PROJECT: Environmental Layers project |
11 | 11 |
#COMMENTS: analyses run for reg4 1992 for test of mosaicing using 1500x4500km and other tiles |
... | ... | |
307 | 307 |
#r1 <- raster(lf_mosaic[[1]][1]) |
308 | 308 |
#list_create_accuracy_residuals_raster_obj |
309 | 309 |
|
310 |
##Run for data_day_s |
|
311 |
## |
|
312 |
data_df <- data_day_s # data.frame table/spdf containing stations with residuals and variable |
|
313 |
|
|
314 |
num_cores_tmp <-num_cores |
|
315 |
lf_day_tiles <- lf_mosaic #list of raster files by dates |
|
316 |
#data_df <- data_day_v # data.frame table/spdf containing stations with residuals and variable |
|
317 |
#df_tile_processed #tiles processed during assessment usually by region |
|
318 |
#var_pred #variable being modeled |
|
319 |
#if not list of models is provided generate one |
|
320 |
if(is.null(list_models)){ |
|
321 |
list_models <- paste(var_pred,"~","1",sep=" ") |
|
322 |
} |
|
323 |
|
|
324 |
#use_autokrige #if TRUE use automap/gstat package |
|
325 |
#y_var_name #"dailyTmax" #PARAM2 |
|
326 |
#interpolation_method #c("gam_CAI") #PARAM3, need to select reg!! |
|
327 |
#date_processed #can be a monthly layer |
|
328 |
#num_cores #number of cores used |
|
329 |
#NA_flag_val |
|
330 |
#file_format |
|
331 |
out_dir_str <- out_dir |
|
332 |
out_suffix_str <- paste("data_day_s_",out_suffix,sep="") |
|
333 |
days_to_process <- day_to_mosaic |
|
334 |
df_tile_processed$path_NEX <- as.character(df_tile_processed$path_NEX) |
|
335 |
df_tile_processed$reg <- basename(dirname(df_tile_processed$path_NEX)) |
|
336 |
|
|
337 |
##By regions, selected earlier |
|
338 |
#for(k in 1:length(region_names)){ |
|
339 |
df_tile_processed_reg <- subset(df_tile_processed,reg==region_selected)#use reg4 |
|
340 |
#i<-1 #loop by days/date to process!! |
|
341 |
#test on the first day |
|
342 |
list_param_create_accuracy_residuals_raster <- list(lf_day_tiles,data_df,df_tile_processed_reg, |
|
343 |
var_pred,list_models,use_autokrige,y_var_name,interpolation_method, |
|
344 |
days_to_process,num_cores_tmp,NA_flag_val,file_format,out_dir_str, |
|
345 |
out_suffix_str) |
|
346 |
names(list_param_create_accuracy_residuals_raster) <- c("lf_day_tiles","data_df","df_tile_processed_reg", |
|
347 |
"var_pred","list_models","use_autokrige","y_var_name","interpolation_method", |
|
348 |
"days_to_process","num_cores_tmp","NA_flag_val","file_format","out_dir_str", |
|
349 |
"out_suffix_str") |
|
350 |
|
|
351 |
list_create_accuracy_residuals_raster_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_residuals_raster, |
|
352 |
list_param=list_param_create_accuracy_residuals_raster) |
|
353 |
|
|
354 |
#undebug(create_accuracy_residuals_raster) |
|
355 |
#list_create_accuracy_residuals_raster_obj <- lapply(1:1,FUN=create_accuracy_residuals_raster, |
|
356 |
# list_param=list_param_create_accuracy_residuals_raster) |
|
357 |
|
|
358 |
#create_accuracy_residuals_raster_obj <- create_accuracy_metric_raster(1, list_param_create_accuracy_residuals_raster_obj) |
|
359 |
|
|
360 |
#note that three tiles did not produce a residuals surface!!! find out more later, join the output |
|
361 |
#to df_raste_tile to keep track of which one did not work... |
|
362 |
#lf_accuracy_residuals_raster <- as.character(unlist(lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name"))},x=list_create_accuracy_residuals_raster_obj))) |
|
363 |
lf_accuracy_residuals_data_s_raster <- lapply(1:length(list_create_accuracy_residuals_raster_obj),FUN=function(i,x){as.character(unlist(extract_from_list_obj(x[[i]]$list_pred_res_obj,"raster_name")))},x=list_create_accuracy_residuals_raster_obj) |
|
364 |
|
|
365 |
##took 31 minutes to generate the residuals maps for each tiles (28) for region 4 |
|
366 |
|
|
310 | 367 |
###################################################### |
311 | 368 |
#### PART 2: GENETATE MOSAIC FOR LIST OF FILES ##### |
312 | 369 |
################################# |
... | ... | |
361 | 418 |
list_mosaic_obj[[i]] <- list(prediction=mosaic_edge_obj_prediction,accuracy=mosaic_edge_obj_accuracy) |
362 | 419 |
|
363 | 420 |
### produce residuals mosaics |
421 |
#for now add data_day_s in the name!! |
|
364 | 422 |
mosaic_method <- "use_edge_weights" #this is distance from edge |
365 |
out_suffix_tmp <- paste(interpolation_method,"kriged_residuals",day_to_mosaic[i],out_suffix,sep="_") |
|
423 |
out_suffix_tmp <- paste(interpolation_method,"kriged_residuals","data_day_s",day_to_mosaic[i],out_suffix,sep="_")
|
|
366 | 424 |
#lf_tmp<-list.files(pattern="*kriged_residuals.*.tif",full.names=T) |
367 | 425 |
lf_tmp <- lf_accuracy_residuals_raster[[i]] |
368 | 426 |
#lf_accuracy_residuals_raster[[i]] |
Also available in: Unified diff
producing residuals kriged surface for testing using training data