Project

General

Profile

« Previous | Next » 

Revision d67ca452

Added by Benoit Parmentier over 8 years ago

modification of master script mosaicing stage 7 adding use integer and scaling option

View differences:

climate/research/oregon/interpolation/master_script_stage_7.R
7 7
#STAGE 2: Covariates preparation for study/processing area: calculation of covariates (spect,land cover,etc.) and reprojection
8 8
#STAGE 3: Data preparation: meteorological station database query and extraction of covariates values from raster brick
9 9
#STAGE 4: Raster prediction: run interpolation method (-- gam fusion, gam CAI, ...) and perform validation 
10
#STAGE 5: Output analyses: assessment of results for specific dates and tiles
11
#STAGE 6: Assessement of predictions by tiles and regions 
10
#STAGE 5: Output analyses: assessment of results for specific dates for individual tiles
11
#STAGE 6: Assessement of predictions by tiles, analyses and figures generation, summarized by regions 
12 12
#STAGE 7: Mosaicing of predicted surfaces and accuracy metrics (RMSE,MAE) by regions 
13
#STAGE 8: Comparison of predictions across regions and years with figures generation.
13
#STAGE 8: Comparison of predictions across regions and years with additional figures generation.
14 14

  
15 15
#AUTHOR: Benoit Parmentier                                                                        
16 16
#CREATED ON: 01/01/2016  
17
#MODIFIED ON: 04/11/2016  
17
#MODIFIED ON: 04/20/2016  
18 18
#PROJECT: NCEAS INPLANT: Environment and Organisms                                                                           
19 19

  
20 20
#First source these files:
......
25 25

  
26 26
## TODO:
27 27
# 
28
# Clean up temporary files
28
## Comments: dealing with flags and datatype in output mosaics
29 29
# 
30 30
##################################################################################################
31 31

  
......
63 63

  
64 64
#script_path <- "/home/parmentier/Data/IPLANT_project/env_layers_scripts"
65 65
script_path <- "/nobackupp8/bparmen1/env_layers_scripts" #path to script
66
function_mosaicing_functions <- "global_run_scalingup_mosaicing_function_04102016.R" #PARAM12
67
function_mosaicing <-"global_run_scalingup_mosaicing_04112016.R"
66
function_mosaicing_functions <- "global_run_scalingup_mosaicing_function_04202016b.R" #PARAM12
67
function_mosaicing <-"global_run_scalingup_mosaicing_04202016b.R"
68 68
source(file.path(script_path,function_mosaicing)) #source all functions used in this script 
69 69
source(file.path(script_path,function_mosaicing_functions)) #source all functions used in this script 
70 70

  
......
80 80
source(file.path(script_path,function_assessment_part3)) #source all functions used in this script 
81 81

  
82 82
### Parameters, constants and arguments ###
83
stages_to_run<-c(0,0,0,0,0,0,7) #this is stage, other stages are stored in files.
83
stages_to_run<-c(0,0,0,0,0,0,7) #this is stage, other stages are stored in files.#CONSTANT1
84 84
  
