Project

General

Profile

« Previous | Next » 

Revision bd7ade8a

Added by Benoit Parmentier over 8 years ago

making callable from shel for function of number of predictions for day with missing tiles

View differences:

climate/research/oregon/interpolation/global_product_assessment_part0.R
9 9
#
10 10
#AUTHOR: Benoit Parmentier 
11 11
#CREATED ON: 10/27/2016  
12
#MODIFIED ON: 11/22/2016            
12
#MODIFIED ON: 11/25/2016            
13 13
#Version: 1
14 14
#PROJECT: Environmental Layers project     
15 15
#COMMENTS: 
......
20 20
#source /nobackupp6/aguzman4/climateLayers/sharedModules2/etc/environ.sh 
21 21
#
22 22
#setfacl -Rm u:aguzman4:rwx /nobackupp6/aguzman4/climateLayers/LST_tempSpline/
23
#COMMIT: moving function of number of predictions for day with missing tiles to functon script
23
#COMMIT: making callable from shel for function of number of predictions for day with missing tiles 
24 24

  
25 25
#################################################################################################
26 26

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

  
91 91
#Product assessment
92
function_product_assessment_part0_functions <- "global_product_assessment_part0_functions_11222016b.R"
92
function_product_assessment_part0_functions <- "global_product_assessment_part0_functions_11252016.R"
93 93
source(file.path(script_path,function_product_assessment_part0_functions)) #source all functions used in this script 
94 94
##Don't load part 1 and part2, mosaic package does not work on NEX
95 95
#function_product_assessment_part1_functions <- "global_product_assessment_part1_functions_09192016b.R"
......
100 100
###############################
101 101
####### Parameters, constants and arguments ###
102 102

  
103
#Find number of param
103
### ARGUMENTS: inputs parameters set from the command line
104 104
#var <- args[1] # variable being interpolated #param 1, arg 1
105 105
#var<-"TMAX" # variable being interpolated #param 1, arg 1
106 106

  
107
#CRS_locs_WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #constant 1
108
proj_str <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0"
109

  
110
var<-"TMAX" # variable being interpolated #param 1, arg 1
111
interpolation_method<-c("gam_CAI") #param 2
112
#CRS_interp <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0" #param 3
113
#list_models<-c("y_var ~ s(lat,lon,k=5) + s(elev_s,k=3) + s(LST,k=3)") #param 4
114
metric_name <- "var_pred" #use RMSE if accuracy
115
pred_mod_name <- "mod1"
116
item_no <- 9
117
day_start <- "2000101" #PARAM 12 arg 12
118
day_end <- "20001231" #PARAM 13 arg 13
119
#date_start <- day_start
120
#date_end <- day_end
121
date_start <- day_start
122
date_end <- day_end
107
var<-"TMAX" # variable being interpolated #PARAM 1, arg 1
108
interpolation_method<-c("gam_CAI") #PARAM 2
109
layers_option <- c("var_pred") #options are:
110
item_no <- 9 #PARAM 4
111
day_start <- "2000101" #PARAM 5, arg 12
112
day_end <- "20001231" #PARAM 6, arg 13
123 113
#day_start <- "1984101" #PARAM 12 arg 12
124 114
#day_end <- "20141231" #PARAM 13 arg 13
125
day_to_mosaic_range <- NULL
115
day_to_mosaic_range <- NULL #PARAM 7
126 116
#infile_mask <- "/data/project/layers/commons/NEX_data/regions_input_files/r_mask_LST_reg6.tif"
127
infile_mask <- "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_LST_reg6.tif"
128

  
129
in_dir <- "/nobackupp6/aguzman4/climateLayers/out/reg6/assessment"
130
#in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg6/mosaics/mosaic" #predicted mosaic
131
region_name <- c("reg6") #param 6, arg 3
132
out_suffix <- "global_assessment_reg6_10232016"
133
create_out_dir_param <- TRUE #param 9, arg 6
134
out_dir <- "/nobackupp6/aguzman4/climateLayers/out/reg6/assessment"
135
file_format <- ".tif" #format for mosaiced files # param 11
136
NA_flag_val <- -32768  #No data value, # param 12
137
plotting_figures <- TRUE #running part2 of assessment to generate figures... # param 14
138
num_cores <- 6 #number of cores used # param 13, arg 8
139
#python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin" #PARAM 30
140
#python_bin <- "/usr/bin" #PARAM 30, NCEAS
141
python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin" #PARAM 30"
142
NA_flag_val_mosaic <- -32768
143
in_dir_list_filename <- NULL #if NULL, use the in_dir directory to search for info
117
infile_mask <- "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_LST_reg6.tif" #PARAM 8
118
in_dir <- "/nobackupp6/aguzman4/climateLayers/out/reg6/assessment" #PARAM 9
119
region_name <- c("reg6") #PARAM 10, arg 3
120
out_suffix <- "predictions_assessment_reg6_10302016" #PARAM 11
121
create_out_dir_param <- TRUE #PARAM 12, arg 6
122
out_dir <- "/nobackupp6/aguzman4/climateLayers/out/reg6/assessment" #PARAM 13
123
file_format <- ".tif" #format for mosaiced files # PARAM 14
124
NA_value <- -32768 #PARAM 15
125
#NA_flag_val <- -32768  #No data value, # param 12
126
plotting_figures <- TRUE #running part2 of assessment to generate figures... # PARAM 13
127
num_cores <- 6 #number of cores used # PARAM 14, arg 8
128
#python_bin <- "/usr/bin" #PARAM 15, NCEAS
129
python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin" #PARAM 15"
130
in_dir_list_filename <- NULL # PARAM 16, if NULL, use the in_dir directory to search for info
144 131
#countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp" #Atlas
145
countries_shp <- "/nobackupp8/bparmen1/NEX_data/countries.shp"
146
lf_raster <- NULL #list of raster to consider
147
#On NEX
132
countries_shp <- "/nobackupp8/bparmen1/NEX_data/countries.shp" #PARAM 17
133
lf_raster <- NULL #list of raster to consider #PARAM 18
148 134
#contains all data from the run by Alberto
149
in_dir1 <- "/nobackupp6/aguzman4/climateLayers/out" #On NEX
150
#parent output dir for the current script analyes
151
y_var_name <- "dailyTmax" #PARAM1
152
out_suffix <- "predictions_assessment_reg6_10302016"
153
#file_format <- ".rst" #PARAM 9
154
NA_value <- -9999 #PARAM10
135
in_dir1 <- "/nobackupp6/aguzman4/climateLayers/out" # PARAM 19 On NEX
136
#list_year_predicted <- c(2000,2012,2013) #year still on disk for reg6 #only consider first year!
137
list_year_predicted <- c(2000) #PARAM 20, year still on disk for reg6 #only consider first year!
138
 
139
metric_name <- "var_pred" #PARAM 3, use RMSE if accuracy
140

  
141
layers_option <- args[17] # PARAM 17 options are:
142
#layers_option <- c("var_pred") #options are:
143
#res_training, res_testing,ac_training, ac_testing, var_pred
144
tmp_files <- args[18] #PARAM 18
145
data_type <- args[19] #PARAM 19 #use integer 32 for layers outputs
146
scaling <- args[20] #PARAM 19 #use integer 32 for layers outputs
147
values_range <-  args[21] #Param 21, args 21
148

  
149

  
150
###################
151
### CONSTANT: not set from command line
152

  
153
pred_mod_name <- "mod1"
154
date_start <- day_start
155
date_end <- day_end
155 156
NA_flag_val <- NA_value
156
#multiple_region <- TRUE #PARAM 12
157
region_name <- "reg6" #PARAM 13
158
#/nobackupp6/aguzman4/climateLayers/out/reg6/subset/shapefiles
159
list_year_predicted <- c(2000,2012,2013) #year still on disk for reg6
160
  
157
#NA_flag_val_mosaic <- -32768
158
#CRS_locs_WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #constant 1
159
proj_str <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0"
160

  
161
#CRS_interp <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0" #param 3
162
#list_models<-c("y_var ~ s(lat,lon,k=5) + s(elev_s,k=3) + s(LST,k=3)") #param 4
163

  
161 164
##Add for precip later...
162 165
if (var == "TMAX") {
163 166
  y_var_name <- "dailyTmax"
......
176 179
  variable_name <- "minimum temperature"
177 180
}
178 181

  
179
i<-1
182
#i<-1
180 183

  
181 184

  
182 185
##### prepare list of parameters for call of function
183
function_product_assessment_part0_functions <- "global_product_assessment_part0_functions_11222016b.R"
184
source(file.path(script_path,function_product_assessment_part0_functions)) #source all functions used in this script 
185 186

  
186 187
list_param_predictions_tiles_missing <- list(in_dir1,region_name,y_var_name,interpolation_method,out_suffix,out_dir,
187 188
                                             create_out_dir_param,proj_str,list_year_predicted,file_format,NA_flag_val,
......
203 204

  
204 205
############################ END OF SCRIPT ##################################
205 206

  
206
  # spdf_tiles <- do.call(intersect, shps_tiles)
207
  # 
208
  # ### Now use intersect to retain actual overlap
209
  # 
210
  # for(i in 1:length(shps_tiles)){
211
  #   overlap_intersect <- intersect(shps_tiles[[1]],shps_tiles[[i]])
212
  # }
213
  # 
214
  # overlap_intersect <- lapply(1:length(shps_tiles),FUN=function(i){intersect(shps_tiles[[1]],shps_tiles[[i]])})
215
  # #test <- overlap_intersect <- intersect(shps_tiles[[1]],shps_tiles[[2]]))
216
  # 
217
  # names(overlap_intersect) <- basename(in_dir_reg)
218
  # shp_selected <- unlist(lapply(1:length(overlap_intersect),function(i){!is.null(overlap_intersect[[i]])}))
219
  # test_list <- overlap_intersect[shp_selected]
220
  # spdf_tiles_test <- do.call(bind, test_list) #combines all intersect!!
221
  # #ll <- ll[ ! sapply(ll, is.null) ]
222
  # test <- overlap_intersect[!lapply(overlap_intersect,is.null)]
223
  # spdf_tiles_test <- do.call(bind, test) #combines all intersect!!
224
  # #ll <- ll[ ! sapply(ll, is.null) ]
225
  # spdf_tiles <- do.call(bind, overlap_intersect[1:4]) #combines all intersect!!
226
  # spdf_tiles_test <- do.call(bind, test) #combines all intersect!!
227
  # 
228
  # plot(spdf_tiles_test,add=T,border="green",usePolypath = FALSE) #added usePolypath following error on brige and NEX
229
  # 
230
  # matrix_overlap%*%df_missing[1,1:26]
231
  # 
232
  # 
233
  # ## For each day can do overalp matrix* prediction
234
  # ## if prediction and overlap then 1 else 0, if no-overlap is then NA
235
  # ## then for each tile compute the number of excepted predictions taken into account in a tile
236
  # 
237
  # #combine polygon
238
  # #http://gis.stackexchange.com/questions/155328/merging-multiple-spatialpolygondataframes-into-1-spdf-in-r
239
  # 
240
  # #http://gis.stackexchange.com/questions/116388/count-overlapping-polygons-in-single-shape-file-with-r
241
  # 
242
  # #### Use the predictions directory
243
  # #By region
244
  # #For each polygon/tile find polygon overlapping with count and ID (like list w)
245
  # #for each polygon/tile and date find if there is a prediction using the tif (multiply number)
246
  # #for each date of year report data in table.
247
  # 
248
  # #go through table and hsow if there are missing data (no prediction) or report min predictions for tile set?
249
  #   
250
  # #for each polygon find you overlap!!
251
  # #plot number of overlap
252
  # #for specific each find prediction...
207

  

Also available in: Unified diff