This function is a simple wrapper for pf_plot_history and saveHTML which creates an animation of the particle filtering (PF) algorithm(s) over time. To implement this function, a named list of arguments for pf_plot_history, which creates the plots, must be supplied. This is embedded within saveHTML, which creates a folder in the specified directory named `images' that contains a .png file for each time step and an animation as a .html file.

pf_animate_history(
  expr_param,
  dir = NULL,
  html_name = "PF_algorithm_demo.html",
  image_name = "PF",
  html_title = "Demonstration of PF",
  html_description = "",
  navigator = FALSE,
  ani_height = 1000,
  ani_width = 1000,
  ani_res = 150,
  interval = 0.1,
  verbose = FALSE,
  ...
)

Arguments

expr_param

A named list of arguments, passed to pf_plot_history, to create plots.

dir

(optional) A string that defines the directory in which to save files. If unsupplied, if available, dir is taken from html_name using dirname.

html_name

A string that defines the name of the html file (see `htmlfile' argument in saveHTML).

image_name

A string that defines the names of the individual .png files creates (see `img.name' argument in saveHTML).

html_title, html_description

Character strings that provide a title and a description that are displayed within the html animation (see `title' and `description' arguments in saveHTML).

navigator

A logical variable that defines whether or not to add a navigator panel to the animation (see `navigator' argument in saveHTML).

ani_height, ani_width, ani_res

Numbers that define the size and the resolution of the animation (see `ani.height' `ani.width' and `ani.res' arguments in ani.options).

interval

A number that defines the time interval between sequential frames (see `interval' argument in ani.options).

verbose

A logical or character variable that defines whether or not, or what, to write as a footer to the html animation (see `verbose' argument in ani.options).

...

Additional arguments passed to ani.options.

Value

The function produces an animation in .html format in the specified directory. A folder named `images' is also produced which contains the images for each time step. The `css' and `js' folders are also produced by saveHTML which creates the animation.

Details

This function requires the animation package.

Author

Edward Lavender

Examples

#### Example (1): Create a zoomed-in animation
pf_animate_history(
  expr_param = list(
    archive = dat_dcpf_histories,
    add_particles = list(
      cex = 2.5, pch = 21,
      col = "black", bg = "black"
    ),
    prompt = FALSE
  ),
  dir = tempdir(),
  interval = 0.25
)
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> HTML file created at: PF_algorithm_demo.html

#### Example (2): Create a wider scale animation
boundaries <- raster::extent(dat_coast)
pf_animate_history(
  expr_param = list(
    archive = dat_dcpf_histories,
    add_particles = list(
      cex = 0.5, pch = 21,
      col = "black", bg = "black"
    ),
    add_polys = list(x = dat_coast, col = "brown"),
    xlim = boundaries[1:2], ylim = boundaries[3:4],
    prompt = FALSE
  ),
  dir = tempdir()
)
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> Spatial layers do not have identical CRS strings
#> prettyGraphics::pretty_map() CRS taken as: 'NA'.
#> HTML file created at: PF_algorithm_demo.html