Commit 8aac025d authored by Monnet Jean-Matthieu's avatar Monnet Jean-Matthieu
Browse files

Temporary fix to NA bug in terra::merge

parent df138b01
No related merge requests found
Showing with 5 additions and 4 deletions
+5 -4
...@@ -432,11 +432,11 @@ public_cropped <- sf::st_crop(public, terra::ext(metrics_map)) ...@@ -432,11 +432,11 @@ public_cropped <- sf::st_crop(public, terra::ext(metrics_map))
Then the function `lidaRtRee::aba_predict` is used to produce the map. If the input is an object containing the stratified model and if the metrics map contains the strata layer, then the model directly maps the output by retaining the corresponding model in each stratum. Then the function `lidaRtRee::aba_predict` is used to produce the map. If the input is an object containing the stratified model and if the metrics map contains the strata layer, then the model directly maps the output by retaining the corresponding model in each stratum.
```{r mapForestStratified, include=TRUE, message=FALSE, warning=FALSE} ```{r mapForestStratified, include=TRUE, message=FALSE, warning=TRUE}
# map with stratified model # map with stratified model
prediction_map_mixed <- lidaRtRee::aba_predict(model_aba_stratified_mixed, metrics_map, stratum = "stratum") prediction_map_mixed <- lidaRtRee::aba_predict(model_aba_stratified_mixed, metrics_map, stratum = "stratum")
# ISSUE in terra::merge 1.7.3 : NA values are not handled correctly ? # ISSUE in terra::merge 1.7.3 : NA values are not handled correctly ?
# WAITING for a fix so that stratified maps are correctly merged # CORRECTED in 1.7.8 for a fix so that stratified maps are correctly merged
# for checking purposes # for checking purposes
# extracted "private" stratum model from combined model # extracted "private" stratum model from combined model
model_private <- list(model = model_aba_stratified_mixed$model$private, stats = model_aba_stratified_mixed$stats["private", ]) model_private <- list(model = model_aba_stratified_mixed$model$private, stats = model_aba_stratified_mixed$stats["private", ])
...@@ -447,9 +447,10 @@ model_public <- list(model = model_aba_stratified_mixed$model$public, stats = mo ...@@ -447,9 +447,10 @@ model_public <- list(model = model_aba_stratified_mixed$model$public, stats = mo
# produce corresponding map # produce corresponding map
prediction_map_public <- lidaRtRee::aba_predict(model_public, metrics_map) prediction_map_public <- lidaRtRee::aba_predict(model_public, metrics_map)
# TEMPORARY fix to NA values in terra::merge (call by lidaRtRee::aba_predict) # TEMPORARY fix to NA values in terra::merge (call by lidaRtRee::aba_predict)
if (packageVersion("terra")<"1.7.3" | packageVersion("terra")>="1.7.8") if (packageVersion("terra")>="1.7.3" && packageVersion("terra")<"1.7.8")
{ {
warning("Merging with terra::mosaic because terra::merge in 1.7.3 and 1.7.6 does not handle NA values") packageVersion("terra")
warning("Manually merging with terra::mosaic because terra::merge in 1.7.3 and 1.7.6 does not handle NA values")
prediction_map_mixed <- terra::mosaic(prediction_map_public, prediction_map_private, fun = max) prediction_map_mixed <- terra::mosaic(prediction_map_public, prediction_map_private, fun = max)
} }
``` ```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment