jmsigner / amt

37 stars 13 forks source link

mixup of terra and raster pckg in function redistribution_kernel() #90

Open eva-szas opened 1 year ago

eva-szas commented 1 year ago

Input class object for the "map" argument must be "SpatRaster", but extract_covariates() still uses "raster" pckg, and following error occurs: ' _Error in extract_covariates.stepsxy(xy, map, where = "both") : no raster '

Error in line 272 of file "R/simulate.R" .

eva-szas commented 1 year ago

Here is the work-around:

redistribution_kernel <- function( x = make_issf_model(), start = make_start(), map = terra::rast(env), # Input must be SpatRaster (here from raster stack (raster pckg) )

fun = function(xy, map) {
  extract_covariates(xy, raster::stack(map), where = "both")  # make terra object into rasterStack
},

. . . .

If you call the function redistribution_kernel(), the input object in map must be a "stack" of class SpatRaster from {terra} package (but the function inside extract_covariates() needs an input raster layer from {raster}.

For drawing N steps call:

redistribution_kernel(model, map = rast(raster::stack(map)), start = start_location, stochastic = TRUE, tolerance.outside = 0.2,

as.raster = FALSE, (needs to be removed)

                              n.control = 1e5, n.sample = 1000)
jmsigner commented 1 year ago

Thanks @eva-szas for reporting. Could you please post the output of SessionInfo()?

eva-szas commented 1 year ago

Here it is:

R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale: [1] LC_COLLATE=German_Germany.utf8 [2] LC_CTYPE=German_Germany.utf8
[3] LC_MONETARY=German_Germany.utf8 [4] LC_NUMERIC=C
[5] LC_TIME=German_Germany.utf8

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

other attached packages: [1] wildlifeDI_0.5.0 tmap_3.3-3 sf_1.0-9
[4] here_1.0.1 vroom_1.6.0 terra_1.6-17
[7] raster_3.6-3 sp_1.5-1 writexl_1.4.1
[10] lubridate_1.9.0 timechange_0.1.1 forcats_1.0.0
[13] stringr_1.5.0 dplyr_1.0.10 purrr_0.3.5
[16] readr_2.1.3 tidyr_1.2.1 tibble_3.1.8
[19] ggplot2_3.4.1 tidyverse_2.0.0

loaded via a namespace (and not attached): [1] CircStats_0.2-6 bit64_4.0.5 RColorBrewer_1.1-3 [4] rprojroot_2.0.3 tools_4.2.2 utf8_1.2.2
[7] R6_2.5.1 KernSmooth_2.23-20 DBI_1.1.3
[10] colorspace_2.0-3 ade4_1.7-22 withr_2.5.0
[13] tidyselect_1.2.0 gridExtra_2.3 leaflet_2.1.2
[16] bit_4.0.4 compiler_4.2.2 leafem_0.2.0
[19] amt_0.1.7 cli_3.4.1 scales_1.2.1
[22] classInt_0.4-8 proxy_0.4-27 digest_0.6.31
[25] rmarkdown_2.21 base64enc_0.1-3 dichromat_2.0-0.1
[28] pkgconfig_2.0.3 htmltools_0.5.4 fastmap_1.1.0
[31] htmlwidgets_1.6.2 rlang_1.1.0 rstudioapi_0.14
[34] generics_0.1.3 adehabitatMA_0.3.15 crosstalk_1.2.0
[37] adehabitatLT_0.3.26 magrittr_2.0.3 rlist_0.4.6.2
[40] Matrix_1.5-3 Rcpp_1.0.9 munsell_0.5.0
[43] fansi_1.0.3 abind_1.4-5 lifecycle_1.0.3
[46] stringi_1.7.12 leafsync_0.1.0 yaml_2.3.6
[49] MASS_7.3-58.1 tmaptools_3.1-1 plyr_1.8.8
[52] grid_4.2.2 parallel_4.2.2 crayon_1.5.2
[55] lattice_0.20-45 stars_0.6-0 splines_4.2.2
[58] hms_1.1.3 knitr_1.42 pillar_1.9.0
[61] boot_1.3-28 codetools_0.2-18 XML_3.99-0.12
[64] glue_1.6.2 evaluate_0.20 data.table_1.14.8
[67] vctrs_0.5.0 png_0.1-7 tzdb_0.3.0
[70] Rdpack_2.4 gtable_0.3.3 xfun_0.38
[73] rbibutils_2.2.9 lwgeom_0.2-9 e1071_1.7-12
[76] class_7.3-20 survival_3.4-0 viridisLite_0.4.1
[79] lemon_0.4.6 units_0.8-0