-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version bump and implementation of clamping
- Loading branch information
1 parent
169505b
commit f51bad4
Showing
6 changed files
with
128 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: insights | ||
Title: An R implementation of the InSiGHTS framework | ||
Version: 0.4 | ||
Version: 0.5 | ||
Year: 2024 | ||
Authors@R: | ||
person("Martin", "Jung", , "[email protected]", role = c("aut", "cre"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#' Clamp stars to a specific bounds or range | ||
#' | ||
#' @description | ||
#' This small helper function simply clamps the a given [`SpatRaster`] or [`stars`] object \ | ||
#' to a provided range. This can help to adjust for example land-use fractions for use | ||
#' in `insights_fraction()`. | ||
#' @param env The original variable stacks as [`SpatRaster`] or [`stars`]. | ||
#' @param lb The lower bound for clamping (Default: \code{-Inf}). | ||
#' @param ub The lower bound for clamping (Default: \code{Inf}). | ||
#' | ||
#' @returns The same as input \code{'env'}. | ||
#' @examples | ||
#' \dontrun{ | ||
#' # Use | ||
#' } | ||
#' | ||
#' @author Martin Jung | ||
#' @keywords utils | ||
st_clamp <- function(env, lb = -Inf, ub = Inf){ | ||
assertthat::assert_that( | ||
ibis.iSDM::is.Raster(env) || inherits(env, "stars"), | ||
# Check numeric | ||
is.numeric(lb), | ||
is.numeric(ub), | ||
lb < ub, | ||
lb != ub | ||
) | ||
|
||
# Apply lower and upper bounds if set and finite | ||
if(is.finite(lb)){ | ||
env[env > lb] <- lb | ||
} | ||
if(is.finite(ub)){ | ||
env[env < ub] <- ub | ||
} | ||
|
||
# Checks and return | ||
assertthat::assert_that( | ||
ibis.iSDM::is.Raster(env) || inherits(env, "stars") | ||
) | ||
return(env) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.