Skip to content

Commit

Permalink
hotix bug in summarize_detections() where value in 'locations' output…
Browse files Browse the repository at this point in the history
… column was name of input column (e.g. 'glatos_array'), rather than values from that column (e.g., 'AGR', 'BBI'); fixes #182; cherrypicked from commit db9d69a which was merged to dev
  • Loading branch information
chrisholbrook committed Feb 25, 2024
1 parent 7e2b883 commit 3f0a2ee
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 83 deletions.
106 changes: 53 additions & 53 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
Package: glatos
Type: Package
Title: A package for the Great Lakes Acoustic Telemetry Observation System
Description: Functions useful to members of the Great Lakes Acoustic Telemetry Observation System https://glatos.glos.us; many more broadly relevant to simulating, processing, analysing, and visualizing acoustic telemetry data.
Version: 0.7.1
Date: 2024-01-19
Depends: R (>= 3.5.0)
Imports:
av,
data.table,
fasterize,
fasttime,
gdalUtilities,
geodist,
gdistance,
jsonlite,
knitr,
lubridate,
magrittr,
methods,
plotrix,
plyr,
purrr,
raster,
readxl,
rmarkdown,
sf,
tibble,
tidyr
Suggests:
gganimate,
gifsky,
GISTools,
png,
tint
URL: https://github.com/ocean-tracking-network/glatos
BugReports: https://github.com/ocean-tracking-network/glatos/issues
Authors@R: c(
person("Christopher", "Holbrook", email = "cholbrook@usgs.gov",
role = c("cre", "aut")),
person("Todd", "Hayden", role = "aut"),
person("Thomas", "Binder", role = "aut"),
person("Jon", "Pye", role = "aut"),
person("Alex", "Nunes", role = "ctb"),
person("Angela", "Dini", role = "ctb"),
person("Ryan", "Gosse", role = "ctb"))
License: GPL-2
LazyLoad: yes
LazyData: true
RoxygenNote: 7.2.3
VignetteBuilder: knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Package: glatos
Type: Package
Title: A package for the Great Lakes Acoustic Telemetry Observation System
Description: Functions useful to members of the Great Lakes Acoustic Telemetry Observation System https://glatos.glos.us; many more broadly relevant to simulating, processing, analysing, and visualizing acoustic telemetry data.
Version: 0.7.2
Date: 2024-02-25
Depends: R (>= 3.5.0)
Imports:
av,
data.table,
fasterize,
fasttime,
gdalUtilities,
geodist,
gdistance,
jsonlite,
knitr,
lubridate,
magrittr,
methods,
plotrix,
plyr,
purrr,
raster,
readxl,
rmarkdown,
sf,
tibble,
tidyr
Suggests:
gganimate,
gifsky,
GISTools,
png,
tint
URL: https://github.com/ocean-tracking-network/glatos
BugReports: https://github.com/ocean-tracking-network/glatos/issues
Authors@R: c(
person("Christopher", "Holbrook", email = "cholbrook@usgs.gov",
role = c("cre", "aut")),
person("Todd", "Hayden", role = "aut"),
person("Thomas", "Binder", role = "aut"),
person("Jon", "Pye", role = "aut"),
person("Alex", "Nunes", role = "ctb"),
person("Angela", "Dini", role = "ctb"),
person("Ryan", "Gosse", role = "ctb"))
License: GPL-2
LazyLoad: yes
LazyData: true
RoxygenNote: 7.3.1
VignetteBuilder: knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
----

# glatos 0.7.2 (2024-02-25)


### Bug fixes


- Fixed bug in `summarize_detections()` where value in `locations` output
column was name of input column (e.g. "glatos_array"), rather than values
from that column (e.g., "AGR", "BBI").
- fixed [issue #182](https://github.com/ocean-tracking-network/glatos/issues/182)
- cherry-picked from [commit 182]( https://github.com/ocean-tracking-network/glatos/commit/db9d69a3d08a97e7b8f86e0d4977aa0909776ddd)
which was merged with dev but not main.


----

# glatos 0.7.1 (2024-01-19)


Expand Down
62 changes: 32 additions & 30 deletions R/summ-summarize_detections.r
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
#'
#' @export



summarize_detections <- function(det, location_col = "glatos_array",
receiver_locs = NULL, animals = NULL,
summ_type = "animal"){
Expand All @@ -190,8 +192,8 @@ summarize_detections <- function(det, location_col = "glatos_array",
dtc <- data.table::as.data.table(det)

#check 'summ_type'
if(!(summ_type %in% c("animal", "location", "both"))) stop(paste0("invalid ",
"summary type ('summ_type'); must be 'animal', 'location', or 'both'."))
if(!(summ_type %in% c("animal", "location", "both"))) stop(paste0("invalid",
"summary type ('summ_type'); must be 'animal', 'location', or 'both'."))

#check that required columns exist in detections
missing_cols <- setdiff(c("animal_id", "detection_timestamp_utc"), names(dtc))
Expand All @@ -211,26 +213,26 @@ summarize_detections <- function(det, location_col = "glatos_array",
stop("Column 'detection_timestamp_utc' in 'dtc' must be of class POSIXct.")
}

if(!is.null(receiver_locs)){

#check that location_col exists in receiver locations
if(!(location_col %in% names(receiver_locs))){
stop(paste0("Column ", location_col, " is missing in 'receiver_locs'.\n",
"Double check input argument 'location_col'."))
}
rcv <- data.table::as.data.table(receiver_locs)

#get mean receiver locations from receiver_locs
mean_locs <- rcv[ , list(mean_lat = mean(deploy_lat),
mean_lon = mean(deploy_long)),
by = location_col]
} else {
if(!is.null(receiver_locs)){

#check that location_col exists in receiver locations
if(!(location_col %in% names(receiver_locs))){
stop(paste0("Column ", location_col, " is missing in 'receiver_locs'.\n",
"Double check input argument 'location_col'."))
}
rcv <- data.table::as.data.table(receiver_locs)

#get mean receiver locations from receiver_locs
mean_locs <- rcv[ , list(mean_lat = mean(deploy_lat),
mean_lon = mean(deploy_long)),
by = location_col]
} else {
#get mean receiver locations from dtc
mean_locs <- dtc[ , list(mean_lat = mean(deploy_lat),
mean_lon = mean(deploy_long)),
by = location_col]
}

mean_locs <- dtc[ , list(mean_lat = mean(deploy_lat),
mean_lon = mean(deploy_long)),
by = location_col]
}

if(!is.null(animals)){

#read animal_id vector from data frame if passed as data frame
Expand Down Expand Up @@ -263,15 +265,15 @@ summarize_detections <- function(det, location_col = "glatos_array",
det_sum <- loc_summary
}

if(summ_type == "animal"){
#summarize fish detections
anim_summary <- dtc[ , list(num_locs = data.table::uniqueN(location_col),
num_dets = .N,
first_det = min(detection_timestamp_utc),
last_det = max(detection_timestamp_utc),
locations = paste(sort(unique(location_col)), collapse = " ")),
by = animal_id]

if(summ_type == "animal"){
#summarize fish detections
anim_summary <- dtc[ , list(num_locs = data.table::uniqueN(location_col),
num_dets = .N,
first_det = min(detection_timestamp_utc),
last_det = max(detection_timestamp_utc),
locations = paste(sort(unique(dtc[[location_col]])), collapse = " ")),
by = animal_id]

#add animals not detected
anim_summary <- merge(anim_summary,
data.table::data.table(animal_id = animals), by = "animal_id", all.y = TRUE)
Expand Down
1 change: 1 addition & 0 deletions man/glatos.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f0a2ee

Please sign in to comment.