Title: | simulate fish tracks & acoustic detections |
---|---|
Description: | facilitates simulation of fish tracks in featureless and semi-realistic environments (coastal oceans, fjords, and lakes). A user-defined raster defining the water body - land boundaries is used to constrain simulated tracks. Fish movements are simulated (currently) as either a correlated random walk or a biased & correlated random walk, with the bias toward a defined Centre-of-Attraction. A potential function is used to ensure the tracks avoid land. The package can also be used to simulate detections of acoustically-tagged fish by acoustic receivers at user-defined locations. |
Authors: | Ian Jonsen |
Maintainer: | Ian Jonsen <[email protected]> |
License: | AGPL-3 |
Version: | 0.2-08.9010 |
Built: | 2024-11-20 04:52:16 UTC |
Source: | https://github.com/mhpob/simfish |
simulate fish tracks & acoustic detections
**Maintainer:** Ian Jonsen <[email protected]> [ORCID](https://orcid.org/0000-0001-5423-6076)
Useful Links: * [https://github.com/ianjonsen/simfish/](https://github.com/ianjonsen/simfish/) * Report bugs/issues at [https://github.com/ianjonsen/simfish/issues/](https://github.com/ianjonsen/simfish/issues/)
A helper function to calculate the logisitc regression intercept and/or slope parameters used to simulate acoustic detection probability as a function of distance between transmitter and receiver
calc_pdrf( pdet = NULL, dist = NULL, int = 5, slope = NULL, plot = FALSE, dmax = 1000, dint = 20 )
calc_pdrf( pdet = NULL, dist = NULL, int = 5, slope = NULL, plot = FALSE, dmax = 1000, dint = 20 )
pdet |
probability of detection |
dist |
distance (in m) between transmitter and receiver |
int |
intercept parameter from a logistic regression of distance on p(detection). Default value is 5. |
slope |
slope parameter from a logistic regression of distance on p(detection). Default is NULL. |
plot |
logical (default = FALSE); plot the relationship. |
dmax |
maximum distance to be plotted. Ignored if plot = FALSE. |
dint |
plotting interval between distances. Ignored if plot = FALSE. |
The int
default value (5) is based on empirical data collected from
sentinel tags and receivers on the Ocean Tracking Network's Halifax line
(https://members.oceantrack.org/OTN/project?ccode=HFX).
the intercept and slope parameters, given pdet
, dist
, and
one of int
or slope
.
Ian Jonsen [email protected]
# calculate slope calc_pdrf(pdet = 0.5, dist = 250, int = 5) # calculate intercept calc_pdrf(pdet = 0.5, dist = 250, slope = -0.02, int = NULL) # calculate slope and plot relationship calc_pdrf(pdet = 0.5, dist = 250, int = 5, plot = TRUE)
# calculate slope calc_pdrf(pdet = 0.5, dist = 250, int = 5) # calculate intercept calc_pdrf(pdet = 0.5, dist = 250, slope = -0.02, int = NULL) # calculate slope and plot relationship calc_pdrf(pdet = 0.5, dist = 250, int = 5, plot = TRUE)
check for barriers between start and end (CoA) points & find route
around barriers via intermediate CoA's to be used by sim_fish()
. Can be
called prior to sim_fish()
or within sim_fish()
.
find_route( data, mpar, coas = 12, npts = 40, land.buff = 2, buffer = 5, centroids = FALSE, keep.coas = NULL )
find_route( data, mpar, coas = 12, npts = 40, land.buff = 2, buffer = 5, centroids = FALSE, keep.coas = NULL )
data |
|
mpar |
|
coas |
|
npts |
|
land.buff |
|
buffer |
|
centroids |
|
keep.coas |
|
a list including a matrix of calculated CoA's and a ggplot2
object
visualizing the CoA's. The visualization is useful for determining whether to
use all the CoA's or subset them, and for helping to diagnose route-finding
failures.
create environmental raster to constraint simulated tracks
generate_env( ext = NULL, prj = "+proj=merc +datum=WGS84 +units=km", res = c(1, 1), grad = FALSE, dist = 0 )
generate_env( ext = NULL, prj = "+proj=merc +datum=WGS84 +units=km", res = c(1, 1), grad = FALSE, dist = 0 )
ext |
longitude and latitude extents as a 4-element vector: (xmin, ymin, xmax, ymax) |
prj |
a crs string or EPSG defining the projection for the raster with
units in km. The default projection is a Mercator grid:
|
res |
resolution of output raster in x,y km (default is 1 km). Smaller values yield higher resolution but longer computation times. |
grad |
(logical) generate gradient rasters. The gradient rasters (gradient of distance from water in x and y directions) are required by the potential function used to simulate tracks. |
dist |
buffer distance (km) to add to land. This can be used when generating the gradient rasters to keep tracks a specified distance from land. The default is 0 km, no buffer. |
the terra
package is used to generate the land and gradient
rasters as SpatRaster objects. This allows higher-resolution rasters to be
generated faster than with the raster
package. The SpatRaster objects are
converted to RasterLayer (land barrier) and RasterStack (gradients) objects
for use in sim_fish
.
a raster defining the simulation environment (i.e., ocean with land barriers). Optionally, the gradient rasters, required for the simulation potential function, can also be generated. Only one of the environment raster or the gradient rasters can be returned.
x <- generate_env(ext = c(-70,43,-52,53), res = c(5,5)) raster::plot(x)
x <- generate_env(ext = c(-70,43,-52,53), res = c(5,5)) raster::plot(x)
a map of single or multiple simulated tracks
map( x, env = NULL, land.poly = TRUE, by.id = FALSE, coas = FALSE, term.pts = TRUE, zoom = FALSE, downsample = 0, ... )
map( x, env = NULL, land.poly = TRUE, by.id = FALSE, coas = FALSE, term.pts = TRUE, zoom = FALSE, downsample = 0, ... )
x |
a simfish simulation object |
env |
... |
land.poly |
logical (default: TRUE); should land be displayed using rnaturalearth spatial polygon data, or using the raster used by the simulation. The former will look smoother in higher resolution images. |
by.id |
logical (default: FALSE); if x is a multi-track object then colour tracks by id |
coas |
logical (default: FALSE); should CoA's be displayed on map |
term.pts |
logical (default: TRUE); should terminal (start, end) points be displayed on map |
zoom |
logical (default: FALSE); should map be zoomed to extent of
simulated track, otherwise map uses extents from the land raster in |
downsample |
speed up map rendering by down-sampling the land raster,
e.g., |
... |
graphical parameters. Arguments that can be passed to
|
a ggplot object
Ian Jonsen [email protected]
assumes detection is a logistic fn of distance in 3-D
pdet(trs = NULL, rec = NULL, b = NULL, noise = 1)
pdet(trs = NULL, rec = NULL, b = NULL, noise = 1)
trs |
- a tibble of transmission locations (in m) with: id, x, y, et and line id |
rec |
- a data.frame of receiver locations (in m) with: x, y, z |
b |
- a vector of two parameters (intercept & slope) for logistic detection range function |
noise |
- range 0 - 1; simulate effect of noisy environment. Reduces detection prob w dist by specified proportion; default = 1, no reduction |
Ian Jonsen [email protected]
a simple visualization of single or multiple simulated tracks
## S3 method for class 'simfish' plot(x, by.id = FALSE, ...)
## S3 method for class 'simfish' plot(x, by.id = FALSE, ...)
x |
a simfish simulation object |
by.id |
logical (default: FALSE); if x is a multi-track object then colour tracks by id |
... |
additional arguments to be ignored |
a ggplot object
Ian Jonsen [email protected]
my.par <- sim_par(N = 1440, time.step = 5, start = c(0, 0), coa = c(0,30)) z <- sim_fish(id = 1, mpar = my.par) plot(z)
my.par <- sim_par(N = 1440, time.step = 5, start = c(0, 0), coa = c(0,30)) z <- sim_fish(id = 1, mpar = my.par) plot(z)
simulate
& sim_setup
outputsimulates transmissions & detections along simulated track segments within a defined range of acoustic array(s)
sim_detect(s, data, delay = c(50, 130), burst = 5, noise = 1)
sim_detect(s, data, delay = c(50, 130), burst = 5, noise = 1)
s |
- a simfish class list containing output from sim_fish |
data |
- a list containing required environmental data, including receiver locations with x,y,z coordinates, where z is receiver depth. |
delay |
- min & max time intervals (s) between transmissions |
burst |
- duration of each transmission (s) |
noise |
- range 0 - 1; simulate effect of noisy environment. Reduces detection prob w dist by specified proportion; default = 1, no reduction |
Ian Jonsen [email protected]
simulates fish tracks in featureless or semi-realistic environments. Semi-realistic environments are user-defined rasters of water bounded by land, which constrain the simulated tracks. User-supplied acoustic receiver locations can be used to simulate acoustic detections based on a user-defined detection probability with distance. Utility functions are provided to generate water-land rasters ('generate_land()'), required gradient rasters ('generate_grad()'), and to convert acoustic tag detection range expectations into logistic regression parameters ('calc_pdrf()').
sim_fish(id = 1, data = NULL, mpar = sim_par(), route = TRUE, ...)
sim_fish(id = 1, data = NULL, mpar = sim_par(), route = TRUE, ...)
id |
- identifier for simulation run (individual fish) |
data |
- a list of required data. If missing then simulation runs on a Cartesian grid (a featureless environment). |
mpar |
- simulation control parameters supplied as a list using 'sim_par()' See '?sim_par' for details on the simulation parameters. |
route |
(logical) turns route-finding on or off (default is TRUE, on) |
... |
additional, optional arguments to 'find_route()' |
## A minimal example - simulation with no environment my.par <- sim_par(N = 500, time.step = 10, start = c(0, 0), coa = c(0,30)) z <- sim_fish(id = 1, mpar = my.par) plot(z) ## Simulate in a semi-realistic environment x <- generate_env(ext = c(-70,43,-52,53), res = c(5,5), grad = TRUE) my.par <- sim_par(N=400, time.step=60*6, start = c(-7260, 5930), coa = c(-6300, 6680), nu = 0.6, rho = 0.7) z <- sim_fish(id = 1, data = x, mpar = my.par) map(z, env = x)
## A minimal example - simulation with no environment my.par <- sim_par(N = 500, time.step = 10, start = c(0, 0), coa = c(0,30)) z <- sim_fish(id = 1, mpar = my.par) plot(z) ## Simulate in a semi-realistic environment x <- generate_env(ext = c(-70,43,-52,53), res = c(5,5), grad = TRUE) my.par <- sim_par(N=400, time.step=60*6, start = c(-7260, 5930), coa = c(-6300, 6680), nu = 0.6, rho = 0.7) z <- sim_fish(id = 1, data = x, mpar = my.par) map(z, env = x)
sim_fish
Define simulation parameters
sim_par(...)
sim_par(...)
... |
simulation parameters:
|
Returns a list of simulation parameters to be used by sim_fish
.
See example, below
## A minimal example - simulation with no environment my.par <- sim_par(N = 1440, time.step = 5, start = c(0, 0), coa = c(0,30)) z <- sim_fish(id = 1, mpar = my.par) plot(z)
## A minimal example - simulation with no environment my.par <- sim_par(N = 1440, time.step = 5, start = c(0, 0), coa = c(0,30)) z <- sim_fish(id = 1, mpar = my.par) plot(z)