Learn R Programming

puff (version 0.1.0)

plot_3d_animated: Plot a 3D Animated Plot for Concentration Over Time

Description

This function generates a 3D animated plot (scatter or contour) using `plotly` to visualize the movement of a plume over time. The animation is based on grid concentration data from `simulate_grid_mode()` output.

Usage

plot_3d_animated(
  data,
  grid_coords,
  start,
  end,
  output_dt,
  frames = 100,
  transition = 99,
  plot_type = "contour",
  save = FALSE
)

Value

A `plotly` object representing the animated plot.

Arguments

data

A matrix or array of grid concentration results from `simulate_grid_mode()`.

grid_coords

A list containing the same grid coordinates passed to `simulate_grid_mode()`.

start

A character string specifying the start time of the simulation (e.g., "YYYY-MM-DD HH:MM:SS").

end

A character string specifying the end time of the simulation (e.g., "YYYY-MM-DD HH:MM:SS").

output_dt

A character string or numeric value specifying the time interval between outputs.

frames

Numeric. Duration between frames in the animation (milliseconds). Default is 100.

transition

Numeric. Duration for transitioning between frames (milliseconds). Default is 99.

plot_type

Character. "contour" (default) or "scatter" to specify the type of plot.

save

Logical. If `TRUE`, saves the plot as an HTML file named `2D_heatmap.html` and specifies saved location. Default set to `FALSE`.

Examples

Run this code
# \donttest{
set.seed(123)

sim_dt <- 10
puff_dt <- 10
output_dt <- 60
start_time <- "2024-01-01 12:00:00"
end_time <- "2024-01-01 13:00:00"
source_coords <- c(0, 0, 2.5)
emission_rate <- 3.5
wind_data <- data.frame(
  wind_u = runif(3601, min = -3, max = 0.7),
  wind_v = runif(3601, min = -3, max = 1.5)
)

grid_coords <- list(
  x = seq(-2, 2, by = 1),
  y = seq(-2, 2, by = 1),
  z = seq(0, 5, by = 1)
)

out <- simulate_grid_mode(
  start_time = start_time,
  end_time = end_time,
  source_coords = source_coords,
  emission_rate = emission_rate,
  wind_data = wind_data,
  grid_coords = grid_coords,
  sim_dt = sim_dt,
  puff_dt = puff_dt,
  output_dt = output_dt,
  puff_duration = 1200
)

plot_3d_animated(out,
   grid_coords,
   start_time, end_time,
   output_dt)
# }

Run the code above in your browser using DataLab