jmsigner / amt

37 stars 13 forks source link

`steps_by_burst()` leads to `Error in diff_rcpp(x$x_) : negative length vectors are not allowed` #6

Closed bniebuhr closed 4 years ago

bniebuhr commented 5 years ago

Hello!

I am rarefying some GPS movement data to 3h fix rate, removing bursts with small numbers of locations, and calculating steps and angles, just following the same code from the vignettes and the paper. Here is is the code.

# resample with 3-hours, get only trajectories with more that 7 days of monitoring
# (7 * 24/3 = 56 locations)
mov.track2 <- mov.track %>% 
  tidyr::nest(-CollarID) %>% 
  dplyr::mutate(resampled.data = purrr::map(data, function(d) {
    d %>% 
      amt::track_resample(rate = lubridate::hours(3), tolerance = lubridate::minutes(30)) %>% 
      amt::filter_min_n_burst(min_n = 7 * 24/3) %>% 
      amt::steps_by_burst()
    })) %>% 
  dplyr::select(-data) %>% 
  tidyr::unnest(cols = c(CollarID, resampled.data))

If I remove the steps_by_burst calculation, it runs just fine. However, when I include I got the error Error in diff_rcpp(x$x_) : negative length vectors are not allowed. Does anyone know what might be happening?

Here is the Traceback of the command, but I do not know if it helps...

40. | diff_rcpp(x$x_)
39. diff_x.track_xy(x) 
38. diff_x(x) 
37. step_lengths_sq.track_xy(x) 
36. step_lengths_sq(x) 
35. step_lengths.track_xy(x, lonlat = lonlat, append_last = FALSE) 
34. step_lengths(x, lonlat = lonlat, append_last = FALSE) 
33. eval_tidy(xs[[i]], unique_output) 
32. lst_quos(xs, transform = expand_lst) 
31. tibble(x1_ = x$x_[-n], x2_ = x$x_[-1], y1_ = x$y_[-n], y2_ = x$y_[-1], 
       sl_ = step_lengths(x, lonlat = lonlat, append_last = FALSE), 
       ta_ = direction_rel(x, lonlat = lonlat, ero_dir = "E", append_last = FALSE)) 
30. steps_base(x, n, lonlat, keep_cols = keep_cols) 
29. steps.track_xyt(x, lonlat = lonlat, keep_cols = keep_cols, ...) 
28. steps(x, lonlat = lonlat, keep_cols = keep_cols, ...) 
27. withCallingHandlers(expr, warning = function(w) invokeRestart("muffleWarning")) 
26. suppressWarnings(steps(x, lonlat = lonlat, keep_cols = keep_cols, 
                       ...)) 
25. steps_by_burst.track_xyt(.) 
24. amt::steps_by_burst(.) 
23. function_list[[k]](value) 
22. withVisible(function_list[[k]](value)) 
21. freduce(value, `_function_list`) 
20. `_fseq`(`_lhs`) 
19. eval(quote(`_fseq`(`_lhs`)), env, env) 
18. eval(quote(`_fseq`(`_lhs`)), env, env) 
17. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env)) 
16. d %>% amt::track_resample(rate = lubridate::hours(3), tolerance = lubridate::minutes(30)) %>% 
  amt::filter_min_n_burst(min_n = 7 * 24/3) %>% amt::steps_by_burst() 
15. .f(.x[[i]], ...) 
14. purrr::map(data, function(d) {
  d %>% amt::track_resample(rate = lubridate::hours(3), tolerance = lubridate::minutes(30)) %>% 
    amt::filter_min_n_burst(min_n = 7 * 24/3) %>% amt::steps_by_burst()
}) 
13. mutate_impl(.data, dots, caller_env()) 
12. mutate.tbl_df(tbl_df(.data), ...) 
11. mutate(tbl_df(.data), ...) 
10. as.data.frame(mutate(tbl_df(.data), ...)) 
9. mutate.data.frame(., resampled.data = purrr::map(data, function(d) {
  d %>% amt::track_resample(rate = lubridate::hours(3), tolerance = lubridate::minutes(30)) %>% 
    amt::filter_min_n_burst(min_n = 7 * 24/3) %>% amt::steps_by_burst()
})) 
8. dplyr::mutate(., resampled.data = purrr::map(data, function(d) {
  d %>% amt::track_resample(rate = lubridate::hours(3), tolerance = lubridate::minutes(30)) %>% 
    amt::filter_min_n_burst(min_n = 7 * 24/3) %>% amt::steps_by_burst()
})) 
7. function_list[[i]](value) 
6. freduce(value, `_function_list`) 
5. `_fseq`(`_lhs`) 
4. eval(quote(`_fseq`(`_lhs`)), env, env) 
3. eval(quote(`_fseq`(`_lhs`)), env, env) 
2. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env)) 
1. mov.track %>% tidyr::nest(-CollarID) %>% dplyr::mutate(resampled.data = purrr::map(data, 
                                                                                   function(d) {
                                                                                     d %>% amt::track_resample(rate = lubridate::hours(3), 
                                                                                                               tolerance = lubridate::minutes(30)) %>% amt::filter_min_n_burst(min_n = 7 *  ...

Thanks in advance!

jmsigner commented 5 years ago

Hi, its a bit hard to diagnose without a small reproducible example. Could it be, that the timestamps are not ordered? If possible, could you make a small subset of the data set available (e.g., by email), that reproduces the error?

tararodkey commented 2 years ago

Hi, were you able to resolve this issue with your code? I am currently running into the same problem, as I rarify my data to every 24 hours and use code quite similar to yours. Any advice that you may have learned from this would be much appreciated! Thank you.

bniebuhr commented 2 years ago

Hi @tararodkey I guess the problem was solved when I reinstalled the amt package. Maybe you can also try it?

If it does not work as @jmsigner wrote me a while back, maybe if you can provide a reproducible example we an test it to check the issue.

jmsigner commented 2 years ago

Hi @tararodkey,

one source of the problem I can think of is that after track_resample() some tracks are left with no observations. As @bniebuhr already said, a small reproducible example of the error gives us the change to help much more efficiently.

tararodkey commented 2 years ago

Hello,

Thank you both for getting back to me so quickly! Unfortunately this was my first time using github to ask a question and these ended up in my spam folder. Since, I've managed to get the code to work, as Johannes suspected, one of my tracks had no observations, and was returning that error.

I will make sure in the future to give a reproducible example, and to check my spam!

Thank you so much, Tara

On Wed, Feb 23, 2022 at 1:45 AM Bernardo Brandão Niebuhr < @.***> wrote:

Hi @tararodkey https://github.com/tararodkey I guess the problem was solved when I reinstalled the amt package. Maybe you can also try it?

If it does not work as @jmsigner https://github.com/jmsigner wrote me a while back, maybe if you can provide a reproducible example we an test it to check the issue.

— Reply to this email directly, view it on GitHub https://github.com/jmsigner/amt/issues/6#issuecomment-1048517959, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASSTFT23DXSZXYX2Z4XS3H3U4SGARANCNFSM4JGBYDTQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

DesiJJ commented 1 year ago

Hi!, May I ask how you solved the problem? I encountered the same issue and the data looks similar to what you described.

Cheers

jmsigner commented 1 year ago

Hi @DesiJJ ,

there are two potential sources of this error: 1) a track with no observations, or 2) a track with timestamps that are not in order. Feel free to send me a small data set that reproduces the error and I am happy to have a look at it.