bcgov / bcgov/PEMsamplr

Update tpi calcs in landscape covariates to terra

Open
#6 0 comments 0 reactions 0 assignees View on GitHub
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
![image](https://user-images.githubusercontent.com/39040813/223193328-350602e9-26f1-46e5-872f-c126ff5fdb07.png)

TPI 2) Terra
![image](https://user-images.githubusercontent.com/39040813/223193445-185a1d23-a436-4b41-89db-86f937ddce42.png)

Thanks to Josh Evans (Ecora for suggested code improvements)

Contributor guide

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.