Revision be545559
Added by Benoit Parmentier over 9 years ago
climate/research/oregon/interpolation/global_run_scalingup_assessment_part1.R | ||
---|---|---|
5 | 5 |
#Part 1 create summary tables and inputs files for figure in part 2 and part 3. |
6 | 6 |
#AUTHOR: Benoit Parmentier |
7 | 7 |
#CREATED ON: 03/23/2014 |
8 |
#MODIFIED ON: 09/15/2015
|
|
8 |
#MODIFIED ON: 10/05/2015
|
|
9 | 9 |
#Version: 4 |
10 | 10 |
#PROJECT: Environmental Layers project |
11 | 11 |
#TO DO: |
... | ... | |
77 | 77 |
in_dir1 <- "/nobackupp6/aguzman4/climateLayers/out_15x45/" |
78 | 78 |
#/nobackupp6/aguzman4/climateLayers/out_15x45/1982 |
79 | 79 |
|
80 |
#region_names <- c("reg4") #selected region names, #PARAM2
|
|
81 |
region_names <- c("1982") #no specific region here so use date
|
|
80 |
region_names <- c("reg4") #selected region names, #PARAM2 |
|
81 |
#region_names <- c("1992") #no specific region here so use date
|
|
82 | 82 |
#region_names <- c("reg1","reg2","reg3","reg4","reg5","reg6") #selected region names, #PARAM2 |
83 | 83 |
#region_namesb <- c("reg_1b","reg_1c","reg_2b","reg_3b","reg_6b") #selected region names, #PARAM2 |
84 | 84 |
|
85 | 85 |
y_var_name <- "dailyTmax" #PARAM3 |
86 | 86 |
interpolation_method <- c("gam_CAI") #PARAM4 |
87 |
out_prefix<-"run10_1500x4500_global_analyses_pred_1982_09152015" #PARAM5
|
|
87 |
out_prefix<-"run10_1500x4500_global_analyses_pred_1992_10052015" #PARAM5
|
|
88 | 88 |
|
89 | 89 |
#output_run10_1500x4500_global_analyses_pred_2003_04102015/ |
90 | 90 |
|
... | ... | |
99 | 99 |
#day_to_mosaic <- c("20100101","20100901") #PARAM9 |
100 | 100 |
#day_to_mosaic <- c("20100829","20100830","20100831", |
101 | 101 |
# "20100901","20100902","20100903") |
102 |
day_to_mosaic <- c("19820101","19820102","19820103","19820104","19820105", |
|
103 |
"19820106","19820107","19820108","19820109","19820110", |
|
104 |
"19820111") |
|
102 |
day_to_mosaic <- c("19920101","19920102","19920103") |
|
103 |
#,"19820104","19820105", |
|
104 |
# "19820106","19820107","19820108","19820109","19820110", |
|
105 |
# "19820111") |
|
105 | 106 |
|
106 | 107 |
#day_to_mosaic <- NULL #if day to mosaic is null then mosaic all dates? |
107 | 108 |
|
... | ... | |
128 | 129 |
|
129 | 130 |
in_dir_list <- list.dirs(path=in_dir1,recursive=FALSE) #get the list regions processed for this run |
130 | 131 |
#basename(in_dir_list) |
131 |
in_dir_list<- lapply(region_names,FUN=function(x,y){y[grep(x,basename(y),invert=FALSE)]},
|
|
132 |
in_dir_list<- lapply(region_names,FUN=function(x,y){y[grep(paste(x,"$",sep=""),basename(y),invert=FALSE)]},
|
|
132 | 133 |
y=in_dir_list) |
133 | 134 |
|
134 |
in_dir_list_all <- lapply(in_dir_list,function(x){list.dirs(path=x,recursive=F)})
|
|
135 |
in_dir_list <- unlist(in_dir_list_all)
|
|
135 |
in_dir_list_all <- unlist(lapply(in_dir_list,function(x){list.dirs(path=x,recursive=F)}))
|
|
136 |
in_dir_list <- in_dir_list_all
|
|
136 | 137 |
#in_dir_list <- in_dir_list[grep("bak",basename(basename(in_dir_list)),invert=TRUE)] #the first one is the in_dir1 |
137 | 138 |
|
138 |
#this was changed |
|
139 |
in_dir_list_tmp <- list.dirs(path=in_dir1,recursive=FALSE) #get the list regions processed for this run |
|
140 |
in_dir_subset <- in_dir_list_tmp[grep("subset",basename(in_dir_list_tmp),invert=FALSE)] #select directory with shapefiles... |
|
139 |
#this was changed on 10052015 because the shapefiles were not matching!!! |
|
140 |
#in_dir_list_tmp <- list.dirs(path=in_dir1,recursive=FALSE) #get the list regions processed for this run |
|
141 |
#in_dir_subset <- in_dir_list_tmp[grep("subset",basename(in_dir_list_tmp),invert=FALSE)] #select directory with shapefiles... |
|
142 |
#in_dir_shp <- file.path(in_dir_subset,"shapefiles") |
|
143 |
#in_dir_list_tmp <- list.dirs(path=in_dir1,recursive=FALSE) #get the list regions processed for this run |
|
144 |
in_dir_subset <- in_dir_list_all[grep("subset",basename(in_dir_list_all),invert=FALSE)] #select directory with shapefiles... |
|
141 | 145 |
in_dir_shp <- file.path(in_dir_subset,"shapefiles") |
142 | 146 |
|
147 |
|
|
143 | 148 |
#select only directories used for predictions |
144 | 149 |
in_dir_reg <- in_dir_list[grep(".*._.*.",basename(in_dir_list),invert=FALSE)] #select directory with shapefiles... |
145 | 150 |
#in_dir_reg <- in_dir_list[grep("july_tiffs",basename(in_dir_reg),invert=TRUE)] #select directory with shapefiles... |
... | ... | |
489 | 494 |
l_shp <- unlist(lapply(1:length(l_shp), |
490 | 495 |
FUN=function(i){paste(strsplit(l_shp[i],"_")[[1]][1:2],collapse="_")})) |
491 | 496 |
|
497 |
df_tiles_all <- as.data.frame(as.character(unlist(list_shp_world))) |
|
498 |
df_tiles_all$tile_coord <- l_shp |
|
499 |
#names(df_tiles_all) <- "list_shp_world" |
|
500 |
names(df_tiles_all) <- c("shp_files","tile_coord") |
|
492 | 501 |
matching_index <- match(basename(in_dir_list),l_shp) |
493 | 502 |
list_shp_reg_files <- list_shp_world[matching_index] |
494 |
df_tile_processed$shp_files <-list_shp_world[matching_index] |
|
503 |
df_tile_processed$shp_files <-list_shp_reg_files |
|
504 |
#df_tile_processed$shp_files <- "" |
|
505 |
#df_tile_processed$tile_coord <- as.character(df_tile_processed$tile_coord) |
|
506 |
#test <- df_tile_processed |
|
507 |
#test$shp_files <- NULL |
|
508 |
#test3 <- merge(test,df_tiles_all,by=c("tile_coord")) |
|
509 |
#test3 <- merge(df_tiles_all,test,by=c("tile_coord")) |
|
510 |
#merge(df_tile_processed,df_tiles_all,by="shp_files") |
|
495 | 511 |
|
496 | 512 |
tx<-strsplit(as.character(df_tile_processed$tile_coord),"_") |
497 | 513 |
lat<- as.numeric(lapply(1:length(tx),function(i,x){x[[i]][1]},x=tx)) |
... | ... | |
503 | 519 |
write.table(df_tile_processed, |
504 | 520 |
file=file.path(out_dir,paste("df_tile_processed_",out_prefix,".txt",sep="")),sep=",") |
505 | 521 |
|
506 |
df_tiles_all <- as.data.frame(as.character(unlist(list_shp_world))) |
|
507 |
names(df_tiles_all) <- "list_shp_world" |
|
522 |
|
|
508 | 523 |
write.table(df_tiles_all, |
509 | 524 |
file=file.path(out_dir,paste("df_tiles_all_",out_prefix,".txt",sep="")),sep=",") |
510 | 525 |
|
... | ... | |
640 | 655 |
#output_atlas_dir <- "/data/project/layers/commons/NEX_data/output_run3_global_analyses_06192014/output10Deg/reg1" |
641 | 656 |
#output_atlas_dir <- "/data/project/layers/commons/NEX_data/output_run5_global_analyses_08252014/output20Deg" |
642 | 657 |
output_atlas_dir <- file.path("/data/project/layers/commons/NEX_data/",out_dir) |
658 |
|
|
659 |
output_run10_1500x4500_global_analyses_pred_1992_10052015 |
|
643 | 660 |
#Make directories on ATLAS |
644 | 661 |
#for (i in 1:length(df_tile_processed$tile_coord)){ |
645 | 662 |
# create_dir_fun(file.path(output_atlas_dir,as.character(df_tile_processed$tile_coord[i])),out_suffix=NULL) |
... | ... | |
650 | 667 |
# create_dir_fun(file.path(output_atlas_dir,as.character(df_tile_processed$tile_coord[i]),"/shapefiles"),out_suffix=NULL) |
651 | 668 |
#} |
652 | 669 |
|
670 |
### Create dir locally and on Atlas |
|
671 |
|
|
672 |
Atlas_dir <- file.path("/data/project/layers/commons/NEX_data/",basename(out_dir))#,"output/subset/shapefiles") |
|
673 |
#Atlas_hostname <- "parmentier@atlas.nceas.ucsb.edu" |
|
674 |
#cmd_str <- paste("ssh ",Atlas_hostname,"mkdir",Atlas_dir, sep=" ") |
|
675 |
|
|
676 |
#Atlas_dir_mosaic <- file.path("/data/project/layers/commons/NEX_data/",basename(out_dir),"mosaics") |
|
677 |
#Atlas_hostname <- "parmentier@atlas.nceas.ucsb.edu" |
|
678 |
#cmd_str <- paste("ssh ",Atlas_hostname,"mkdir",Atlas_dir_mosaic, sep=" ") |
|
679 |
|
|
680 |
#Atlas_dir_shapefiles <- file.path("/data/project/layers/commons/NEX_data/",basename(out_dir),"shapefiles") |
|
681 |
#Atlas_hostname <- "parmentier@atlas.nceas.ucsb.edu" |
|
682 |
#cmd_str <- paste("ssh ",Atlas_hostname,"mkdir",Atlas_dir_shapefiles, sep=" ") |
|
683 |
|
|
684 |
#locally on NEX |
|
685 |
#cmd_str <- paste(" mkdir ",out_dir,"/{mosaic,shapefiles,tiles}", sep="") |
|
686 |
cmd_str <- paste(" mkdir ",out_dir,"/{mosaic,tiles}", sep="") #create both dir |
|
687 |
system(cmd_str) |
|
688 |
|
|
689 |
#remotely on Atlas |
|
690 |
cmd_str <- paste("ssh ",Atlas_hostname," mkdir ",Atlas_dir,"/{mosaic,shapefiles,tiles}", sep="") |
|
691 |
system(cmd_str) |
|
692 |
|
|
653 | 693 |
#Copy summary textfiles back to atlas |
654 | 694 |
|
655 | 695 |
Atlas_dir <- file.path("/data/project/layers/commons/NEX_data/",basename(out_dir))#,"output/subset/shapefiles") |
... | ... | |
659 | 699 |
cmd_str <- paste("scp -p",filenames_NEX,paste(Atlas_hostname,Atlas_dir,sep=":"), sep=" ") |
660 | 700 |
system(cmd_str) |
661 | 701 |
|
702 |
#cp -rp ./*/gam_CAI_dailyTmax_predicted_mod1_0_1_19920103_30_*.tif /nobackupp8/bparmen1//output_run10_1500x4500_global_analyses_pred_1992_10052015/tiles |
|
662 | 703 |
#system("scp -p ./*.txt parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run6_global_analyses_09162014") |
663 | 704 |
#system("scp -p ./*.txt ./*.tif parmentier@atlas.nceas.ucsb.edu:/data/project/layers/commons/NEX_data/output_run2_global_analyses_05122014") |
664 | 705 |
|
... | ... | |
669 | 710 |
Atlas_dir <- file.path("/data/project/layers/commons/NEX_data/",basename(out_dir),"shapefiles") |
670 | 711 |
Atlas_hostname <- "parmentier@atlas.nceas.ucsb.edu" |
671 | 712 |
lf_cp_shp <- df_tile_processed$shp_files #get all the files... |
672 |
|
|
713 |
list_shp_world |
|
673 | 714 |
lf_cp_shp_pattern <- gsub(".shp","*",basename(lf_cp_shp)) |
674 | 715 |
lf_cp_shp_pattern <- file.path(dirname(lf_cp_shp),lf_cp_shp_pattern) |
675 | 716 |
|
Also available in: Unified diff
running assessment part1 for South America 1992, major changes in code