ABbiodiversity / wildRtrax

wildrtrax is an R package for environmental sensor data management and analytics
https://abbiodiversity.github.io/wildRtrax/
Other
8 stars 9 forks source link

wt_ind_det() incorrect grouping causes doubling of animals detected #60

Open ctlamb opened 1 month ago

ctlamb commented 1 month ago

Here is a repo of a bug I've discovered. I use ABMI data to show that the wt_ind_det() fn creates an incorrect max_animals estimate.

I struggled to decompose the following section in wt_ind_det(): mutate(ungroup(mutate(mutate(group_by(arrange(ungroup(distinct(mutate(group_by(mutate( but I think somewhere in the group_by() image_id needs to be added.

library(wildrtrax)
library(tidyverse)

wt_auth() 
##download some ABMI data
test_raw <- wt_download_report(
  project_id = 2073, 
  sensor_id = "CAM",
  report = "main", 
  weather_cols = FALSE
)

##isolate an example where there are duplicated date/times
##all are unique images, just rapidfire sometimes has 2 images in same date/time down to the second
## here a bull moose is detected over a period of about 8 minutes, individual count==1 across all tags
isolate_detection <- test_raw%>%
  filter(location=="ST-430-3-SW" &
         species_common_name=="Moose")%>%
  filter(date(image_date_time)==ymd("2023-03-01"))

##create individual detections
test_detections <- wildrtrax::wt_ind_detect(
  x = isolate_detection, 
  threshold = 30,
  units = "minutes",
  remove_human = TRUE, 
  remove_domestic = TRUE 
)

##fails-- it calculates 2, due to wt_ind_detect() grouping over image_date_time and summing instead of over image_id
test_detections$max_animals==1
mabecker89 commented 1 month ago

Thanks Clayton. Let me know if/when you want me to jump in on some fixes you've drafted.