Project

General

Profile

« Previous | Next » 

Revision 6f37bb0b

Added by Benoit Parmentier over 10 years ago

global scalingup assessment part 1 generating mosaic for clim and generating automatic listing for part 3

View differences:

climate/research/oregon/interpolation/global_run_scalingup_assessment_part1.R
39 39

  
40 40
#### FUNCTION USED IN SCRIPT
41 41

  
42
function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_10222013.R" #first interp paper
42
function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_05212014.R" #first interp paper
43 43
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_05052014.R"
44 44

  
45 45
load_obj <- function(f)
......
348 348
list_names_tile_id <- paste("tile",1:length(list_raster_obj_files),sep="_")
349 349
names(list_raster_obj_files)<- list_names_tile_id
350 350

  
351
lf_covar_obj <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern="covar_obj.*.RData",full.names=T)})
352
lf_covar_tif <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern="covar.*.tif",full.names=T)})
353

  
351 354
########################## START SCRIPT ##############################
352 355

  
353 356
################################################################
......
361 364
#First create table of tiles under analysis and their coord
362 365
df_tile_processed <- data.frame(tile_coord=basename(in_dir_list))
363 366
df_tile_processed$tile_id <- unlist(list_names_tile_id)
364

  
367
df_tile_processed$path_NEX <- in_dir_list
368
  
365 369
##Quick exploration of raster object
366 370
robj1 <- load_obj(list_raster_obj_files[[1]])
367 371
names(robj1)
......
460 464
y_var_name <- "dailyTmax"
461 465
interpolation_method <- c("gam_CAI")
462 466
name_method <- paste(interpolation_method,"_",y_var_name,"_",sep="")
463
l_pattern_models <- lapply(c(".*predicted_mod1_0_1.*",".*predicted_mod2_0_1.*",".*predicted_mod3_0_1.*"),
467
l_pattern_models <- lapply(c(".*predicted_mod1_0_1.*",".*predicted_mod2_0_1.*",".*predicted_mod3_0_1.*",".*predicted_mod_kr_0_1.*"),
464 468
                           FUN=function(x){paste(x,dates_l,".*.tif",sep="")})
465
out_prefix_s <- paste(name_method,c("predicted_mod1_0_01","predicted_mod2_0_01","predicted_mod3_0_01"),sep="")
469
#gam_CAI_dailyTmax_predicted_mod_kr_0_1_20101231_30_145.0_-120.0.tif
470
out_prefix_s <- paste(name_method,c("predicted_mod1_0_01","predicted_mod2_0_01","predicted_mod3_0_01","predicted_mod_kr_0_1"),sep="")
466 471
dates_l #list of predicted dates
467 472
#l_out_rastnames_var <- paste(name_method,"predicted_mod1_0_01_",dates_l,sep="")
468 473
l_out_rastnames_var <- lapply(out_prefix_s,
469 474
                              FUN=function(x){paste(x,"_",dates_l,sep="")})
470
                     
471
for (i in 1:lenth(l_pattern_models)){
472
  
475
#gam_CAI_dailyTmax_predicted_mod_kr_0_1_20101231_30_145.0_-120.0.tif                    
476

  
477
##Get list of predicted tif across all tiles, models and dates...
478
#this takes time, use mclapply!!
479
lf_pred_tif <- vector("list",length=length(l_pattern_models)) #number of models is 3
480
for (i in 1:length(l_pattern_models)){
481
  l_pattern_mod <- l_pattern_models[[i]]
482
  list_tif_files_dates <-lapply(1:length(l_pattern_mod),FUN=list_tif_fun, 
483
                              in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]])
484
  lf_pred_tif[[i]] <- list_tif_files_dates
485
}
486

  
487
#Now get the clim surfaces:
488
month_l <- paste("clim_month_",1:12,sep="")
489
l_pattern_models <- lapply(c("_mod1_0_1.*","_mod2_0_1.*","_mod3_0_1.*","_mod_kr_0_1.*"),
490
                           FUN=function(x){paste("*.",month_l,x,".*.tif",sep="")})
491
#"CAI_TMAX_clim_month_11_mod2_0_145.0_-120.0.tif"
492
lf_clim_tif <- vector("list",length=nb_mod) #number of models is 3
493
for (i in 1:length(l_pattern_models)){
473 494
  l_pattern_mod <- l_pattern_models[[i]]
495
  list_tif_files_dates <- lapply(1:length(l_pattern_mod),FUN=list_tif_fun, 
496
                              in_dir_list=in_dir_list,pattern_str=l_pattern_models[[i]])
497
  lf_clim_tif[[i]] <- list_tif_files_dates
498
}
499

  
500

  
501

  
502
#### NOW create mosaic images
503
nb_mod <- 4
504

  
505
for (i in 1:nb_mod){
506
  
507
  #l_pattern_mod <- l_pattern_models[[i]]
474 508
  #out_prefix_s <-    
475 509
    
476 510
  #list_tif_files_dates <- list_tif_fun(1,in_dir_list,l_pattern_mod)
477 511

  
478 512
  ##List of predicted tif ...
479
  list_tif_files_dates <-lapply(1:length(l_pattern_mod),FUN=list_tif_fun, 
480
                              in_dir_list=in_dir_list,pattern_str=l_pattern_mod)
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_mod)
515
  list_tif_files_dates <- lf_pred_tif[[i]] 
