biodiverse / ubms

Fit models to data from unmarked animals using Stan. Uses a similar interface to the R package 'unmarked', while providing the advantages of Bayesian inference and allowing estimation of random effects.
https://hmecology.github.io/ubms/
GNU General Public License v3.0
35 stars 8 forks source link

Migrate spatial predictions from raster to terra #78

Closed jniedballa closed 2 weeks ago

jniedballa commented 4 months ago

Hi Ken, ubms allows spatial predictions using rasters from the raster package. The raster package is no longer being developed though and has been replaced by terra. While raster still works and is on CRAN, it carries the risk of breaking at some point in the future.

Porting spatial predictions in ubms from raster to terra should be straightforward, replacing raster::as.data.frame() in https://github.com/kenkellner/ubms/blob/8c761fda6d69a1377997b18f65dbcc6ff2493ab5/R/predict.R#L64 with terra::as.data.frame(),

and this line: https://github.com/kenkellner/ubms/blob/8c761fda6d69a1377997b18f65dbcc6ff2493ab5/R/predict.R#L68

with out <- terra::rast(out, crs = terra::crs(inp_rast))

nb, I didn't test the code. Thank you and best regards,

kenkellner commented 4 months ago

Thanks @jniedballa, good idea.