babaknaimi / sdm

sdm is an extensible framework to develop species distributions models using individual and community-based approaches, generate ensembles of models, evaluate the models, and predict species potential distributions in space and time.
21 stars 5 forks source link

Bug in niche function #26

Open Wycology opened 5 months ago

Wycology commented 5 months ago

The niche function does not plot x and y values properly. They appear to overlap near the 0,0 coordinate. Capture

library(sdm)

species <- vect(system.file("external/species.shp", package = "sdm"))

preds <- rast(list.files(path = system.file("external", package = "sdm"), pattern = 'asc$', full.names = TRUE))

names(preds)

d <- sdmData(formula = Occurrence~., train = species, predictors = preds)

m <- sdm(Occurrence~., data = d, methods = c('rf', 'glm', 'brt'))

p1 <- ensemble(m, newdata = preds, setting = list(method = 'weighted', stat = 'AUC'))

niche(x = preds, h = p1, c('precipitation', 'temperature'))

Wycology commented 5 months ago

Seems the implementation of terra functions and objects was the issue. If I wrap the x and h arguments to raster::stack and raster, the niche plot works fine as shown.

niche(x = raster::stack(preds), h = raster(p1), c('precipitation','temperature'))

image