Revision 71539f11
Added by Benoit Parmentier over 10 years ago
climate/research/oregon/interpolation/global_run_scalingup_assessment_part1.R | ||
---|---|---|
5 | 5 |
#Part 1 create summary tables and inputs for figure in part 2 and part 3. |
6 | 6 |
#AUTHOR: Benoit Parmentier |
7 | 7 |
#CREATED ON: 03/23/2014 |
8 |
#MODIFIED ON: 05/29/2014
|
|
8 |
#MODIFIED ON: 06/19/2014
|
|
9 | 9 |
#Version: 3 |
10 | 10 |
#PROJECT: Environmental Layers project |
11 | 11 |
#TO DO: |
... | ... | |
232 | 232 |
|
233 | 233 |
pred_data_day_info$method_interp <- rep(method_interp,nrow(pred_data_day_info)) |
234 | 234 |
pred_data_day_info$var_interp <- rep(var_interp,nrow(pred_data_day_info)) |
235 |
pred_data_day_info$tile_id <- rep(tile_id,nrow(pred_data_day_info)) |
|
236 |
|
|
237 |
#pred_data_day_s_info$method_interp <- rep(method_interp,nrow(pred_data_day_s_info)) |
|
238 |
#pred_data_day_s_info$var_interp <- rep(var_interp,nrow(pred_data_day_s_info)) |
|
239 |
#pred_data_day_s_info$tile_id <- rep(tile_id,nrow(pred_data_day_s_info)) |
|
240 |
#pred_data_day_v_info <- do.call(rbind,list_pred_data_day_v_info) |
|
241 |
#pred_data_day_v_info$method_interp <- rep(method_interp,nrow(pred_data_day_v_info)) |
|
242 |
#pred_data_day_v_info$var_interp <- rep(var_interp,nrow(pred_data_day_v_info)) |
|
243 |
#pred_data_day_v_info$tile_id <- rep(tile_id,nrow(pred_data_day_v_info)) |
|
244 |
|
|
235 |
pred_data_day_info$tile_id <- rep(tile_id,nrow(pred_data_day_info)) |
|
245 | 236 |
} |
246 | 237 |
|
247 | 238 |
if(use_month==TRUE){ |
... | ... | |
265 | 256 |
pred_data_month_info$method_interp <- rep(method_interp,nrow(pred_data_month_info)) |
266 | 257 |
pred_data_month_info$var_interp <- rep(var_interp,nrow(pred_data_month_info)) |
267 | 258 |
pred_data_month_info$tile_id <- rep(tile_id,nrow(pred_data_month_info)) |
268 |
|
|
269 |
#pred_data_month_s_info$method_interp <- rep(method_interp,nrow(pred_data_month_s_info)) |
|
270 |
#pred_data_month_s_info$var_interp <- rep(var_interp,nrow(pred_data_month_s_info)) |
|
271 |
#pred_data_month_s_info$tile_id <- rep(tile_id,nrow(pred_data_month_s_info)) |
|
272 |
#pred_data_month_v_info$method_interp <- rep(method_interp,nrow(pred_data_month_v_info)) |
|
273 |
#pred_data_month_v_info$var_interp <- rep(var_interp,nrow(pred_data_month_v_info)) |
|
274 |
#pred_data_month_v_info$tile_id <- rep(tile_id,nrow(pred_data_month_v_info)) |
|
275 |
|
|
276 | 259 |
} |
277 | 260 |
|
278 | 261 |
if(use_month==FALSE){ |
... | ... | |
320 | 303 |
|
321 | 304 |
#in_dir1 <- "/data/project/layers/commons/NEX_data/test_run1_03232014/output" #On Atlas |
322 | 305 |
in_dir1 <- "/nobackupp4/aguzman4/climateLayers/output10Deg/reg1/" #On NEX |
323 |
|
|
324 |
#in_dir_list <- list.dirs(path=in_dir1) #get the list of directories with resutls by 10x10 degree tiles
|
|
306 |
#/nobackupp4/aguzman4/climateLayers/output10Deg/reg1/finished.txt |
|
307 |
in_dir_list <- list.dirs(path=in_dir1,recursive=FALSE) #get the list of directories with resutls by 10x10 degree tiles
|
|
325 | 308 |
#use subset for now: |
326 | 309 |
|
327 |
in_dir_list <- c( |
|
328 |
"/nobackupp4/aguzman4/climateLayers/output10Deg/reg1/40.0_-120.0/", |
|
329 |
"/nobackupp4/aguzman4/climateLayers/output10Deg/reg1/35.0_-115.0/") |
|
310 |
#in_dir_list <- c(
|
|
311 |
#"/nobackupp4/aguzman4/climateLayers/output10Deg/reg1/40.0_-120.0/",
|
|
312 |
#"/nobackupp4/aguzman4/climateLayers/output10Deg/reg1/35.0_-115.0/")
|
|
330 | 313 |
|
331 | 314 |
#in_dir_list <- file.path(in_dir1,read.table(file.path(in_dir1,"processed.txt"))$V1) |
332 | 315 |
#in_dir_list <- as.list(in_dir_list[-1]) |
333 | 316 |
#in_dir_list <- in_dir_list[grep("bak",basename(basename(in_dir_list)),invert=TRUE)] #the first one is the in_dir1 |
334 | 317 |
#in_dir_shp <- in_dir_list[grep("shapefiles",basename(in_dir_list),invert=FALSE)] #select directory with shapefiles... |
335 | 318 |
in_dir_shp <- "/nobackupp4/aguzman4/climateLayers/output10Deg/reg1/subset/shapefiles/" |
319 |
in_dir_shp_list <- list.files(in_dir_shp,".shp") |
|
320 |
|
|
336 | 321 |
#in_dir_list <- in_dir_list[grep("shapefiles",basename(in_dir_list),invert=TRUE)] |
337 | 322 |
#the first one is the in_dir1 |
338 | 323 |
# the last directory contains shapefiles |
339 | 324 |
y_var_name <- "dailyTmax" |
340 | 325 |
interpolation_method <- c("gam_CAI") |
341 |
out_prefix<-"run3_global_analyses_05292014"
|
|
326 |
out_prefix<-"run3_global_analyses_06192014"
|
|
342 | 327 |
|
343 | 328 |
#out_dir<-"/data/project/layers/commons/NEX_data/" #On NCEAS Atlas |
344 | 329 |
out_dir <- "/nobackup/bparmen1/" #on NEX |
... | ... | |
366 | 351 |
|
367 | 352 |
##raster_prediction object : contains testing and training stations with RMSE and model object |
368 | 353 |
|
354 |
#l_shp <- lapply(1:length(in_dir_shp_list),FUN=function(i){paste(strsplit(in_dir_shp_list[i],"_")[[1]][2:3],collapse="_")}) |
|
355 |
#match(l_shp,in_dir_list) |
|
356 |
#in_dir_list[match(in_dir_list,l_shp] |
|
357 |
|
|
369 | 358 |
list_raster_obj_files <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern="^raster_prediction_obj.*.RData",full.names=T)}) |
370 | 359 |
basename(dirname(list_raster_obj_files[[1]])) |
371 | 360 |
list_names_tile_coord <- lapply(list_raster_obj_files,FUN=function(x){basename(dirname(x))}) |
... | ... | |
406 | 395 |
#### Table 1: Average accuracy metrics |
407 | 396 |
|
408 | 397 |
#can use a maximum of 6 cores on the NEX Bridge |
398 |
#summary_metrics_v_list <- mclapply(list_raster_obj_files[5:6],FUN=function(x){try( x<- load_obj(x)); try(x[["summary_metrics_v"]]$avg)},mc.preschedule=FALSE,mc.cores = 2) |
|
399 |
|
|
409 | 400 |
summary_metrics_v_list <- mclapply(list_raster_obj_files,FUN=function(x){try( x<- load_obj(x)); try(x[["summary_metrics_v"]]$avg)},mc.preschedule=FALSE,mc.cores = 6) |
410 | 401 |
names(summary_metrics_v_list) <- list_names_tile_id |
411 | 402 |
|
... | ... | |
499 | 490 |
pred_pattern_str <- paste(".*predicted_mod",mod_id,"_0_1.*",sep="") |
500 | 491 |
#,".*predicted_mod2_0_1.*",".*predicted_mod3_0_1.*",".*predicted_mod_kr_0_1.*") |
501 | 492 |
#l_pattern_models <- lapply(c(".*predicted_mod1_0_1.*",".*predicted_mod2_0_1.*",".*predicted_mod3_0_1.*",".*predicted_mod_kr_0_1.*"), |
502 |
FUN=function(x){paste(x,dates_l,".*.tif",sep="")}) |
|
493 |
# FUN=function(x){paste(x,dates_l,".*.tif",sep="")})
|
|
503 | 494 |
l_pattern_models <- lapply(pred_pattern_str, |
504 | 495 |
FUN=function(x){paste(x,dates_l,".*.tif",sep="")}) |
505 | 496 |
#gam_CAI_dailyTmax_predicted_mod_kr_0_1_20101231_30_145.0_-120.0.tif |
... | ... | |
510 | 501 |
lf_pred_tif <- vector("list",length=length(l_pattern_models)) #number of models is 3 |
511 | 502 |
for (i in 1:length(l_pattern_models)){ |
512 | 503 |
l_pattern_mod <- l_pattern_models[[i]] #365 dates |
513 |
list_tif_files_dates <-lapply(1:length(l_pattern_mod),FUN=list_tif_fun, |
|
514 |
in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]]) |
|
504 |
#list_tif_files_dates <-lapply(1:length(l_pattern_mod),FUN=list_tif_fun, |
|
505 |
# in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]]) |
|
506 |
list_tif_files_dates <-mclapply(1:length(l_pattern_mod),FUN=list_tif_fun, |
|
507 |
in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]],mc.preschedule=FALSE,mc.cores = 6) |
|
508 |
|
|
515 | 509 |
lf_pred_tif[[i]] <- list_tif_files_dates |
516 | 510 |
} |
517 | 511 |
|
... | ... | |
523 | 517 |
lf_clim_tif <- vector("list",length=nb_mod) #number of models is 3 |
524 | 518 |
for (i in 1:length(l_pattern_models)){ |
525 | 519 |
l_pattern_mod <- l_pattern_models[[i]] #12 dates |
526 |
list_tif_files_dates <- lapply(1:length(l_pattern_mod),FUN=list_tif_fun, |
|
527 |
in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]]) |
|
520 |
list_tif_files_dates <- mclapply(1:length(l_pattern_mod),FUN=list_tif_fun,
|
|
521 |
in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]],mc.preschedule=FALSE,mc.cores = 6)
|
|
528 | 522 |
lf_clim_tif[[i]] <- list_tif_files_dates |
529 | 523 |
} |
530 | 524 |
|
... | ... | |
538 | 532 |
lf_delta_tif <- vector("list",length=nb_mod) #number of models is 3 |
539 | 533 |
for (i in 1:length(l_pattern_models)){ |
540 | 534 |
l_pattern_mod <- l_pattern_models[[i]] |
541 |
list_tif_files_dates <- lapply(1:length(l_pattern_mod),FUN=list_tif_fun, |
|
542 |
in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]]) |
|
535 |
list_tif_files_dates <- mclapply(1:length(l_pattern_mod),FUN=list_tif_fun,
|
|
536 |
in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]],mc.preschedule=FALSE,mc.cores = 6)
|
|
543 | 537 |
lf_delta_tif[[i]] <- list_tif_files_dates |
544 | 538 |
} |
545 | 539 |
|
... | ... | |
703 | 697 |
# use_day=TRUE |
704 | 698 |
# use_month=TRUE |
705 | 699 |
# |
700 |
|
|
706 | 701 |
# list_param_training_testing_info <- list(list_raster_obj_files,use_month,use_day,list_names_tile_id) |
707 | 702 |
# names(list_param_training_testing_info) <- c("list_raster_obj_files","use_month","use_day","list_names_tile_id") |
708 | 703 |
# |
... | ... | |
719 | 714 |
#in_dir_shp <- "/nobackupp4/aguzman4/climateLayers/output4/subset/shapefiles/" |
720 | 715 |
|
721 | 716 |
#get shape files for the region being assessed: |
722 |
list_shp_global_tiles_files <- list.files(path=in_dir_shp,pattern="*.shp") |
|
717 |
#list_shp_global_tiles_files <- list.files(path=in_dir_shp,pattern="*.shp") |
|
718 |
#l_shp<-lapply(1:length(in_dir_shp_list),FUN=function(i){paste(strsplit(in_dir_shp_list[i],"_")[[1]][2:3],collapse="_")}) |
|
719 |
list_shp_global_tiles_files <- l_shp |
|
723 | 720 |
pattern_str <- basename(in_dir_list) |
721 |
#list_shp_global_tiles_files |
|
724 | 722 |
list_shp_reg_files <- lapply(pattern_str,function(x){list_shp_global_tiles_files[grep(x,invert=FALSE,list_shp_global_tiles_files)]}) #select directory with shapefiles... |
725 | 723 |
df_tile_processed$shp_files <- unlist(list_shp_reg_files) |
726 | 724 |
|
... | ... | |
797 | 795 |
#copy shapefiles defining regions |
798 | 796 |
Atlas_dir <- file.path("/data/project/layers/commons/NEX_data/",basename(out_dir),"output/subset/shapefiles") |
799 | 797 |
Atlas_hostname <- "parmentier@atlas.nceas.ucsb.edu" |
800 |
lf_cp_shp <- list.files(in_dir_shp, ".shp",full.names=T) |
|
798 |
lf_cp_shp <- list.files(in_dir_shp,full.names=T) #get all the files... |
|
799 |
#lf_cp_shp <- list.files(in_dir_shp, ".shp",full.names=T) |
|
800 |
|
|
801 | 801 |
filenames_NEX <- paste(lf_cp_shp,collapse=" ") #copy raster prediction object |
802 | 802 |
cmd_str <- paste("scp -p",filenames_NEX,paste(Atlas_hostname,Atlas_dir,sep=":"), sep=" ") |
803 | 803 |
system(cmd_str) |
... | ... | |
811 | 811 |
cmd_str <- paste("scp -p",filenames_NEX,paste(Atlas_hostname,Atlas_dir,sep=":"), sep=" ") |
812 | 812 |
system(cmd_str) |
813 | 813 |
|
814 |
system("scp -p ./*.txt parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_global_analyses_05122014") |
|
815 |
system("scp -p ./*.txt ./*.tif parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_global_analyses_05122014") |
|
814 |
#system("scp -p ./*.txt parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_global_analyses_05122014")
|
|
815 |
#system("scp -p ./*.txt ./*.tif parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_global_analyses_05122014")
|
|
816 | 816 |
|
817 | 817 |
system("scp -p /nobackupp4/aguzman4/climateLayers/output4/subset/shapefiles/* parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/shapefiles") |
818 | 818 |
|
Also available in: Unified diff
assessment NEX run part1: debugging extraction of training and testing info function