Revision a541eb58
Added by Benoit Parmentier over 8 years ago
climate/research/oregon/interpolation/global_run_scalingup_mosaicing_function.R | ||
---|---|---|
1343 | 1343 |
data_df <- list_param$data_df |
1344 | 1344 |
df_raster_pred_tiles <- list_param$df_raster_pred_tiles |
1345 | 1345 |
list_formulas <- list_param$list_formulas |
1346 |
use_autokrige <- list_param$use_autokrige |
|
1346 | 1347 |
NA_flag_val <- list_param$NA_flag_val |
1347 | 1348 |
file_format <- list_param$file_format |
1348 | 1349 |
out_dir_str <- list_param$out_dir_str |
... | ... | |
1360 | 1361 |
#create output name for predicted raster |
1361 | 1362 |
extension_str <- extension(inFilename) |
1362 | 1363 |
raster_name_tmp <- gsub(extension_str,"",basename(inFilename)) |
1363 |
out_filename <- file.path(out_dir,paste(raster_name_tmp,"_","kriged_residuals_",var_pred,"_",out_suffix,file_format,sep="")) #for use in function later...
|
|
1364 |
out_filename <- file.path(out_dir_str,paste(raster_name_tmp,"_","kriged_residuals_",var_pred,"_",out_suffix_str,file_format,sep="")) #for use in function later...
|
|
1364 | 1365 |
|
1365 | 1366 |
#tile_selected <- as.character(df_raster_pred_tiles$tile_id[j]) |
1366 | 1367 |
data_df$tile_id <- as.character(data_df$tile_id) |
... | ... | |
1412 | 1413 |
NA_flag_val <- list_param$NA_flag_val |
1413 | 1414 |
#NAflag,file_format,out_suffix etc... |
1414 | 1415 |
file_format <- list_param$file_format |
1415 |
out_dir_str <- list_param$out_dir |
|
1416 |
out_suffix_str <- list_param$out_suffix |
|
1416 |
out_dir_str <- list_param$out_dir_str
|
|
1417 |
out_suffix_str <- list_param$out_suffix_str
|
|
1417 | 1418 |
|
1418 | 1419 |
######## START SCRIPT ############### |
1419 | 1420 |
|
... | ... | |
1427 | 1428 |
#Now match the correct tiles with data used in kriging... |
1428 | 1429 |
#match the correct tile!!! df_tile_processed |
1429 | 1430 |
#pattern_str <- as.character(unique(df_tile_processed$tile_coord)) |
1431 |
|
|
1432 |
#check that all the rows are tile related (this is related to the bug of "output_test) |
|
1433 |
df_tile_processed_reg <- df_tile_processed_reg[!is.na(df_tile_processed_reg$shp_files),] |
|
1434 |
|
|
1430 | 1435 |
list_tile_coord <- as.character(df_tile_processed_reg$tile_coord) |
1431 | 1436 |
pattern_str <- glob2rx(paste("*",list_tile_coord,"*","*.tif",sep="")) |
1432 | 1437 |
keywords_str <- pattern_str |
1433 | 1438 |
tmp_str2 <-unlist(lapply(keywords_str,grep,lf_day_tiles,value=TRUE)) |
1434 |
df_raster_pred_tiles_tmp <- data.frame(files =tmp_str2, tile_coord=list_tile_coord) |
|
1439 |
list_coord_tf <- basename(dirname(dirname(tmp_str2))) |
|
1440 |
df_raster_pred_tiles_tmp <- data.frame(files =tmp_str2, tile_coord=list_coord_tf) |
|
1441 |
|
|
1442 |
#df_raster_pred_tiles_tmp <- data.frame(files =tmp_str2, tile_coord=list_tile_coord) |
|
1435 | 1443 |
df_raster_pred_tiles <- merge(df_raster_pred_tiles_tmp,df_tile_processed_reg,by="tile_coord") |
1436 | 1444 |
df_raster_pred_tiles$path_NEX <- as.character(df_raster_pred_tiles$path_NEX) |
1437 | 1445 |
df_raster_pred_tiles$reg <- basename(dirname(df_raster_pred_tiles$path_NEX)) |
... | ... | |
1449 | 1457 |
lf <- df_raster_pred_tiles$files |
1450 | 1458 |
|
1451 | 1459 |
##Make this loop a function later on, testing right now |
1452 |
list_param_generate_residuals_raster <- list(lf,var_pred,data_df,df_raster_pred_tiles,list_formulas,NA_flag_val,file_format,out_dir,out_suffix)
|
|
1453 |
names(list_param_generate_residuals_raster) <- c("lf","var_pred","data_df","df_raster_pred_tiles","list_formulas","NA_flag_val","file_format","out_dir","out_suffix")
|
|
1460 |
list_param_generate_residuals_raster <- list(lf,var_pred,data_df,df_raster_pred_tiles,list_formulas,use_autokrige,NA_flag_val,file_format,out_dir_str,out_suffix_str)
|
|
1461 |
names(list_param_generate_residuals_raster) <- c("lf","var_pred","data_df","df_raster_pred_tiles","list_formulas","use_autokrige","NA_flag_val","file_format","out_dir_str","out_suffix_str")
|
|
1454 | 1462 |
|
1455 | 1463 |
#debug(generate_residuals_raster) |
1456 |
#test_lf <- lapply(1,FUN=generate_residuals_raster,list_param=list_param_generate_residuals_raster)
|
|
1464 |
#test_lf <- lapply(3,FUN=generate_residuals_raster,list_param=list_param_generate_residuals_raster)
|
|
1457 | 1465 |
|
1458 | 1466 |
list_pred_res_obj <- mclapply(1:length(lf),FUN=generate_residuals_raster,list_param=list_param_generate_residuals_raster,mc.preschedule=FALSE,mc.cores = num_cores) |
1459 | 1467 |
## Add to df_raster_pred_tiles |
... | ... | |
1462 | 1470 |
#write output |
1463 | 1471 |
accuracy_residuals_obj <-list(list_pred_res_obj,data_df,df_raster_pred_tiles) |
1464 | 1472 |
names(accuracy_residuals_obj)<-c("list_pred_res_obj","data_df","df_raster_pred_tiles") |
1465 |
save(accuracy_residuals_obj,file= file.path(out_dir,paste("accuracy_residuals_obj_",date_processed,"_",var_pred, |
|
1473 |
save(accuracy_residuals_obj,file= file.path(out_dir_str,paste("accuracy_residuals_obj_",date_processed,"_",var_pred,
|
|
1466 | 1474 |
out_suffix_str,".RData",sep=""))) |
1467 | 1475 |
|
1468 | 1476 |
return(accuracy_residuals_obj) |
Also available in: Unified diff
fixing function to create mosaics of residuals