Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in frames_spatial() when creating frames for more than 20 tracks #113

Open
makratofil opened this issue Jan 3, 2023 · 5 comments
Open

Comments

@makratofil
Copy link

This is going to sound crazy but I haven't been able to source any solution yet. I'm having issues creating spatial frames for MoveStack objects that contain more than 20 animal tracks: Error in if (row1 == 1 & row2 == nrow(x) & col1 == 1 & col2 == ncol(x)) { : missing value where TRUE/FALSE needed.

My code for this worked successfully not too long ago, and I'm able to create spatial frames via frames_spatial() with subsets that include fewer tracks using the exact same code but for some reason not the sets with 21+. I copied the code and output below, but can connect via email if you need some of the data I'm working with (or could try with large dataset from Movebank?).

frames_hap <- frames_spatial(m, path_colours = col12CBx2,
                             map_service = "esri", map_type = "world_imagery",
                             equidistant = F,
                             path_fade = TRUE, 
                             tail_length = 12,
                             path_legend = F,
                             path_join = "mitre")

Checking temporal alignment...
Processing movement data...
Approximated animation duration: ≈ 16s at 25 fps for 400 frames
Retrieving and compositing basemap imagery...
Loading basemap 'world_imagery' from map service 'esri'...
|===============================================================================================================| 100% elapsed=02s
Assigning raster maps to frames...
Error in if (row1 == 1 & row2 == nrow(x) & col1 == 1 & col2 == ncol(x)) { :
missing value where TRUE/FALSE needed

The m object is a MoveStack object of 21 tracks and the col12CBx2 vector is just a vector of 21 colors, one for each track. Again, this exact script works just fine for subsets of the original data that include 20 or fewer tracks (with the corresponding number of path colors).

Session info:

R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.9.0  timechange_0.1.1 move_4.1.10      rgdal_1.5-32     raster_3.6-3     sp_1.4-7         geosphere_1.5-14 ggplot2_3.3.6   
 [9] dplyr_1.0.9      moveVis_0.10.6  

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0   terra_1.6-17       purrr_0.3.4        pbapply_1.5-0      sf_1.0-7           lattice_0.20-45    colorspace_2.0-3  
 [8] vctrs_0.5.0        generics_0.1.2     utf8_1.2.2         rlang_1.0.6        e1071_1.7-9        pillar_1.7.0       withr_2.5.0       
[15] glue_1.6.2         DBI_1.1.2          slippymath_0.3.1   av_0.8.2           lifecycle_1.0.3    munsell_0.5.0      gtable_0.3.0      
[22] basemaps_0.0.5     codetools_0.2-18   memoise_2.0.1      fastmap_1.1.0      parallel_4.2.0     curl_4.3.2         class_7.3-20      
[29] fansi_1.0.3        gifski_1.6.6-1     Rcpp_1.0.8.3       KernSmooth_2.23-20 scales_1.2.0       classInt_0.4-3     lwgeom_0.2-8      
[36] cachem_1.0.6       magick_2.7.3       grid_4.2.0         cowplot_1.1.1      cli_3.3.0          tools_4.2.0        magrittr_2.0.3    
[43] proxy_0.4-26       tibble_3.1.7       crayon_1.5.1       pkgconfig_2.0.3    ellipsis_0.3.2     xml2_1.3.3         assertthat_0.2.1  
[50] httr_1.4.3         rstudioapi_0.13    R6_2.5.1           units_0.8-0        compiler_4.2.0    
@Qianru-liao
Copy link

I just met the same problem. And I fixed it after I set a coarser resolution (from 180 to 240) in the previous step:
m <- moveVis::align_move(data, res = 240, unit = "mins")

It seems like the error is caused by the NA value in temporal interpolation.

@smerker
Copy link

smerker commented Dec 7, 2023

Sometimes I get this error and sometimes I do not. It is unclear when it happens and when the NA appears or doesn't. More often I get a fatal R crash.

@dmkaplan2000
Copy link

I am getting this error and I am wondering if there has been any progress on fixing it since the last comments?

@NinoPierantonio
Copy link

NinoPierantonio commented Jan 29, 2025

Is there any update on this issue? I have tried to allign the data to a coarser timestep but the error persists. Sometimes the whole process works, sometimes it doesn't. It definitely seems that the error is related to the opresence of NAs but i think it is in relation to the IDs of the tracks(?). I have also noted that the creation date is always the same, date created: 2025-01-11 03:39:41, and definitely wrong given that I have created the MoveStack objects today.

Any feedback is welcome, thanks.

For this MoveStack I can produce an animation:

> m
class       : MoveStack 
features    : 174520 
extent      : 0.7561053, 8.401739, 40.1614, 43.0054  (xmin, xmax, ymin, ymax)
crs         : +proj=longlat +datum=WGS84 +no_defs 
variables   : 3
names       :                 x,                y,       time 
min values  : 0.756105258704161, 40.1614015828972, 1620262800 
max values  :   8.4017388017539, 43.0054015391913, 1623020400 
timestamps  : 2021-05-06 01:00:00 ... 2021-06-06 23:00:00 Time difference of 32 days  (start ... end, duration) 
sensors     : interpolateTime, unknown 
indiv. data :  
individuals : X636092040, X266457000, X226269000, X672747000, X228358800, X271040948, X636018322, X226308000, X211307550, X247371500, X566042000, X215588000, X304535000, X374050000, X227182000 
date created: 2025-01-11 03:39:41

but for this one I can't:

> m
class       : MoveStack 
features    : 161758 
extent      : 1.086963, 6.932974, 40.34493, 43.14665  (xmin, xmax, ymin, ymax)
crs         : +proj=longlat +datum=WGS84 +no_defs 
variables   : 3
names       :                x,                y,       time 
min values  : 1.08696298036393, 40.3449334068324, 1652317200 
max values  : 6.93297373036251, 43.1466542841553, 1654729200 
timestamps  : 2022-05-12 01:00:00 ... 2022-06-08 23:00:00 Time difference of 28 days  (start ... end, duration) 
sensors     : interpolateTime 
indiv. data : x 
min ID Data : NA 
max ID Data : NA 
individuals : X277551000, X355795000, X372050000, X605116230, X255806148, X311000585, X228081000, X304302000, X538005064, X309979000, X247178700, X215086000, X256084000, X271002572, X538007990 
date created: 2025-01-11 03:39:41

In this one I cannot see any NAs but i stil get the error message:

>m
class       : MoveStack 
features    : 191580 
extent      : 1.086915, 6.932969, 40.34498, 43.14762  (xmin, xmax, ymin, ymax)
crs         : +proj=longlat +datum=WGS84 +no_defs 
variables   : 3
names       :                x,                y,       time 
min values  :  1.0869148094978, 40.3449795794822, 1652315400 
max values  : 6.93296861524917, 43.1476201376123, 1654731000 
timestamps  : 2022-05-12 00:30:00 ... 2022-06-08 23:30:00 Time difference of 28 days  (start ... end, duration) 
sensors     : interpolateTime, unknown 
indiv. data :  
individuals : X277551000, X355795000, X538009740, X372050000, X304302000, X228081000, X244297000, X309979000, X215086000, X256084000, X271002572, X538007990, X219191000, X352001239, X250005981 
date created: 2025-01-11 03:39:41

@NinoPierantonio
Copy link

As a comment to my previous post, I have managed to produce the animation for those MoveStaks that didn't work earlier. Although I did not have any specific warning messages regarding the fact that some trackIDs had less than 2 points, I have filtered out from my dataframe all the IDs with less than 10 datapoints and re-run the code. This in some way solved the issue. I am not sure that having too few points for some tracks was actually causing the problems because normally moveVis gives a warning or error when some tracks are too rarefied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants