Project

General

Profile

« Previous | Next » 

Revision e8753de4

Added by Benoit Parmentier about 8 years ago

moving check missing function and testing it

View differences:

climate/research/oregon/interpolation/global_product_assessment_part2.R
4 4
#This part 2 of the assessment focuses on graphics to explore the spatial patterns of raster times series as figures and movie
5 5
#AUTHOR: Benoit Parmentier 
6 6
#CREATED ON: 10/03/2016  
7
#MODIFIED ON: 10/10/2016            
7
#MODIFIED ON: 10/19/2016            
8 8
#Version: 1
9 9
#PROJECT: Environmental Layers project     
10 10
#COMMENTS: Initial commit, script based on part NASA biodiversity conferenc 
......
18 18
#source /nobackupp6/aguzman4/climateLayers/sharedModules2/etc/environ.sh 
19 19
#
20 20
#setfacl -Rm u:aguzman4:rwx /nobackupp6/aguzman4/climateLayers/LST_tempSpline/
21
#COMMIT: generating animation for reg6 (Australia and South East Asia)
21
#COMMIT: moving check missing function and testing it
22 22

  
23 23
#################################################################################################
24 24

  
......
86 86
#Product assessment
87 87
function_product_assessment_part1_functions <- "global_product_assessment_part1_functions_09192016b.R"
88 88
source(file.path(script_path,function_product_assessment_part1_functions)) #source all functions used in this script 
89
function_product_assessment_part2_functions <- "global_product_assessment_part2_functions_10102016b.R"
89
function_product_assessment_part2_functions <- "global_product_assessment_part2_functions_10192016.R"
90 90
source(file.path(script_path,function_product_assessment_part2_functions)) #source all functions used in this script 
91 91

  
92 92
###############################
......
128 128
#in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg5/mosaic/mosaic"
129 129
in_dir <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg6/assessment"
130 130
in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg6/mosaics/mosaic" #predicted mosaic
131
#/data/project/layers/commons/NEX_data/climateLayers/out/reg4/mosaic/mosaic
131 132

  
132 133
region_name <- c("reg6") #param 6, arg 3
133 134
out_suffix <- "global_assessment_reg6_10102016"
......
197 198

  
198 199
###########  ####################
199 200

  
200
in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg6/mosaics/mosaic"
201
############ Using predicting first ##########
202

  
201 203
## using predictions
202 204
if(is.null(lf_raster)){
203 205
  
......
228 230
#day_start <- "1984101" #PARAM 12 arg 12
229 231
#day_end <- "20141231" #PARAM 13 arg 13
230 232

  
231
check_missing <- function(lf, pattern_str=NULL,in_dir=".",date_start="1984101",date_end="20141231",item_no=13,out_suffix=""){
232
  #Function to check for missing files such as mosaics or predictions for tiles etc.
233
  #The function assumes the name of the files contain "_".
234
  #INPUTS:
235
  #lf
236
  #pattern_str
237
  #in_dir
238
  #date_start
239
  #date_end
240
  #item_no
241
  #out_suffix
242
  #OUTPUTS
243
  #
244
  #
245
  
246
  ##### Start script #####
247
  
248
  out_dir <- in_dir
249
  
250
  list_dates_produced <- unlist(mclapply(1:length(lf),
251
                                         FUN = extract_date,
252
                                         x = lf,
253
                                         item_no = item_no,
254
                                         mc.preschedule = FALSE,
255
                                         mc.cores = num_cores))
256
  
257
  list_dates_produced_date_val <- as.Date(strptime(list_dates_produced, "%Y%m%d"))
258
  month_str <- format(list_dates_produced_date_val, "%b") ## Month, char, abbreviated
259
  year_str <- format(list_dates_produced_date_val, "%Y") ## Year with century
260
  day_str <- as.numeric(format(list_dates_produced_date_val, "%d")) ## numeric month
261
  df_files <- data.frame(lf = basename(lf),
262
                          date = list_dates_produced_date_val,
263
                          month_str = month_str,
264
                          year = year_str,
265
                          day = day_str,
266
                          dir = dirname(lf))
267
  
268
  df_files_fname <- file.path(out_dir, paste0("df_files_", out_suffix, ".txt"))
269
  write.table(df_files,file = df_files_fname,sep = ",",row.names = F)
270
  
271
  #undebug(finding_missing_dates )
272
  missing_dates_obj <- finding_missing_dates (date_start,date_end,list_dates_produced_date_val)
273
  
274
  df_time_series <- missing_dates_obj$df_dates
275
  df_time_series$date <- as.character(df_time_series$date)  
276
  df_files$date <- as.character(df_files$date)
277
  
278
  df_time_series <- merge(df_time_series,df_files,by="date",all=T) #outer join to keep missing dates
279
  
280
  df_time_series$month_str <- format(as.Date(df_time_series$date), "%b") ## Month, char, abbreviated
281
  df_time_series$year_str <- format(as.Date(df_time_series$date), "%Y") ## Year with century
282
  df_time_series$day <- as.numeric(format(as.Date(df_time_series$date), "%d")) ## numeric month
233
debug(check_missing)
234
test_missing <- check_missing(lf=lf_raster, 
235
                              pattern_str=NULL,
236
                              in_dir=".",
237
                              date_start="1984101",
238
                              date_end="20141231",
239
                              item_no=13,
240
                              out_suffix="")
283 241
  
284
  df_time_series_fname <- file.path(out_dir,paste0("df_time_series_",out_suffix,".txt")) #add the name of var later (tmax)
285
  write.table(df_time_series,file= df_time_series_fname,sep=",",row.names = F) 
286
  
287
  df_time_series_obj <- list(df_raster_fname,df_time_series_fname,df_time_series)
288
  names(df_time_series_obj) <- c("df_raster_fname","df_time_series_fname","df_time_series")
289
  
290
  ## report in text file missing by year and list of dates missing in separate textfile!!
291
  return(df_time_series_obj)
292
}
242
test_missing <- check_missing(lf=lf_raster, 
243
                              pattern_str=NULL,
244
                              in_dir=".",
245
                              date_start="1984101",
246
                              date_end="20141231",
247
                              item_no=13,
248
                              out_suffix="")
293 249

  
250
#############################
251
##### Creating animation based on prediction
294 252

  
295 253
#####
296 254
NAvalue(r_stack)
......
298 256
#plot(r_stack,zlim=c(-50,50),col=matlab.like(255))
299 257
var_name <- "dailyTmax"
300 258

  
301

  
302

  
303

  
304

  
305

  
306 259
#debug(plot_and_animate_raster_time_series)
307 260

  
308 261
metric_name <- "var_pred" #use RMSE if accuracy
......
323 276
                                    out_suffix=out_suffix,
324 277
                                    out_dir=out_dir)
325 278

  
326

  
327 279
############ Now accuracy
328 280
#### PLOT ACCURACY METRICS: First test ####
329 281
##this will be cleaned up later:

Also available in: Unified diff