ConsBiol-unibern / SDMtune

Performs Variables selection and model tuning for Species Distribution Models (SDMs). It provides also several utilities to display results.
https://consbiol-unibern.github.io/SDMtune/
Other
23 stars 8 forks source link

[Bug]: predict, maxent method - find_dims error #34

Open ameliabridges opened 9 months ago

ameliabridges commented 9 months ago

Describe the bug

When trying to use SDMtune::predict() to extract predictors over the entire extent of the environmental rasters, the following error is produced: Error in find_dims(object, model, nc, fun, const, na.rm, index, ...) : could not find function "find_dims"

Calculating predictions for the pres/abs locations using the swd object as opposed to the predictors object works fine.

Steps to reproduce the bug

library(SDMtune)

map <- SDMtune::predict(model5,
               data = predictors,
               type = "cloglog")

Session information

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=English_United Kingdom.utf8  LC_CTYPE=English_United Kingdom.utf8    LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.utf8    

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

other attached packages:
 [1] gridExtra_2.3        rJava_1.0-6          GGally_2.1.2         SDMtune_1.3.1        robis_2.11.3         MultiscaleDTM_0.5.3 
 [7] terra_1.7-3          raster_3.6-14        sp_1.6-0             lubridate_1.9.2      forcats_1.0.0        stringr_1.5.0       
[13] dplyr_1.1.2          purrr_1.0.1          readr_2.1.4          tidyr_1.3.0          tibble_3.2.1         ggplot2_3.4.2       
[19] tidyverse_2.0.0      sdmpredictors_0.2.15

loaded via a namespace (and not attached):
 [1] httr_1.4.7         maps_3.4.1         jsonlite_1.8.7     shiny_1.7.4        progress_1.2.2     pillar_1.9.0      
 [7] lattice_0.20-45    glue_1.6.2         digest_0.6.31      RColorBrewer_1.1-3 promises_1.2.0.1   colorspace_2.1-0  
[13] plyr_1.8.8         htmltools_0.5.4    httpuv_1.6.8       pkgconfig_2.0.3    xtable_1.8-4       scales_1.2.1      
[19] later_1.3.0        mapedit_0.6.0      tzdb_0.3.0         timechange_0.2.0   proxy_0.4-27       farver_2.1.1      
[25] generics_0.1.3     ellipsis_0.3.2     withr_2.5.1        cli_3.6.0          crayon_1.5.2       magrittr_2.0.3    
[31] mime_0.12          fansi_1.0.4        xml2_1.3.5         class_7.3-20       prettyunits_1.1.1  tools_4.2.2       
[37] dismo_1.3-9        data.table_1.14.6  hms_1.1.2          lifecycle_1.0.3    munsell_0.5.0      compiler_4.2.2    
[43] e1071_1.7-13       rlang_1.1.1        classInt_0.4-10    units_0.8-4        grid_4.2.2         rstudioapi_0.14   
[49] htmlwidgets_1.6.1  crosstalk_1.2.0    labeling_0.4.2     base64enc_0.1-3    gtable_0.3.3       codetools_0.2-18  
[55] reshape_0.8.9      DBI_1.1.3          curl_5.0.0         R6_2.5.1           rgdal_1.6-4        knitr_1.42        
[61] fastmap_1.1.0      utf8_1.2.2         KernSmooth_2.23-20 stringi_1.7.12     parallel_4.2.2     Rcpp_1.0.10       
[67] vctrs_0.6.2        sf_1.0-14          rgl_1.0.1          leaflet_2.1.1      tidyselect_1.2.0   xfun_0.36

Additional information

No response

Reproducible example

Daviser95 commented 7 months ago

Hi @sgvignali, I also had the same error, simply following the code shown in the vignettes, but with my own data, both using ANN and RF as methods. This is the code which produces the error, I tryed using ext(the extent of my predictors) to solve it but nothing change:

map_rf <- predict(final_model_rf, 
                   data = EnvVars,
                   ext = extvars)

All other analysis performed well, only when producing the prediction map it comes this problem. This is my sessionInfo:

R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22631)

Matrix products: default

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

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

other attached packages:
[1] plotROC_2.3.1 ggplot2_3.4.4 terra_1.7-29  zeallot_0.1.0 SDMtune_1.3.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10          pillar_1.9.0         compiler_4.2.3       plyr_1.8.8           tools_4.2.3         
 [6] jsonlite_1.8.8       lifecycle_1.0.3      tibble_3.2.1         gtable_0.3.1         lattice_0.20-45     
[11] pkgconfig_2.0.3      rlang_1.1.2          cli_3.6.2            rstudioapi_0.14      dismo_1.3-14        
[16] withr_2.5.0          dplyr_1.1.4          raster_3.6-3         generics_0.1.3       vctrs_0.6.5         
[21] grid_4.2.3           nnet_7.3-18          tidyselect_1.2.0     glue_1.6.2           R6_2.5.1            
[26] fansi_1.0.3          sp_1.5-1             farver_2.1.1         magrittr_2.0.3       whisker_0.4         
[31] scales_1.2.1         codetools_0.2-19     randomForest_4.7-1.1 colorspace_2.0-3     labeling_0.4.2      
[36] utf8_1.2.2           munsell_0.5.0