481 516
  #save(list_tif_files_dates, file=paste("list_tif_files_dates","_",out_prefix,".RData",sep=""))
482 517

  
483

  
484 518
  mosaic_list_var <- list_tif_files_dates
485 519
#  l_out_rastnames_var <- paste(name_method,"predicted_mod1_0_01_",dates_l,sep="")
486 520
#  out_rastnames_var <- l_out_rastnames_var[i]  
......
497 531
  list_var_mosaiced <- mclapply(1:2,FUN=mosaic_m_raster_list,list_param=list_param_mosaic,mc.preschedule=FALSE,mc.cores = 2)
498 532
  #list_var_mosaiced <- mclapply(1:365,FUN=mosaic_m_raster_list,list_param=list_param_mosaic,mc.preschedule=FALSE,mc.cores = 2)
499 533

  
534
  
500 535
}
501 536

  
502 537
### Now find out how many files were predicted
......
505 540

  
506 541
l_f_t12 <- list.files(path=in_dir_list[12],".*predicted_mod1_0_1.*")
507 542

  
543

  
544
l_f_bytiles<-lapply(in_dir_list,function(x){list.files(path=x,pattern=".*predicted_mod1_0_1.*")})
545
l_f_bytiles<-lapply(in_dir_list,function(x){list.files(path=x,pattern=".*predicted_mod1_0_1.*")})
508 546
l_f_bytiles<-lapply(in_dir_list,function(x){list.files(path=x,pattern=".*predicted_mod1_0_1.*")})
509 547

  
510 548

  
......
590 628

  
591 629
########### LAST PART: COPY SOME DATA BACK TO ATLAS #####
592 630

  
593
#Copy back to atlas
631
#Copy summary and mosaic back to atlas
594 632
system("scp -p ./*.txt parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_global_analyses_05122014")
595 633
system("scp -p ./*.txt ./*.tif parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_global_analyses_05122014")
596 634

  
635
#Copy specific tiles info back...
636
#tile_6: Oregon (45.0_-120.0)
637
system("scp -p ./*.txt ./*.tif parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_05122014/output/45.0_-120.0")
638
#tile_8: Californi-Arizona
639
system("scp -p ./*.txt ./*.tif parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_05122014/output/45.0_-120.0")
640
df_tile_processed$path_NEX
641
list_raster_obj_files[6]
642
list_raster_obj_files[8]
643
Atlas_dir <- "/data/project/layers/commons/NEX_data/output_run2_05122014/output/45.0_-120.0"
644
Atlas_hostname <- "parmentier@atlas.nceas.ucsb.edu"
645

  
646
#Oregon tile
647
filenames_NEX <- list_raster_obj_files[6] #copy raster prediction object
648
cmd_str <- paste("scp -p",filenames_NEX,paste(Atlas_hostname,Atlas_dir,sep=":"), sep=" ")
649
system(cmd_str)
650
#Now copy back tif for specific dates and tile (date 1 and date 244)
651
date_selected <- c("20100101","20100901")
652
date_index <- c(1,244)
653
tile_nb <- 6
654
nb_mod <- 3+1
655
lf_cp <- vector("list",length=length(date_selected))
656
for(i in 1:length(date_selected)){
657
  index <- date_index[i]  
658
  #get all predicted tmax files for all models and specific date, tile
659
  lf_cp[[i]] <- unlist(lapply(1:nb_mod,FUN=function(x){lf_pred_tif[[x]][[index]][[tile_nb]]}))
660
}
661

  
662
lf_clim_tiff[[]]
663

  
664
filenames_NEX <- paste(list_tif_files_dates[[1]][[6]],list_tif_files_dates[[244]][[6]],lf_covar_tif[6]) #to get first date and tile 6 prediction mod1
665
cmd_str <- paste("scp -p",filenames_NEX,paste(Atlas_hostname,Atlas_dir,sep=":"), sep=" ")
666
system(cmd_str)
667

  
668
#California-Arizona tile
669
Atlas_dir <- "/data/project/layers/commons/NEX_data/output_run2_05122014/output/35.0_-115.0"
670
filenames_NEX <- paste(list_raster_obj_files[8],lf_covar_obj[8]) #copy raster prediction object
671
cmd_str <- paste("scp -p",filenames_NEX,paste(Atlas_hostname,Atlas_dir,sep=":"), sep=" ")
672
system(cmd_str)
673
#Now copy back tif for specific dates and tile (date 1 and date 244)
674
filenames_NEX <- paste(list_tif_files_dates[[1]][[8]],list_tif_files_dates[[244]][[8]],lf_covar_tif[8]) #to get first date and tile 6 prediction mod1
675
cmd_str <- paste("scp -p",filenames_NEX,paste(Atlas_hostname,Atlas_dir,sep=":"), sep=" ")
676
system(cmd_str)
677

  
597 678
##################### END OF SCRIPT ######################

Also available in: Unified diff