Revision 22ed7a16
Added by Benoit Parmentier about 8 years ago
climate/research/oregon/interpolation/global_product_assessment_part2.R | ||
---|---|---|
300 | 300 |
list_param=list_param_plot_raster_mosaic) |
301 | 301 |
l_dates <- list_dates_produced_date_val |
302 | 302 |
r_stack_subset <- r_stack |
303 |
zlim_val <- NULL |
|
304 |
list_param_plot_raster_mosaic <- list(l_dates,r_stack_subset,NA_flag_val,out_dir,out_suffix, |
|
305 |
region_name,variable_name, zlim_val) |
|
306 |
names(list_param_plot_raster_mosaic) <- c("l_dates","r_mosaiced_scaled","NA_flag_val_mosaic","out_dir","out_suffix", |
|
307 |
"region_name","variable_name","zlim_val") |
|
308 | 303 |
|
309 | 304 |
lf_mosaic_plot_fig <- mclapply(1:length(l_dates), |
310 | 305 |
FUN=plot_raster_mosaic, |
311 | 306 |
list_param=list_param_plot_raster_mosaic, |
312 | 307 |
mc.preschedule=FALSE, |
313 |
mc.cores = num_cores) |
|
308 |
mc.cores = num_cores) |
|
309 |
|
|
314 | 310 |
if(is.null(zlim_val)){ |
315 | 311 |
out_suffix_movie <- paste("min_max_",out_suffix,sep="") |
316 | 312 |
}else{ |
317 | 313 |
zlim_val_str <- paste(zlim_val,sep="_",collapse="_") |
318 | 314 |
out_suffix_movie <- paste(zlim_val_str,"_",out_suffix,sep="") |
319 | 315 |
} |
316 |
r_stack_subset <- subset(r_stack,1:11) |
|
317 |
l_dates <- list_dates_produced_date_val[1:11] |
|
320 | 318 |
|
321 |
#filename_figures_mosaic <- file.path(out_dir,"mosaic_plot_fig.txt") |
|
322 |
filename_figures_mosaic <- file.path(out_dir,paste("list_mosaic_plot_fig",out_suffix_movie,".txt",sep="")) |
|
323 |
out_figure_movies <- file.path(out_dir,paste("mosaic_movie_",out_suffix_movie,".gif",sep="")) |
|
324 |
|
|
325 |
write.table(unlist(lf_mosaic_plot_fig),filename_figures_mosaic,row.names = F,col.names = F,quote = F) |
|
319 |
write.table(unlist(lf_mosaic_plot_fig[1:11]),filenames_figures,row.names = F,col.names = F,quote = F) |
|
326 | 320 |
#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="./", |
|
327 |
out_filename_figure_animation=NULL) |
|
328 |
|
|
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 |
|
327 | 344 |
|
328 |
#-delay 20 |
|
329 |
delay_option <- 60 |
|
330 |
cmd_str <- paste("convert",paste("-delay",delay_option),paste0("@",filename_figures_mosaic),out_figure_movies) |
|
331 |
#convert @myimages.txt mymovie.gif |
|
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) |
|
332 | 359 |
|
333 |
system(cmd_str)
|
|
360 |
}
|
|
334 | 361 |
|
335 | 362 |
#### PLOT ACCURACY METRICS: First test #### |
336 | 363 |
##this will be cleaned up later: |
Also available in: Unified diff
creating function to generate animation from mosaic figures png files