hugomflavio / actel

Standardised analysis of acoustic telemetry data from fish moving through receiver arrays
https://hugomflavio.github.io/actel-website
26 stars 6 forks source link

Bug? jump.error = 1 behaves as jump.error = 2 #71

Closed Flinkkkk closed 2 years ago

Flinkkkk commented 2 years ago

Hi,

I found a possible bug, when specifying jump.error = 1, I only get warnings/errors when a fish has jumped through 2 or more arrays. I can see from the movement table that there are cases of fish jumping 1 array as well. Specifying jump.warning = 1 works, then I get warnings about fish jumping a single array.

Thank you for your work, Henrik

hugomflavio commented 2 years ago

Hi Henrik,

Thank you for trying out actel and for reporting this issue. I will have a look at it over the weekend.

Cheers, Hugo

hugomflavio commented 2 years ago

Hi again Henrik,

I have just run a test and jump.error seems to be working fine for me. Can you try running the minimal example below and let me know if the two checkJumpDistance() calls trigger user interaction?

setwd(tempdir())
actel::exampleWorkspace("exampleWorkspace")
setwd("exampleWorkspace")

study.data <- suppressWarnings(actel:::loadStudyData(tz = "Europe/Copenhagen", start.time = NULL,
    stop.time = NULL, section.order = NULL, exclude.tags = NULL))
detections.list <- study.data$detections.list
bio <- study.data$bio
spatial <- study.data$spatial
dist.mat <- study.data$dist.mat
dotmat <- study.data$dotmat
arrays <- study.data$arrays
paths <- study.data$paths

moves <- actel:::groupMovements(detections.list = detections.list[1:2], bio = bio, spatial = spatial,
    speed.method = "last to first", max.interval = 60, tz = "Europe/Copenhagen", dist.mat = dist.mat)

# Test release to first movement
xmoves <- moves[[1]]
xmoves$Array[1] <- "A2"

actel:::checkJumpDistance(movements = xmoves, bio = bio, tag = "R64K-4451", dotmat = dotmat, paths = paths, n = "(1/1)",
                       arrays = arrays, spatial = spatial, jump.warning = 1, jump.error = 1, GUI = "never",
                       detections = detections.list[["R64K-4451"]], save.tables.locally = FALSE)
# n

# seems to be working fine.

# Test between movements
xmoves <- moves[[1]]
xmoves$Array[2] <- "A3"

x <- actel:::checkJumpDistance(movements = xmoves, bio = bio, tag = "R64K-4451", dotmat = dotmat, paths = paths, n = "(1/1)",
                       arrays = arrays, spatial = spatial, jump.warning = 1, jump.error = 1, GUI = "never",
                       detections = detections.list[["R64K-4451"]], save.tables.locally = FALSE)
# n

# seems to work fine too.

In my case they do:

image

Flinkkkk commented 2 years ago

Hi Hugo,

I tested your minimal example and yes, both triggered intervention.

I tried my own data again in a limited time period to compare jump.warning and jump.error and found that jump.error=1 do trigger intervention when fish jump a single array, however it does not report information about the movement that trigger intervention.

Here is the output from the two runs (only 1 fish in the output for convenience):

test1 <- explore(tz = "Europe/Stockholm", start.time = "2021-03-30 18:00:00", stop.time = "2021-04-30 18:00:00", report=FALSE, save.tables.locally = TRUE, discard.orphans = TRUE, max.interval = 60, minimum.detections = 2, jump.warning = 1)

jump warning

test2 <- explore(tz = "Europe/Stockholm", start.time = "2021-03-30 18:00:00", stop.time = "2021-04-30 18:00:00", report=FALSE, save.tables.locally = TRUE, discard.orphans = TRUE, max.interval = 60, minimum.detections = 2, jump.error = 1)

jump error

Here is an example of a fish (7003) that jumped 1 array without any additional jumps

jump.warning = 1

Screenshot 2021-12-13 at 10 57 22

jump.error = 1

Screenshot 2021-12-13 at 10 57 04

Flinkkkk commented 2 years ago

To conclude, I should have specified both jump.warning = 1 and jump.error = 1, if so I get warnings also on single array jumps.

By specifying jump.error = 1 without specifying jump.warning it seems as jump.warning is automatically set to 2.

Thanks for your great work, Henrik

hugomflavio commented 2 years ago

Hi Henrik,

Indeed, you are correct! When jump.warning is higher than jump.error, actel should drop the former automatically, but the updated value was getting lost along the way. I have found it and corrected it (commit 64aa9cbdf37abf01cfb0868239e842560f001868), so whenever I get a new version ready to send to CRAN that bug will go away. Meanwhile, specifying both manually will solve the problem.

Thanks for letting me know!