Project

General

Profile

« Previous | Next » 

Revision 122ba379

Added by Benoit Parmentier almost 9 years ago

clean up of function mosaicing main function callable from stage 7

View differences:

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: 01/01/2016            
8
#MODIFIED ON: 01/05/2016            
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
......
37 37

  
38 38
#### FUNCTION USED IN SCRIPT
39 39

  
40
function_mosaicing <-"global_run_scalingup_mosaicing_function_12192015.R"
41

  
42
in_dir_script <-"/home/parmentier/Data/IPLANT_project/env_layers_scripts" #NCEAS UCSB
43
#in_dir_script <- "/nobackupp8/bparmen1/env_layers_scripts" #NASA NEX
44
source(file.path(in_dir_script,function_mosaicing))
45

  
46
load_obj <- function(f)
47
{
48
  env <- new.env()
49
  nm <- load(f, env)[1]
50
  env[[nm]]
51
}
52

  
53
create_dir_fun <- function(out_dir,out_suffix){
54
  if(!is.null(out_suffix)){
55
    out_name <- paste("output_",out_suffix,sep="")
56
    out_dir <- file.path(out_dir,out_name)
57
  }
58
  #create if does not exists
59
  if(!file.exists(out_dir)){
60
    dir.create(out_dir)
61
  }
62
  return(out_dir)
63
}
40
# function_mosaicing <-"global_run_scalingup_mosaicing_function_12192015.R"
41
# 
42
# #in_dir_script <-"/home/parmentier/Data/IPLANT_project/env_layers_scripts" #NCEAS UCSB
43
# in_dir_script <- "/nobackupp8/bparmen1/env_layers_scripts" #NASA NEX
44
# source(file.path(in_dir_script,function_mosaicing))
45
# 
46
# load_obj <- function(f)
47
# {
48
#   env <- new.env()
49
#   nm <- load(f, env)[1]
50
#   env[[nm]]
51
# }
52
# 
53
# create_dir_fun <- function(out_dir,out_suffix){
54
#   if(!is.null(out_suffix)){
55
#     out_name <- paste("output_",out_suffix,sep="")
56
#     out_dir <- file.path(out_dir,out_name)
57
#   }
58
#   #create if does not exists
59
#   if(!file.exists(out_dir)){
60
#     dir.create(out_dir)
61
#   }
62
#   return(out_dir)
63
# }
64 64

  
65 65
############################################
66 66
#### Parameters and constants  
67 67

  
68 68
#Data is on ATLAS or NASA NEX
69 69
#PARAM 1
70
in_dir <- "/data/project/layers/commons/NEX_data/output_run10_1500x4500_global_analyses_pred_1992_12072015" #NCEAS
71
#in_dir <- "/nobackupp8/bparmen1/output_run10_1500x4500_global_analyses_pred_1992_12072015" #NEX
72

  
73
in_dir_tiles <- file.path(in_dir,"tiles") #this is valid both for Atlas and NEX
74
y_var_name <- "dailyTmax" #PARAM2
75
interpolation_method <- c("gam_CAI") #PARAM3
76
region_name <- "reg4" #PARAM 4 #reg4 South America, Africa reg5,Europe reg2, North America reg1, Asia reg3
77
mosaicing_method <- c("unweighted","use_edge_weights") #PARAM5
78
out_suffix <- paste(region_name,"_","run10_1500x4500_global_analyses_pred_1992_12072015",sep="") #PARAM 6
79
out_suffix_str <- "run10_1500x4500_global_analyses_pred_1992_12072015" #PARAM 7
80
metric_name <- "rmse" #RMSE, MAE etc. #PARAM 8
81
pred_mod_name <- "mod1" #PARAM 9
82
var_pred <- "res_mod1" #used in residuals mapping #PARAM 10
83

  
84
out_dir <- in_dir #PARAM 11
85
create_out_dir_param <- FALSE #PARAM 12
86

  
87
#if daily mosaics NULL then mosaicas all days of the year #PARAM 13
88
day_to_mosaic <- c("19920101","19920102","19920103") #,"19920104","19920105") #PARAM9, two dates note in /tiles for now on NEX
89

  
90
#CRS_WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 #CONSTANT1
91
#CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
92
#proj_str<- CRS_WGS84 #PARAM 8 #check this parameter
93
 
94
file_format <- ".tif" #PARAM 14
95
NA_value <- -9999 #PARAM 15
96
NA_flag_val <- NA_value #PARAM 16
97
     
