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
25 stars 8 forks source link

[Enhancement] Accepting single raster as well #19

Closed lophital closed 1 year ago

lophital commented 2 years ago

This is not a bug report actually but I couldn't label it so reporting in bug category. I really prefer this package compare to biomod2 or dismo, sdm packages. I've been used it since 2020 and I hope if there is new feature, it would be really much nicer. Since I am trying to modelling with virtual species, most of my research is conducted with single or just few variables. Biomod2 accepting single variable but it seems SDMtune package with prepareSWD function only accepting raster stack variables. Hope it could accept single raster variable as well in near future. Thanks!

sincerely, JEON

sgvignali commented 1 year ago

I don't see any problem when using only one variable:

# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
                    pattern = "grd",
                    full.names = TRUE)

predictors <- terra::rast(files[1])

# Prepare presence and background locations
p_coords <- virtualSp$presence
bg_coords <- virtualSp$background

# Create the SWD object
data <- prepareSWD(species = "Virtual species",
                   p = p_coords,
                   a = bg_coords,
                   env = predictors)
data

# Train model
m <- train("Maxnet",
           data = data)

# Make predictions
pred <- predict(m, data)
pred |> head()

I close this issue, if you face again the problem, please provide a reproducible example.