knitr::opts_chunk$set(echo = TRUE)
remotes::install_github("ianjonsen/aniMotum@dev", dependencies = TRUE)
require(tidyverse, quietly = TRUE) require(aniMotum, quietly = TRUE)
crw
SSM with 12 h time.stepfit <- fit_ssm(sese2, model = "crw", time.step = 12, control = ssm_control(verbose = 0))
trs <- sim_fit(fit[2,], what = "p", reps = 200, cpf = TRUE) plot(trs)
trs.f1 <- sim_filter(trs, keep = 0.3, flag = 1) plot(trs.f1)
trs.fll <- sim_filter(trs, keep = 0.3, var = c("lon","lat"), FUN = "mean") plot(trs.fll)
trs.fllr <- route_path(trs.fll, centroids = TRUE) plot(trs.fllr)
## read SpatRaster chl <- terra::rast("chl.grd") terra::plot(chl) trs.df <- unnest(trs.fllr, cols = c(sims)) ## extract chl values at track locations trs.df <- trs.df |> mutate(terra::extract(chl, cbind(lon, lat))) |> rename(chl = chl_summer_climatology) ## convert back to nested tibble trs.n <- nest(trs.df, sims = c(rep, date, lon, lat, x, y, chl)) ## append new nested tibble with correct aniMotum classes so sim_filter works class(trs.n) <- append(class(trs.fllr)[1:2], class(trs.n))
## try filtering on mean chl trs.chl.mn <- sim_filter(trs.n, keep = 0.15, var = "chl", FUN = "mean", na.rm = TRUE)
plot(trs.chl.mn) ## all tracks tmp.a <- unnest(trs.n, cols = c(sims)) ## filtered tracks tmp.f <- unnest(trs.chl.mn, cols = c(sims)) ## Kernel densities of all Chl values d.all <- density(tmp.a$chl, na.rm = TRUE) ## densities of Chl values from estimated track d.e <- density(subset(tmp.f, rep == 0)$chl, na.rm = TRUE) ## densities of Chl values from filtered random tracks d.s <- density(subset(tmp.f, rep > 0)$chl, na.rm = TRUE) ## plot density of all chl values plot(d.all, ylim = c(0, 1.75), lwd = 2) ## add density of Chl from estimated track lines(d.e, col = "red", lwd = 2) ## add density of Chl from filtered random tracks lines(d.s, col = "blue", lwd = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.