85
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
85
#CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84, CONST2
86
CRS_WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84, CONST2
86 87

  
87 88
#####mosaicing parameters
88 89

  
89 90
#Data is on ATLAS or NASA NEX
90 91

  
91 92
### PARAMETERS DEFINED IN THE SCRIPT
92
#There are 31 parameters, 1 constant and 17 arguments (drawn from the parameters) for the Rscript call.
93
#The arguments are passed directly from Rscript:
94
#var <- args[1] # variable being interpolated #param 1, arg 1
95
#in_dir <- args[2] # This is the output directory containing global prediction e.g./nobackupp6/aguzman4/climateLayers/out/ param 5, arg 2
96
#region_name <- args[3] # region e.g. "reg4" param 3, arg 3
97
#out_suffix <- args[4] # formely out_prefix, this is used in creating an output directory, it is suggested to use "reg4" or same as region_name
98
#out_dir <- args[5] # output parent dir, can be home dir or other, param 5, arg 5
99
#create_out_dir_param <- args[6] # if TRUE create a output from "output"+out_prefix param 6, arg 6
100
#year_predicted <- args[7] # enter as list but currently runs on the first element of the list, param 7, arg 7
101
#num_cores <- args[8] #number of cores used # param 8, arg 8
102
#max_mem <- args[9] # maximum memory, param 9
103
#mosaicing_method <- arg[10] #PARAM10
104
#metric_name <- arg[11] #"rmse" #RMSE, MAE etc. #PARAM 11
105
#day_to_mosaic_range <- arg[12] #c("19910101","19910103") #if null run all year, param 12
106
#infile_mask <- arg[13] # "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_reg4.tif"
107
#df_assessment_files_name <- arg[14] #"/nobackupp6/aguzman4/climateLayers/out/reg4/assessment/output_reg4_1991/df_assessment_files_reg4_1991_reg4_1991.txt" # data.frame with all files used in assessmnet, PARAM 21
108
#algorithm <- arg[15] #"python" #PARAM 28 #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
109
#layers_option <- arg[16] #c("var_pred") #options are:res_training, res_testing,ac_training, ac_testing, var_pred
110
#tmp_files <- arg[17] #FALSE
93
#There are 33 parameters, 3 constants and 20 arguments (drawn from the parameters) for the Rscript shell call.
94
#The 20 arguments are passed directly from Rscript:
111 95

  
112 96
### Use the following values to run code from the shell:
113 97
#var<-"TMAX" # variable being interpolated #param 1, arg 1
114 98
#in_dir <- "/nobackupp6/aguzman4/climateLayers/out/" #PARAM2,arg 2
115 99
#region_name <- "reg4" #PARAM 3, arg 3 #reg4 South America, Africa reg5,Europe reg2, North America reg1, Asia reg3
116 100
#out_suffix <- "reg4" #PARAM 4, arg 4
101
#out_suffix_str <- region_name #PARAM 4, CONST 3
117 102
#out_dir <- "/nobackupp8/bparmen1/climateLayers/out/reg4" #PARAM 5,arg 5 use this location for now
118 103
#create_out_dir_param <- TRUE #PARAM 6, arg 6
119 104
#year_predicted <- 1991 #PARAM 7, arg 7
120 105
#num_cores <- 6 #PARAM 8, arg 8         
121 106
#max_mem = 1e+07 #param 9, arg 9
122
#mosaicing_method <- use_edge_weights" #PARAM10, arg 10
107
#mosaicing_method <- "use_edge_weights" #PARAM10, arg 10
123 108
#metric_name <- "rmse" #RMSE, MAE etc. #PARAM 11, arg 11
124
#day_start <- "19910101" #PARAM 12
125
#day_end <- "19910101" #PARAM 13
109
#day_start <- "19910101" #PARAM 12 arg 12
110
#day_end <- "19910103" #PARAM 13 arg 13
126 111
#infile_mask <- "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_reg4.tif" #PARAM 14, arg 14
127 112
#df_assessment_files_name <- "/nobackupp6/aguzman4/climateLayers/out/reg4/assessment/output_reg4_1991/df_assessment_files_reg4_1991_reg4_1991.txt"  # data.frame with all files used in assessmnet, PARAM 15
128 113
#algorithm <- "python" #PARAM 16 #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
129 114
#layers_option <- c("var_pred") #arg 17 ,param 17, options are:#res_training, res_testing,ac_training, ac_testing, var_pred
130 115
#tmp_files <- FALSE #arg 18, param 18
116
#use_int <- TRUE #, param 19, use int32 for output layers mosaiced
117
#scaling <- 100 #, param 20, 
118

  
119
var<-"TMAX" # variable being interpolated #param 1, arg 1
120
in_dir <- "/nobackupp6/aguzman4/climateLayers/out/" #PARAM2,arg 2
121
region_name <- "reg4" #PARAM 3, arg 3 #reg4 South America, Africa reg5,Europe reg2, North America reg1, Asia reg3
122
out_suffix <- "reg4" #PARAM 4, arg 4
123
out_suffix_str <- region_name #PARAM 4, CONST 3
124
out_dir <- "/nobackupp8/bparmen1/climateLayers/out/reg4" #PARAM 5,arg 5 use this location for now
125
create_out_dir_param <- TRUE #PARAM 6, arg 6
126
year_predicted <- 1991 #PARAM 7, arg 7
127
num_cores <- 6 #PARAM 8, arg 8         
128
max_mem = 1e+07 #param 9, arg 9
129
mosaicing_method <- "use_edge_weights" #PARAM10, arg 10
130
metric_name <- "rmse" #RMSE, MAE etc. #PARAM 11, arg 11
131
day_start <- "19910101" #PARAM 12 arg 12
132
day_end <- "19910103" #PARAM 13 arg 13
133
infile_mask <- "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_reg4.tif" #PARAM 14, arg 14
134
df_assessment_files_name <- "/nobackupp6/aguzman4/climateLayers/out/reg4/assessment/output_reg4_1991/df_assessment_files_reg4_1991_reg4_1991.txt"  # data.frame with all files used in assessmnet, PARAM 15
135
algorithm <- "python" #PARAM 16 #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
136
layers_option <- c("var_pred") #arg 17 ,param 17, options are:#res_training, res_testing,ac_training, ac_testing, var_pred
137
tmp_files <- FALSE #arg 18, param 18
138
use_int <- TRUE #, param 19, use int32 for output layers mosaiced
139
scaling <- 100 #, param 20, 
131 140

  
132 141
#path_assessment <- NOT USED "/nobackupp6/aguzman4/climateLayers/out/reg4/assessment/output_reg4_1991" #PARAM 14a, arg 14
133 142

  
134 143
### Testing several years on the bridge before running jobs on nodes with qsub
135 144
#Use the following command to run as script via the shell on the bridge 
136
#Rscript /nobackupp8/bparmen1/env_layers_scripts/master_script_stage_7_04112016.R TMAX /nobackupp6/aguzman4/climateLayers/out/ reg4 reg4 /nobackupp8/bparmen1/climateLayers/out/reg4 TRUE 1991 6 1e+07 use_edge_weights rmse 19910101 19910103 /nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_reg4.tif /nobackupp6/aguzman4/climateLayers/out/reg4/assessment/output_reg4_1991/df_assessment_files_reg4_1991_reg4_1991.txt python var_pred FALSE 
145
#Rscript /nobackupp8/bparmen1/env_layers_scripts/master_script_stage_7_04202016.R TMAX /nobackupp6/aguzman4/climateLayers/out/ reg4 reg4 /nobackupp8/bparmen1/climateLayers/out/reg4 TRUE 1991 6 1e+07 use_edge_weights rmse 19910101 19910103 /nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_reg4.tif /nobackupp6/aguzman4/climateLayers/out/reg4/assessment/output_reg4_1991/df_assessment_files_reg4_1991_reg4_1991.txt python var_pred FALSE TRUE 100 
137 146

  
138 147
############################
139 148

  
......
154 163

  
155 164
out_suffix <- args[4] #PARAM 4
156 165
#out_suffix <- region_name #PARAM 4
157
out_suffix_str <- region_name #PARAM 4
166
out_suffix_str <- region_name #PARAM 4, CONST 3
158 167
out_dir <- args[5] #PARAM 5
159 168
#out_dir <- "/nobackupp8/bparmen1/climateLayers/out/reg4" #PARAM 5, use this location for now
160 169
create_out_dir_param <- args[6] #PARAM 6
......
190 199
#path_assessment <- "/nobackupp6/aguzman4/climateLayers/out/reg4/assessment/output_reg4_1991"
191 200
#path_assessment <- file.path(in_dir,region_name,"assessment",paste("output_",region_name,year_processed,sep=""))
192 201

  
193
df_assessment_files_name <- args[15] #PARAM 15
202
df_assessment_files_name <- args[15] #PARAM 15, files containing assessment information
194 203
#df_assessment_files_name <- "/nobackupp6/aguzman4/climateLayers/out/reg4/assessment/output_reg4_1991/df_assessment_files_reg4_1991_reg4_1991.txt" # data.frame with all files used in assessmnet, PARAM 14
195 204
algorithm <- args[16] #PARAM 16
196 205
#algorithm <- "python" #PARAM 15 #if R use mosaic function for R, if python use modified gdalmerge script from Alberto Guzmann
......
200 209
#layers_option <- c("var_pred") #options are:
201 210
#res_training, res_testing,ac_training, ac_testing, var_pred
202 211
tmp_files <- args[18] #PARAM 18
212
use_int <- args[19] #PARAM 19 #use integer 32 for layers outputs
213
scaling <- args[20] #PARAM 19 #use integer 32 for layers outputs
214

  
203 215
#tmp_files <- FALSE
204
interpolation_method <- c("gam_CAI") #PARAM19
205
pred_mod_name <- "mod1" #PARAM 20
206
var_pred <- "res_mod1" #used in residuals mapping #PARAM 21
207
proj_str<- CRS_WGS84 #PARAM 22 #check this parameter
208
file_format <- ".tif" #PARAM 23
209
NA_value <- -9999 #PARAM 24
210
NA_flag_val <- NA_value #PARAM 24
211
use_autokrige <- F #PARAM 25
212
proj_str <- CRS_locs_WGS84 #PARAM 26
216
interpolation_method <- c("gam_CAI") #PARAM21
217
pred_mod_name <- "mod1" #PARAM 22
218
var_pred <- "res_mod1" #used in residuals mapping #PARAM 23
219
proj_str<- CRS_WGS84 #PARAM 24 #check this parameter
220
file_format <- ".tif" #PARAM 25
221
NA_value <- -9999 #PARAM 26
222
NA_flag_val <- NA_value #PARAM 27
223
use_autokrige <- F #PARAM 28
224
#proj_str <- CRS_locs_WGS84 #PARAM 29
213 225
#python script and gdal on NEX NASA:
214
mosaic_python <- "/nobackupp6/aguzman4/climateLayers/sharedCode/" #PARAM 27
215
python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin" #PARAM 28
226
mosaic_python <- "/nobackupp6/aguzman4/climateLayers/sharedCode/" #PARAM 29
227
python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin" #PARAM 30
216 228
#python script and gdal on Atlas NCEAS
217
#mosaic_python <- "/data/project/layers/commons/NEX_data/sharedCode" #PARAM 29
229
#mosaic_python <- "/data/project/layers/commons/NEX_data/sharedCode" #PARAM 30
218 230
#python_bin <- "/usr/bin" #PARAM 30
219
match_extent <- "FALSE" #PARAM 29 #try without matching!!!
231
match_extent <- "FALSE" #PARAM 31 #try without matching!!!
220 232
#for residuals...
221
list_models <- NULL #PARAM 30
233
list_models <- NULL #PARAM 32
222 234
#list_models <- paste(var_pred,"~","1",sep=" ") #if null then this is the default...
223 235
  
