Project

General

Profile

« Previous | Next » 

Revision 7afb4484

Added by Benoit Parmentier about 8 years ago

testing function to generate animation and moving to function script

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/03/2016            
7
#MODIFIED ON: 10/09/2016            
8 8
#Version: 1
9 9
#PROJECT: Environmental Layers project     
10 10
#COMMENTS: Initial commit, script based on part NASA biodiversity conferenc 
......
19 19
#
20 20
#setfacl -Rmd user:aguzman4:rwx /nobackupp8/bparmen1/output_run10_1500x4500_global_analyses_pred_1992_10052015
21 21

  
22
#COMMIT: plotting extracted predicted values and measured tmax 
22
#COMMIT: testing function to generate animation and moving to function script
23 23

  
24 24
#################################################################################################
25 25

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

  
93 93
###############################
......
281 281
##################################### PART 5  ######
282 282
##### Plotting specific days for the mosaics
283 283

  
284
function_product_assessment_part2_functions <- "global_product_assessment_part2_functions_10032016b.R"
284
function_product_assessment_part2_functions <- "global_product_assessment_part2_functions_10092016.R"
285 285
source(file.path(script_path,function_product_assessment_part2_functions)) #source all functions used in this script 
286 286

  
287 287
#NA_flag_val_mosaic <- -3399999901438340239948148078125514752.000
......
316 316
r_stack_subset <- subset(r_stack,1:11)
317 317
l_dates <- list_dates_produced_date_val[1:11]
318 318

  
319
write.table(unlist(lf_mosaic_plot_fig[1:11]),filenames_figures,row.names = F,col.names = F,quote = F)
319
filenames_figures_mosaic <- "test_animation_reg1.txt"
320

  
321
write.table(unlist(lf_mosaic_plot_fig[1:11]),filenames_figures_mosaic,row.names = F,col.names = F,quote = F)
320 322
#now generate movie with imageMagick
321
debug(generate_animation_from_figures_fun)
322
generate_animation_from_figures_fun(filenames_figures="list_mosaic_plot_figmin_max__global_assessment_reg1_10032016.txt",
323
                                    frame_speed=60,
324
                                    format_file=".gif",
325
                                    out_suffix="",
326
                                    out_dir="./",
323
frame_speed <- 60
324
animation_format <- ".gif"
325
out_suffix_str <- out_suffix
326

  
327
#debug(generate_animation_from_figures_fun)
328
generate_animation_from_figures_fun(filenames_figures= filenames_figures_mosaic,
329
                                    frame_speed=frame_speed,
330
                                    format_file=animation_format,
331
                                    out_suffix=out_suffix_str,
332
                                    out_dir=out_dir,
327 333
                                    out_filename_figure_animation=NULL)
328 334
  
329
generate_animation_from_figures_fun <- function(filenames_figures,frame_speed=60,format_file=".gif",out_suffix="",out_dir=".",out_filename_figure_animation=NULL){
330

  
331
  if(is.null(out_filename_figure_animation)){
332
    #out_filename_figure_movies <- file.path(out_dir,paste("mosaic_movie_",out_suffix_movie,".gif",sep=""))
333
    out_filename_figure_animation <- file.path(out_dir,paste("animation_frame_",frame_speed,"_",out_suffix,format_file,sep=""))
334
  }
335
  
336
  if(class(filenames_figures)=="list"){
337
    #filename_figures_mosaic <- file.path(out_dir,"mosaic_plot_fig.txt")
338
    out_filenames_figures <- file.path(out_dir,paste("list_figures_animation_",out_suffix,".txt",sep=""))
339
    write.table(unlist(filenames_figures),out_filenames_figures,row.names = F,col.names = F,quote = F)
340
    filenames_figures <- out_filenames_figures
341
  }
342
  
343
  #now generate movie with imageMagick
335
generate_animation_from_figures_fun(filenames_figures= filenames_figures_mosaic,
336
                                    frame_speed=frame_speed,
337
                                    format_file=animation_format,
338
                                    out_suffix=out_suffix_str,
339
                                    out_dir=out_dir,
340
                                    out_filename_figure_animation="test.gif")
344 341

  
345
  #-delay 20
346
  #delay_option <- 60
347
  delay_option <- frame_speed
348
  
349
  cmd_str <- paste("convert",
350
                   paste("-delay",delay_option),
351
                   paste0("@",filenames_figures),
352
                   out_filename_figure_animation)
353
  #convert @myimages.txt mymovie.gif
354
  #save cmd_str in text file!!!
355
  
356
  system(cmd_str)
357
  
358
  return(out_filename_figure_animation)
359 342

  
360
}
361 343

  
362 344
#### PLOT ACCURACY METRICS: First test ####
363 345
##this will be cleaned up later:

Also available in: Unified diff