extract_covariates {amt}R Documentation

Extract covariate values

Description

Extract the covariate values at relocations, or at the beginning or end of steps.

Usage

extract_covariates(x, ...)

## S3 method for class 'track_xy'
extract_covariates(x, covariates, ...)

## S3 method for class 'random_points'
extract_covariates(x, covariates, ...)

## S3 method for class 'steps_xy'
extract_covariates(x, covariates, where = "end", ...)

extract_covariates_along(x, ...)

## S3 method for class 'steps_xy'
extract_covariates_along(x, covariates, ...)

extract_covariates_var_time(x, ...)

## S3 method for class 'track_xyt'
extract_covariates_var_time(
  x,
  covariates,
  when = "any",
  max_time,
  name_covar = "time_var_covar",
  ...
)

## S3 method for class 'steps_xyt'
extract_covariates_var_time(
  x,
  covariates,
  when = "any",
  max_time,
  name_covar = "time_var_covar",
  where = "end",
  ...
)

Arguments

x

[track_xy, track_xyt, steps]
Either a track created with mk_track or track, or steps.

...

Additional arguments passed to terra::extract().

covariates

⁠[SpatRaster]⁠
The (environmental) covariates. For extract_covariates_var_time the argument covariates need to have a z-column (i.e. the time stamp).

where

⁠[character(1)="end"]{"start", "end", "both"}⁠
For steps this determines if the covariate values should be extracted at the beginning or the end of a step. or end.

when

⁠[character(1)="any"]{"any", "before", "after"}⁠
Specifies for for extract_covariates_var_time whether to look before, after or in both direction (any) for the temporally closest environmental raster.

max_time

⁠[Period(1)]⁠
The maximum time difference between a relocation and the corresponding raster. If no rasters are within the specified max. distance NA is returned.

name_covar

⁠[character(1)="time_var_covar"]⁠
The name of the new column.

Details

extract_covariates_along extracts the covariates along a straight line between the start and the end point of a (random) step. It returns a list, which in most cases will have to be processed further.

Value

A tibble with additional columns for covariate values.

Examples

data(deer)
sh_forest <- get_sh_forest()
mini_deer <- deer[1:20, ]
mini_deer |> extract_covariates(sh_forest)
mini_deer |> steps() |> extract_covariates(sh_forest)


# Illustration of extracting covariates along the a step
mini_deer |> steps() |> random_steps() |>
  extract_covariates(sh_forest) |> # extract at the endpoint
  (\(.) mutate(., for_path = extract_covariates_along(., sh_forest)))()  |>
  # 1 = forest, lets calc the fraction of forest along the path
  mutate(for_per = purrr::map_dbl(for_path, function(x) mean(x == 1)))


[Package amt version 0.2.2.0 Index]