From 35ffcc4031d18c4d08752ae9c600cca3a1184d53 Mon Sep 17 00:00:00 2001 From: Jean-Matthieu Monnet <jean-matthieu.monnet@inrae.fr> Date: Tue, 21 Jan 2025 13:30:13 +0100 Subject: [PATCH] ... arguments added to some functions, no-finite values replaced in aba --- DESCRIPTION | 4 ++-- NEWS.md | 3 +++ R/aba.R | 19 ++++++++++++++----- R/optical_metrics.R | 2 +- README.md | 4 ++-- man/aba_build_model.Rd | 9 +++++++-- man/aba_predict.Rd | 5 ++++- man/add_vegetation_indices.Rd | 2 +- man/convert_raster.Rd | 11 ++--------- 9 files changed, 36 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ca1adbb..1044ce6 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: lidaRtRee Type: Package Version: 4.0.7 Title: Forest Analysis with Airborne Laser Scanning (LiDAR) Data -Date: 2024-03-13 +Date: 2024-09-13 Authors@R: c( person("Jean-Matthieu", "Monnet", email = "jean-matthieu.monnet@inrae.fr", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9948-9891")), person("Pascal", "Obstétar", email = "pascal.obstetar@onf.fr", role = c("ctb"), comment = c(ORCID = "0000-0002-2811-7548"))) @@ -24,5 +24,5 @@ Imports: graphics, stats, methods, grDevices, terra, sf, imager, leaps, gvlma, c Suggests: stars License: GPL-3 LazyData: TRUE -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index 3c40bde..3aac860 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,11 +3,14 @@ ## New * `clouds_tree_metrics()` now has a `roi` argument to select trees to retain for subsequent computation based on spatial object. +* `ABA_predict()` now has a `...` argument to pass additional arguments to `stats::predict.lm()`. ## Change * `boxcox_tr()` and `boxcox_itr()` do not automatically replace `0` with `NA` anymore. * `RasterLayer` objects are not supported anymore as the `raster` package package is now obsolete. +* in `aba_build_model()`, when specified the minimum `threshold` parameter now replaces non finite values in predictions. +* added `...` argument in `aba_build_model()`: passed to `leaps::regsubsets()` # lidaRtRee 4.0.6 diff --git a/R/aba.R b/R/aba.R index 435d1da..9dd6f99 100755 --- a/R/aba.R +++ b/R/aba.R @@ -38,7 +38,10 @@ #' observations: not used in the function but exported in the result for use in #' further inference functions #' @param threshold vector of length two. minimum and maximum values of threshold -#' to apply to predicted values +#' to apply to predicted values. Non-finite values are replaced by the minimum. +#' Values are replaced after computation of the variance of residuals used for +#' bias correction +#' @param ... other parameters to be passed to \code{\link[leaps]{regsubsets}}, #' #' @seealso \code{\link{aba_combine_strata}} for combining models calibrated #' on different strata, \code{\link{aba_plot}} for plotting model @@ -84,7 +87,8 @@ aba_build_model <- nmax = 3, test = c("partial_p", "vif", "gvlma"), xy = NULL, - threshold = NULL) { + threshold = NULL, + ...) { # build data.frame with dependent variable and predictors df <- data.frame(dep_var = variable, predictors) row.names(df) <- row.names(predictors) @@ -147,7 +151,8 @@ aba_build_model <- nbest = 20, nvmax = nmax - 1, method = "exhaustive", - really.big = TRUE + really.big = TRUE, + ... ) ) #----------------------------------------------------------------------------- @@ -229,6 +234,7 @@ aba_build_model <- if (!is.null(threshold)) { prediction <- pmin(prediction, threshold[2]) prediction <- pmax(prediction, threshold[1]) + prediction[!is.finite(prediction)] <- threshold[1] } # #--------------------------------------------------------------------------- @@ -697,6 +703,7 @@ aba_plot <- #' \code{log} transformation case #' @param pkg raster output format. Use pkg = "terra|raster|stars" to get an output in SpatRaster, RasterLayer #' or stars format. +#' @param ... other parameters to be passed to \code{\link[stats]{predict.lm}}, e.g. \code{interval = "prediction"}, #' @examples #' # load data #' data(quatre_montagnes) @@ -724,7 +731,8 @@ aba_predict <- metrics_map, stratum = NULL, add_error = FALSE, - pkg = "terra") { + pkg = "terra", + ...) { # convert to terra if(!inherits(metrics_map, "SpatRaster")) metrics_map <- convert_raster(metrics_map, "terra") # create factor of stratum if not existing @@ -757,7 +765,8 @@ aba_predict <- } # predict on all cells r[[stratum_label]] <- terra::predict(newdata, - model_aba$model[[stratum_label]]) + model_aba$model[[stratum_label]], + ...) if (model_aba$stats[stratum_label, "transform"] == "boxcox") # case of Box-Cox transform diff --git a/R/optical_metrics.R b/R/optical_metrics.R index ec32722..d704e59 100755 --- a/R/optical_metrics.R +++ b/R/optical_metrics.R @@ -7,7 +7,7 @@ #' #' Computes vegetation indices from the Red, Green and Infra-Red bands of an IRC #' image and adds them as additional bands or columns. Acronyms are listed on -#' \url{https://www.l3harrisgeospatial.com/docs/broadbandgreenness.html}. If the +#' \url{https://www.nv5geospatialsoftware.com/docs/BroadbandGreenness.html}. If the #' Blue band is also present, additional indices are computed. #' #' @param r raster or data.frame. Should contain bands or columns with diff --git a/README.md b/README.md index 9e6d2ce..37f14f6 100755 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ Tutorials using `lidaRtRee` functions are available in the [vignettes](https://f # Acknowledgements / funding -`lidaRtRee` development (2018-2021) was funded by the [ADEME](https://www.ademe.fr/en) (french Agency for Ecological Transition) through the [PROTEST](https://protest.inrae.fr/) project (grant 1703C0069 of the GRAINE program). +`lidaRtRee` development (2018-2021) was funded by the [ADEME](https://www.ademe.fr/en/frontpage/) (french Agency for Ecological Transition) through the [PROTEST](https://protest.inrae.fr/) project (grant 1703C0069 of the GRAINE program). -[<img src="man/figures/logo-ademe-republique-francaise.jpg" alt="logo-ademe-republique-francaise" width="300"/>](https://www.ademe.fr/en) +[<img src="man/figures/logo-ademe-republique-francaise.jpg" alt="logo-ademe-republique-francaise" width="300"/>](https://www.ademe.fr/en/frontpage/) <br> [<img src="man/figures/logo_inrae.png" alt="logo_inrae" width="330"/>](https://www.inrae.fr/en) diff --git a/man/aba_build_model.Rd b/man/aba_build_model.Rd index 363b2c1..c873842 100755 --- a/man/aba_build_model.Rd +++ b/man/aba_build_model.Rd @@ -11,7 +11,8 @@ aba_build_model( nmax = 3, test = c("partial_p", "vif", "gvlma"), xy = NULL, - threshold = NULL + threshold = NULL, + ... ) } \arguments{ @@ -35,7 +36,11 @@ observations: not used in the function but exported in the result for use in further inference functions} \item{threshold}{vector of length two. minimum and maximum values of threshold -to apply to predicted values} +to apply to predicted values. Non-finite values are replaced by the minimum. +Values are replaced after computation of the variance of residuals used for +bias correction} + +\item{...}{other parameters to be passed to \code{\link[leaps]{regsubsets}},} } \value{ a list with three elements diff --git a/man/aba_predict.Rd b/man/aba_predict.Rd index 5d81118..fd9183d 100755 --- a/man/aba_predict.Rd +++ b/man/aba_predict.Rd @@ -9,7 +9,8 @@ aba_predict( metrics_map, stratum = NULL, add_error = FALSE, - pkg = "terra" + pkg = "terra", + ... ) } \arguments{ @@ -29,6 +30,8 @@ N(0, sigma(residuals)) should be added to fitted values; implemented only for \item{pkg}{raster output format. Use pkg = "terra|raster|stars" to get an output in SpatRaster, RasterLayer or stars format.} + +\item{...}{other parameters to be passed to \code{\link[stats]{predict.lm}}, e.g. \code{interval = "prediction"},} } \value{ a raster of predictions obtained by applying the model \code{aba_build_model} diff --git a/man/add_vegetation_indices.Rd b/man/add_vegetation_indices.Rd index 54788bf..9caa5c8 100755 --- a/man/add_vegetation_indices.Rd +++ b/man/add_vegetation_indices.Rd @@ -21,7 +21,7 @@ a raster or data.frame with added bands or columns \description{ Computes vegetation indices from the Red, Green and Infra-Red bands of an IRC image and adds them as additional bands or columns. Acronyms are listed on -\url{https://www.l3harrisgeospatial.com/docs/broadbandgreenness.html}. If the +\url{https://www.nv5geospatialsoftware.com/docs/BroadbandGreenness.html}. If the Blue band is also present, additional indices are computed. } \examples{ diff --git a/man/convert_raster.Rd b/man/convert_raster.Rd index 18a8ec4..a425280 100755 --- a/man/convert_raster.Rd +++ b/man/convert_raster.Rd @@ -10,7 +10,7 @@ convert_raster(r, pkg = NULL) \item{r}{raster object or file name.} \item{pkg}{package name. Use pkg = "terra| -raster|stars" to get an output in SpatRaster, RasterLayer or stars format} +stars" to get an output in SpatRaster or stars format} } \value{ A raster object in the specified format @@ -29,13 +29,6 @@ chm_chablais3 <- terra::rast(chm_chablais3) # to stars # chm_stars <- convert_raster(chm_chablais3, pkg = "stars") # chm_stars +# convert_raster(chm_stars, pkg = "terra") # } -if (require("raster")) -{ -# to raster -chm_raster <- convert_raster(chm_chablais3, pkg = "raster") -chm_raster -# back to terra -convert_raster(chm_raster, pkg = "terra") -} } -- GitLab