98
num_cores <- 6 #PARAM 17                 
99
region_names <- c("reg23","reg4") #selected region names, ##PARAM 18 
100
use_autokrige <- F #PARAM 19
101

  
102
###Separate folder for masks by regions, should be listed as just the dir!!... #PARAM 20
103
#infile_mask <- "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_reg4.tif"
104
infile_mask <- "/data/project/layers/commons/NEX_data/regions_input_files/r_mask_reg4.tif"
105
## All of this is interesting so use df_assessment!!
106
df_assessment_files_name <- "df_assessment_files_reg4_1984_run_global_analyses_pred_12282015.txt" # data.frame with all files used in assessmnet, PARAM 21
107

  
108
#in_dir can be on NEX or Atlas
109

  
110
#python script and gdal on NEX NASA:
111
#mosaic_python <- "/nobackupp6/aguzman4/climateLayers/sharedCode/"
112
#python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin"
113
#python script and gdal on Atlas NCEAS
114
mosaic_python <- "/data/project/layers/commons/NEX_data/sharedCode" #PARAM 26
115
python_bin <- "/usr/bin" #PARAM 27
116

  
117
algorithm <- "python" #PARAM 28 #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
118
#algorithm <- "R" #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
119
match_extent <- "FALSE" #PARAM 29 #try without matching!!!
120

  
121
#for residuals...
122
list_models <- NULL #PARAM 30
123
#list_models <- paste(var_pred,"~","1",sep=" ") #if null then this is the default...
70
# in_dir <- "/data/project/layers/commons/NEX_data/output_run10_1500x4500_global_analyses_pred_1992_12072015" #NCEAS
71
# #in_dir <- "/nobackupp8/bparmen1/output_run10_1500x4500_global_analyses_pred_1992_12072015" #NEX
72
# 
73
# in_dir_tiles <- file.path(in_dir,"tiles") #this is valid both for Atlas and NEX
74
# y_var_name <- "dailyTmax" #PARAM2
75
# interpolation_method <- c("gam_CAI") #PARAM3
76
# region_name <- "reg4" #PARAM 4 #reg4 South America, Africa reg5,Europe reg2, North America reg1, Asia reg3
77
# mosaicing_method <- c("unweighted","use_edge_weights") #PARAM5
78
# out_suffix <- paste(region_name,"_","run10_1500x4500_global_analyses_pred_1992_12072015",sep="") #PARAM 6
79
# out_suffix_str <- "run10_1500x4500_global_analyses_pred_1992_12072015" #PARAM 7
80
# metric_name <- "rmse" #RMSE, MAE etc. #PARAM 8
81
# pred_mod_name <- "mod1" #PARAM 9
82
# var_pred <- "res_mod1" #used in residuals mapping #PARAM 10
83
# 
84
# out_dir <- in_dir #PARAM 11
85
# create_out_dir_param <- FALSE #PARAM 12
86
# 
87
# #if daily mosaics NULL then mosaicas all days of the year #PARAM 13
88
# day_to_mosaic <- c("19920101","19920102","19920103") #,"19920104","19920105") #PARAM9, two dates note in /tiles for now on NEX
89
# 
90
# #CRS_WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 #CONSTANT1
91
# #CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
92
# #proj_str<- CRS_WGS84 #PARAM 8 #check this parameter
93
#  
94
# file_format <- ".tif" #PARAM 14
95
# NA_value <- -9999 #PARAM 15
96
# NA_flag_val <- NA_value #PARAM 16
97
#      
98
# num_cores <- 6 #PARAM 17                 
99
# region_names <- c("reg23","reg4") #selected region names, ##PARAM 18 
100
# use_autokrige <- F #PARAM 19
101
# 
102
# ###Separate folder for masks by regions, should be listed as just the dir!!... #PARAM 20
103
# #infile_mask <- "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_reg4.tif"
104
# infile_mask <- "/data/project/layers/commons/NEX_data/regions_input_files/r_mask_reg4.tif"
105
# ## All of this is interesting so use df_assessment!!
106
# df_assessment_files_name <- "df_assessment_files_reg4_1984_run_global_analyses_pred_12282015.txt" # data.frame with all files used in assessmnet, PARAM 21
107
# 
108
# #in_dir can be on NEX or Atlas
109
# 
110
# #python script and gdal on NEX NASA:
111
# #mosaic_python <- "/nobackupp6/aguzman4/climateLayers/sharedCode/"
112
# #python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin"
113
# #python script and gdal on Atlas NCEAS
114
# mosaic_python <- "/data/project/layers/commons/NEX_data/sharedCode" #PARAM 26
115
# python_bin <- "/usr/bin" #PARAM 27
116
# 
117
# algorithm <- "python" #PARAM 28 #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
118
# #algorithm <- "R" #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
119
# match_extent <- "FALSE" #PARAM 29 #try without matching!!!
120
# 
121
# #for residuals...
122
# list_models <- NULL #PARAM 30
123
# #list_models <- paste(var_pred,"~","1",sep=" ") #if null then this is the default...
124
# 
125
# list_param_run_mosaicing_prediction <- list(in_dir,y_var_name,interpolation_method,region_name,
126
#                  mosaicing_method,out_suffix,out_suffix_str,metric_name,pred_mod_name,var_pred,
127
#                  create_out_dir_param,day_to_mosaic,proj_str,file_format,NA_value,num_cores,
128
#                  region_name,use_autokrige,infile_mask,df_assessment_files_name,mosaic_python,
129
#                  python_bin,algorithm,match_extent,list_models)
130
# param_names <- c("in_dir","y_var_name","interpolation_method","region_name",
131
#                  "mosaicing_method","out_suffix","out_suffix_str","metric_name","pred_mod_name","var_pred",
132
#                  "create_out_dir_param","day_to_mosaic","proj_str","file_format","NA_value","num_cores",
133
#                  "region_name","use_autokrige","infile_mask","df_assessment_files_name","mosaic_python",
134
#                  "python_bin","algorithm","match_extent","list_models")
135
# names(list_param_run_mosaicing_prediction) <- param_names
124 136

  
125 137
########################## START SCRIPT ##############################
126 138

  

Also available in: Unified diff