Update tpi calcs in landscape covariates to terra
- Dominant language
- R
- Stars
- 3
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Landscape covar generation is based on spatial::eco rather than terra. Benchmarking tests show approx double the time required and should be updated to terra package. Initial testing indicated some work needs to be done to adjust the normalization factor :
``` library(tictoc)
tic()
tp <- spatialEco::tpi(dtm, scale=scale, win=win, normalize=TRUE)
terra::writeRaster(tp, file.path(outpath, "tpi_se.tif"), overwrite = TRUE)
toc()
tic()
sd <- focal(dtm, w = scale, fun = "sd", na.policy = "omit")
tpi <- terra::terrain(dtm, v = "TPI", neighbors=8)
dev <- tpi/sd
toc()
terra::writeRaster(dev, file.path(outpath, "tpi_terra.tif"), overwrite = TRUE)
```
TPI 1) Spatial Eco

TPI 2) Terra

Thanks to Josh Evans (Ecora for suggested code improvements)
Contributor guide
Research direction
Start from the landscape covariate generation entry point that currently uses spatialEco::tpi, then run the benchmark code shown in the issue to compare it with terra::terrain and focal. Verify that the terra-based result matches the intended TPI normalization and that the generated tpi_terra.tif output preserves the expected values while improving runtime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100