Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8210790
Showing
46 changed files
with
5,100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Package: movegroup | ||
Title: Visualizing and Quantifying Space Use Data for Groups of Animals | ||
Version: 2024.03.05 | ||
Authors@R: c( | ||
person("Simon", "Dedman", email = "simondedman@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9108-972X")), | ||
person("Maurits", "van Zinnicq Bergmann", email = "mauritsvzb@gmail.com", role = c("aut"), comment = c(ORCID = "0000-0002-8414-5025"))) | ||
Description: Offers an easy and automated way to scale up individual-level space use analysis to | ||
that of groups. Contains a function from the 'move' package to calculate a dynamic Brownian | ||
bridge movement model from movement data for individual animals, as well as functions to | ||
visualize and quantify space use for individuals aggregated in groups. Originally written with | ||
passive acoustic telemetry in mind, this package also provides functionality to account for | ||
unbalanced acoustic receiver array designs, and satellite tag data. | ||
Depends: R (>= 4.1.0) | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
Language: en-GB | ||
LazyData: true | ||
Imports: ggplot2 (>= 3.3.5), utils, beepr (>= 1.3), dplyr (>= 1.0.8), | ||
ggmap (>= 3.0.0), knitr (>= 1.45), lubridate (>= 1.8.0), magick | ||
(>= 2.8.2), methods, move (>= 4.1.6), purrr (>= 1.0.2), raster | ||
(>= 3.5-15), rlang (>= 1.0.2), sf (>= 1.0-7), sp (>= 1.4-6), | ||
stars (>= 0.5-5), starsExtra (>= 0.2.7), stringr (>= 1.4.0), | ||
terra (>= 1.7-39), tidyr (>= 1.2.0), tidyselect (>= 1.2.0), | ||
viridis (>= 0.6.4) | ||
RoxygenNote: 7.3.1 | ||
Suggests: rmarkdown | ||
VignetteBuilder: knitr | ||
NeedsCompilation: no | ||
Packaged: 2024-03-05 17:31:10 UTC; simon | ||
Author: Simon Dedman [aut, cre] (<https://orcid.org/0000-0002-9108-972X>), | ||
Maurits van Zinnicq Bergmann [aut] | ||
(<https://orcid.org/0000-0002-8414-5025>) | ||
Maintainer: Simon Dedman <simondedman@gmail.com> | ||
Repository: CRAN | ||
Date/Publication: 2024-03-07 10:10:02 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2024 | ||
COPYRIGHT HOLDER: movegroup authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
58536556a1fb30f850babda03d67f3b6 *DESCRIPTION | ||
76b68b4e55c084c0fea9e66c50a1cb0b *LICENSE | ||
73455c1826e0a2e3f810f6e0ec2f2f68 *NAMESPACE | ||
4295b5bee2bed31cf46f573937622504 *NEWS.md | ||
4fddaef28ddec57953dcb7d22fdb9f47 *R/alignraster.R | ||
57d78896bdaaf12719bd30196d52c664 *R/data.R | ||
90fb4e2013a27881b2535b2aa245617c *R/moveLocErrorCalc.R | ||
21d025d45528718e3df50f21c0fc16ec *R/movegroup-package.R | ||
28739d173ac55d5941fd868c93f292bc *R/movegroup.R | ||
1ee51f89755916cd678d4a2d323c82d5 *R/plotRasterIsometric.R | ||
f43ca44f3397f77c30e017e722759472 *R/plotraster.R | ||
8afebd4def29d420a5e604ba69d26c17 *R/scaleraster.R | ||
56e9d1a6abb10288917ca1401019a0dc *R/utils.R | ||
3006aa268d9bfa7c6df48025a2bab7ac *README.md | ||
78d3e5cedcea9f876d7071001d54bc93 *build/vignette.rds | ||
32d74e8c5806498def4a22aab1e7dc68 *data/TracksCleaned.RData | ||
87fe4e6e57ca71e54998b54a7cfc316e *data/argosFiltered.RData | ||
c6fdf1ca23610e8672a65906e142add6 *inst/CITATION | ||
2bbd1c54a7b58ba2f26d6d39453490df *inst/Misc/RunScriptExample.R | ||
31d6ae223cf149aebfc66d2eb927b436 *inst/doc/Using-the-movegroup-package.R | ||
0ffc94f7d6f608e75c7485c7bd7218d8 *inst/doc/Using-the-movegroup-package.Rmd | ||
29c3dec51dfaaa374eac7e4486cd9d1f *inst/doc/Using-the-movegroup-package.html | ||
a9c7027f32ea4789efc3adb6450c0f5c *man/TracksCleaned.Rd | ||
8d9ce83accda1848da3e562517ad75c2 *man/alignraster.Rd | ||
a7d9d06697d2a3f5dd241354775a6d8e *man/argosFiltered.Rd | ||
a1cbaf3f328e8d74e747faacf640c7fc *man/figures/lifecycle-archived.svg | ||
6f521fb1819410630e279d1abf88685a *man/figures/lifecycle-defunct.svg | ||
391f696f961e28914508628a7af31b74 *man/figures/lifecycle-deprecated.svg | ||
691b1eb2aec9e1bec96b79d11ba5e631 *man/figures/lifecycle-experimental.svg | ||
405e252e54a79b33522e9699e4e9051c *man/figures/lifecycle-maturing.svg | ||
f41ed996be135fb35afe00641621da61 *man/figures/lifecycle-questioning.svg | ||
306bef67d1c636f209024cf2403846fd *man/figures/lifecycle-soft-deprecated.svg | ||
ed42e3fbd7cc30bc6ca8fa9b658e24a8 *man/figures/lifecycle-stable.svg | ||
bf2f1ad432ecccee3400afe533404113 *man/figures/lifecycle-superseded.svg | ||
a4cf8f6456b0eb071feee24301af1ca2 *man/figures/logo.png | ||
092e4f2209e5820868aa88a0989db74c *man/moveLocErrorCalc.Rd | ||
e9c404fdeb8e6467aa1a01eab59e04d4 *man/movegroup-package.Rd | ||
b11337355f0b87fddb702e5a069143b1 *man/movegroup.Rd | ||
36ea0c526ae32ed313f12bd4cab3bc10 *man/plotraster.Rd | ||
d4f5f6885c7804a3f43aa7633e6cf235 *man/scaleraster.Rd | ||
0ffc94f7d6f608e75c7485c7bd7218d8 *vignettes/Using-the-movegroup-package.Rmd | ||
6a066e0c74cf1a730457128963107ea0 *vignettes/figures/BBtrajectoryvignette.png | ||
ddb3bdc1f92e71a36b0f71f2f8ebde1d *vignettes/figures/BBvariancesvignette.png | ||
0ff9d396a91a90a8c0713289bc8a4e14 *vignettes/figures/plotrasterVignette.png | ||
0a2f6bf5428c63c6eea7fc131bd421c4 *vignettes/figures/relocationsUDvignette.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(alignraster) | ||
export(moveLocErrorCalc) | ||
export(movegroup) | ||
export(plotraster) | ||
export(scaleraster) | ||
import(ggmap) | ||
import(ggplot2) | ||
import(utils) | ||
importFrom(beepr,beep) | ||
importFrom(dplyr,across) | ||
importFrom(dplyr,arrange) | ||
importFrom(dplyr,bind_cols) | ||
importFrom(dplyr,distinct) | ||
importFrom(dplyr,filter) | ||
importFrom(dplyr,group_by) | ||
importFrom(dplyr,mutate) | ||
importFrom(dplyr,pull) | ||
importFrom(dplyr,rename) | ||
importFrom(dplyr,select) | ||
importFrom(dplyr,semi_join) | ||
importFrom(dplyr,summarise) | ||
importFrom(dplyr,ungroup) | ||
importFrom(grDevices,graphics.off) | ||
importFrom(graphics,par) | ||
importFrom(knitr,plot_crop) | ||
importFrom(lubridate,is.POSIXt) | ||
importFrom(lubridate,today) | ||
importFrom(magick,image_trim) | ||
importFrom(methods,as) | ||
importFrom(methods,new) | ||
importFrom(move,brownian.bridge.dyn) | ||
importFrom(move,brownian.motion.variance.dyn) | ||
importFrom(move,burst) | ||
importFrom(move,getVolumeUD) | ||
importFrom(move,move) | ||
importFrom(move,timeLag) | ||
importFrom(purrr,map2) | ||
importFrom(purrr,map_df) | ||
importFrom(raster,calc) | ||
importFrom(raster,crs) | ||
importFrom(raster,extend) | ||
importFrom(raster,maxValue) | ||
importFrom(raster,ncell) | ||
importFrom(raster,nlayers) | ||
importFrom(raster,projectExtent) | ||
importFrom(raster,projectRaster) | ||
importFrom(raster,raster) | ||
importFrom(raster,res) | ||
importFrom(raster,setMinMax) | ||
importFrom(raster,setValues) | ||
importFrom(raster,stack) | ||
importFrom(raster,stackApply) | ||
importFrom(raster,values) | ||
importFrom(raster,writeRaster) | ||
importFrom(rlang,.data) | ||
importFrom(rlang,set_names) | ||
importFrom(sf,st_as_sf) | ||
importFrom(sf,st_as_sfc) | ||
importFrom(sf,st_bbox) | ||
importFrom(sf,st_distance) | ||
importFrom(sf,st_set_crs) | ||
importFrom(sf,st_transform) | ||
importFrom(sp,CRS) | ||
importFrom(sp,SpatialPoints) | ||
importFrom(sp,bbox) | ||
importFrom(sp,proj4string) | ||
importFrom(sp,spTransform) | ||
importFrom(stars,read_stars) | ||
importFrom(stars,st_contour) | ||
importFrom(stars,st_raster_type) | ||
importFrom(starsExtra,trim2) | ||
importFrom(stats,sd) | ||
importFrom(stats,setNames) | ||
importFrom(stringr,str_remove) | ||
importFrom(terra,project) | ||
importFrom(tidyr,drop_na) | ||
importFrom(tidyselect,everything) | ||
importFrom(viridis,scale_fill_viridis) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: "NEWS.md" | ||
author: "Simon Dedman" | ||
date: "2024-03-05" | ||
output: html_document | ||
--- | ||
# v2024.03.05 | ||
* first CRAN release | ||
|
||
|
||
<!-- If an item is related to an issue in GitHub, include the issue number in parentheses, e.g. (#10). | ||
If an item is related to a pull request, include the pull request number and the author, e.g. (#101, @hadley). | ||
Doing this makes it easy to navigate to the relevant issues on GitHub.--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#' Combines region-specific group-level UD rasters into a single raster. | ||
#' | ||
#' Extends the spatial extent of each area-specific group-level raster to the spatial extent shared by all rasters. | ||
#' This will only be required if you have multiple individuals (e.g. different sharks) divided amongst a few discrete areas | ||
#' (e.g. around different islands) and the effort (e.g. receiver coverage) is different among islands. | ||
#' Not required for multiple individuals all within the same region or sampling regime. | ||
#' | ||
#' @param folderroots Character vector of locations of folder roots output by movegroup. Function | ||
#' expects CRS.Rds file and a subfolder with the scaled raster. | ||
#' @param foldernames Character vector names of folders corresponding to files in folderroots, i.e. | ||
#' the names of the objects, arrays, regions, etc. | ||
#' @param pattern For input rasters from scaleraster. Default ".asc". | ||
#' @param scalefolder For input rasters from scaleraster. Default "Scaled". | ||
#' @param scaledweightedname For input rasters from scaleraster. Default "All_Rasters_Scaled". | ||
#' @param savefolder E.g. "/myfolder/Aligned". Single character entry of folder to save outputs, no trailing slash. | ||
#' @param format Character. Output file type for raster::writeRaster param format. Default ascii, | ||
#' other options have generally not worked well in SD's experience. | ||
#' @param datatype Character. Data type for writing values to disk for raster::writeRaster param | ||
#' datatype. Default FLT4S. | ||
#' @param bylayer For raster::writeRaster param bylayer. Default TRUE. | ||
#' @param overwrite For raster::writeRaster param overwrite. Default TRUE. | ||
#' @param returnObj Logical. Return the scaled object to the parent environment to be assigned as an | ||
#' object? Default FALSE. | ||
#' | ||
#' @return Region-specific group-level UD rasters that share the same spatial extent. | ||
#' | ||
#' @details When used in a movegroup pipeline, the order would be: movegroup.R, scaleraster.R, | ||
#' alignraster.R if required, plotraster.R. | ||
#' | ||
#' @examples | ||
#' \donttest{ | ||
#' # load data | ||
#' data("TracksCleaned") | ||
#' # loop movegroup and scaleraster through tide subsets | ||
#' tide <- c("H", "M", "L") | ||
#' for (i in tide) { | ||
#' dir.create(file.path(tempdir(), i)) | ||
#' movegroup( | ||
#' data = TracksCleaned[TracksCleaned$T.Ph == i, ], | ||
#' ID = "Shark", | ||
#' Datetime = "Datetime", | ||
#' Lat = "Lat", | ||
#' Lon = "Lon", | ||
#' savedir = file.path(tempdir(), i, "/")) | ||
#' | ||
#' scaleraster(path = file.path(tempdir(), i), | ||
#' crsloc = file.path(tempdir(), i)) | ||
#' } | ||
#' | ||
#' alignraster(folderroots = file.path(tempdir(), tide), | ||
#' foldernames = tide, | ||
#' savefolder = file.path(tempdir(), "Aligned")) | ||
#' } | ||
#' | ||
#' @author Simon Dedman, \email{simondedman@@gmail.com} | ||
#' @author Maurits van Zinnicq Bergmann, \email{mauritsvzb@@gmail.com} | ||
|
||
#' @export alignraster | ||
|
||
#' @importFrom methods as | ||
#' @importFrom purrr map2 | ||
#' @importFrom raster crs setMinMax raster extend writeRaster | ||
#' @importFrom sp bbox | ||
#' @importFrom terra project | ||
|
||
|
||
|
||
# read in rasters & add to list#### | ||
alignraster <- function(folderroots = c("/myfolder/H", # character vector of locations of folder roots output by movegroup. Function expects CRS.Rds file and a subfolder with the scaled raster. | ||
"/myfolder/L", # these were /home/simon/Dropbox/PostDoc Work/Rob Bullock accelerometer Lemons 2020.09/dBBMM ASCII/H L M | ||
"/myfolder/M"), | ||
foldernames = c("H", "L", "M"), # character vector names of folders corresponding to files in folderroots, i.e. the names of the objects, arrays, regions, etc. | ||
pattern = ".asc", # for input rasters from scaleraster | ||
scalefolder = "Scaled", # for input rasters from scaleraster | ||
scaledweightedname = "All_Rasters_Scaled_Weighted", # for input rasters from scaleraster. | ||
savefolder = tempdir(), # e.g. "/myfolder/Aligned". Single character entry, no trailing slash. | ||
format = "ascii", # save format | ||
datatype = "FLT4S", # save format | ||
bylayer = TRUE, # save format | ||
overwrite = TRUE, # save format | ||
returnObj = FALSE # return rasterlist object? | ||
) { | ||
if (length(folderroots) != length(foldernames)) stop("length of folderroots and foldernames must be equal") | ||
# If folderroots or savefolder have a terminal slash, remove it, it's added later | ||
for (folders in folderroots) { | ||
if (substr(x = folders, start = nchar(folders), stop = nchar(folders)) == "/") folderroots[which(folderroots %in% folders)] = substr(x = folders, start = 1, stop = nchar(folders) - 1) | ||
} | ||
|
||
if (substr(x = savefolder, start = nchar(savefolder), stop = nchar(savefolder)) == "/") savefolder = substr(x = savefolder, start = 1, stop = nchar(savefolder) - 1) | ||
|
||
foldernames <- as.list(foldernames) | ||
|
||
# Read in CRS files as list | ||
crslist <- as.list(file.path(folderroots, "CRS.Rds")) |> | ||
lapply(function(x) readRDS(x)) | ||
names(crslist) <- foldernames # unnecessary? | ||
|
||
rasterlist <- | ||
as.list(file.path(folderroots, scalefolder, paste0(scaledweightedname, pattern))) |> # Pull all raster names from folderroots into a list | ||
lapply(function(x) raster::raster(x)) |> # read in rasters | ||
lapply(function(x) raster::setMinMax(x)) |> # set minmax values | ||
# https://stackoverflow.com/questions/72063819/use-an-arrow-assignment-function-as-r-purrr-map2 | ||
purrr::map2(crslist, ~ {raster::crs(.x) <- .y;.x}) |> | ||
purrr::map2(foldernames, ~ {names(.x) <- .y;.x}) | ||
|
||
# calculate full shared extent | ||
sharedextent <- lapply(rasterlist, function(x) as.vector(sp::bbox(x))) # xmin #ymin #xmax #ymax | ||
sharedextent <- data.frame(t(sapply(sharedextent, c))) | ||
sharedextent <- c(min(sharedextent[1]), # xmin | ||
max(sharedextent[3]), # xmax | ||
min(sharedextent[2]), # ymin | ||
max(sharedextent[4])) # ymax | ||
|
||
# align to same spatial extent | ||
rasterlist <- lapply(rasterlist, function(x) raster::extend(x, sharedextent)) | ||
|
||
# Convert to SpatRaster format to be used by {terra} | ||
rasterlist <- lapply(rasterlist, function(x) as(x, "SpatRaster")) # methods::as | ||
|
||
# Reproject all rasters simultaneously | ||
rasterlist <- lapply(rasterlist, function(x) project(x, y = rasterlist[[length(rasterlist)]])) | ||
|
||
# Convert back to RasterLayer to save CRS | ||
rasterlist <- lapply(rasterlist, function(x) raster::raster(x)) | ||
|
||
# Save CRS | ||
rasterlistCRS <- sp::CRS(sp::proj4string(rasterlist[[1]])) | ||
class(rasterlistCRS) # CRS | ||
|
||
# if savefolder doesn't exist, create it | ||
if (!file.exists(savefolder)) dir.create(savefolder) | ||
write.csv(sp::proj4string(rasterlistCRS), file.path(savefolder, "CRS.csv"), row.names = FALSE) | ||
saveRDS(rasterlistCRS, file = file.path(savefolder, "CRS.Rds")) | ||
|
||
rasterlist <- lapply(rasterlist, function(x) raster::writeRaster(x = x, # resave individual rasters | ||
filename = file.path(savefolder, names(x)), # , pattern: removed ability to resave as different format | ||
# error: adds X to start of numerical named objects#### | ||
format = format, | ||
datatype = datatype, | ||
if (format != "CDF") bylayer = bylayer, | ||
overwrite = overwrite)) | ||
|
||
if (returnObj) return(rasterlist) | ||
} # close function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#' Data: Tracks of lemon sharks off Bimini, Bahamas | ||
#' | ||
#' Tracks of 17 lemon sharks (Negaprion brevirostris) tagged off Bimini, Bahamas, 2012:2014, by | ||
#' Bimini Biological Field Station employees and volunteers, with accompanying tidal phase. | ||
#' | ||
#' @format A data frame with 1308 rows and 5 variables: | ||
#' \describe{ | ||
#' \item{Datetime}{POSIXct datetime, format YYYY-MM-DD HH:MM:SS.} | ||
#' \item{Shark}{Individual shark ID code.} | ||
#' \item{T.Ph}{Tidal phase, H M L High Medium Low.} | ||
#' \item{Lat}{Decimal latitudes.} | ||
#' \item{Lon}{Decimal longitudes.} | ||
#' } | ||
#' | ||
#' @docType data | ||
#' @keywords datasets | ||
#' @name TracksCleaned | ||
#' @usage data(TracksCleaned) | ||
#' @author Simon Dedman, \email{simondedman@@gmail.com} | ||
#' @author Maurits van Zinnicq Bergmann, \email{mauritsvzb@@gmail.com} | ||
#' @source \url{https://www.biminisharklab.com} | ||
"TracksCleaned" | ||
|
||
#' Data: Tracks of two great hammerhead sharks with position confidence intervals | ||
#' | ||
#' Tracks of 2 great hammerhead sharks tagged in Jupiter, and The Keys, Florida, USA, in 2022 and | ||
#' 2023 respectively, by Saving The Blue (savingtheblue.org), filtered by argosfilter::sdafilter and | ||
#' with state space model applied using aniMotum package, using scripts by Vital Heim, see | ||
#' https://github.com/SimonDedman/SavingTheBlue/blob/main/R/06A_Filter_SPOT_data.R and | ||
#' https://github.com/SimonDedman/SavingTheBlue/blob/main/R/06B_CTCRW_SPOT_data_usin_animotum.R . | ||
#' | ||
#' @format A data frame with 1492 rows and 8 variables: | ||
#' \describe{ | ||
#' \item{id}{Character, shark ID.} | ||
#' \item{date}{POSIXct datetime, format YYYY-MM-DD HH:MM:SS.} | ||
#' \item{lon}{Decimal longitudes.} | ||
#' \item{lon025}{Decimal longitudes, lower 95% confidence interval bound.} | ||
#' \item{lon975}{Decimal longitudes, upper 95% confidence interval bound.} | ||
#' \item{lat}{Decimal latitudes.} | ||
#' \item{lat025}{Decimal latitudes, lower 95% confidence interval bound.} | ||
#' \item{lat975}{Decimal latitudes, upper 95% confidence interval bound.} | ||
#' } | ||
#' | ||
#' @docType data | ||
#' @keywords datasets | ||
#' @name argosFiltered | ||
#' @usage data(argosFiltered) | ||
#' @author Simon Dedman, \email{simondedman@@gmail.com} | ||
#' @author Vital Heim, \email{vital.heim@@gmail.com} | ||
#' @source \url{https://www.savingtheblue.org} | ||
"argosFiltered" |
Oops, something went wrong.