224 236
if (var == "TMAX") {
......
239 251
#browser()
240 252

  
241 253
#rasterOptions(maxmemory=1e+07,timer=TRUE)
254
##30 parameters passed
242 255
list_param_run_mosaicing_prediction <- list(in_dir,y_var_name,interpolation_method,region_name,
243 256
                 mosaicing_method,out_suffix,out_suffix_str,metric_name,pred_mod_name,var_pred, out_dir,
244 257
                 create_out_dir_param,day_to_mosaic_range,year_predicted,proj_str,file_format,NA_value,num_cores,
245 258
                 use_autokrige,infile_mask,df_assessment_files_name,mosaic_python,
246
                 python_bin,algorithm,match_extent,list_models,layers_option,tmp_files)
259
                 python_bin,algorithm,match_extent,list_models,layers_option,tmp_files,use_int,scaling)
247 260
param_names <- c("in_dir","y_var_name","interpolation_method","region_name",
248 261
                 "mosaicing_method","out_suffix","out_suffix_str","metric_name","pred_mod_name","var_pred","out_dir",
249 262
                 "create_out_dir_param","day_to_mosaic_range","year_predicted","proj_str","file_format","NA_value","num_cores",
250 263
                 "use_autokrige","infile_mask","df_assessment_files_name","mosaic_python",
251
                 "python_bin","algorithm","match_extent","list_models","layers_option","tmp_files")
264
                 "python_bin","algorithm","match_extent","list_models","layers_option","tmp_files","use_int","scaling")
252 265
names(list_param_run_mosaicing_prediction) <- param_names
253 266
#list_param_run_mosaicing_prediction
254 267
#debug(run_mosaicing_prediction_fun)

Also available in: Unified diff