Skip to content

Commit

Permalink
Merge pull request #132 from iiasa/dev
Browse files Browse the repository at this point in the history
Version bump
  • Loading branch information
Martin-Jung authored Aug 3, 2024
2 parents ef889ee + d0af641 commit 3011208
Show file tree
Hide file tree
Showing 54 changed files with 1,421 additions and 449 deletions.
26 changes: 20 additions & 6 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -----------------------------------------------------------
# CITATION file created with {cffr} R package, v1.0.0
# --------------------------------------------
# CITATION file created with {cffr} R package
# See also: https://docs.ropensci.org/cffr/
# -----------------------------------------------------------
# --------------------------------------------

cff-version: 1.2.0
message: 'To cite package "ibis.iSDM" in publications use:'
type: software
license: CC-BY-4.0
title: 'ibis.iSDM: Modelling framework for integrated biodiversity distribution scenarios'
version: 0.1.3
version: 0.1.4
abstract: Integrated framework of modelling the distribution of species and ecosystems
in a suitability framing. This package allows the estimation of integrated species
distribution models (iSDM) based on several sources of evidence and provided presence-only
Expand Down Expand Up @@ -153,7 +153,7 @@ references:
title: geodist
abstract: 'geodist: Fast, Dependency-Free Geodesic Distance Calculations'
notes: Imports
url: https://github.com/hypertidy/geodist
url: https://hypertidy.github.io/geodist/
repository: https://CRAN.R-project.org/package=geodist
authors:
- family-names: Padgham
Expand Down Expand Up @@ -566,7 +566,20 @@ references:
given-names: Fabian E.
email: [email protected]
year: '2024'
version: '>= 2.6.0'
version: '>= 2.10.0'
- type: software
title: fmesher
abstract: 'fmesher: Triangle Meshes and Related Geometry Tools'
notes: Suggests
url: https://inlabru-org.github.io/fmesher/
repository: https://CRAN.R-project.org/package=fmesher
authors:
- family-names: Lindgren
given-names: Finn
email: [email protected]
orcid: https://orcid.org/0000-0002-5833-2011
year: '2024'
version: '>= 0.1.7'
- type: software
title: igraph
abstract: 'igraph: Network Analysis and Visualization'
Expand Down Expand Up @@ -867,3 +880,4 @@ references:
given-names: Jiaming
email: [email protected]
year: '2024'

9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ibis.iSDM
Type: Package
Title: Modelling framework for integrated biodiversity distribution scenarios
Version: 0.1.3
Version: 0.1.4
Authors@R:
c(person(given = "Martin",
family = "Jung",
Expand Down Expand Up @@ -66,7 +66,8 @@ Suggests:
glmnetUtils,
gnlm,
geosphere,
inlabru (>= 2.6.0),
inlabru (>= 2.10.0),
fmesher (>= 0.1.7),
igraph,
knitr,
mboost,
Expand All @@ -83,7 +84,7 @@ Suggests:
xgboost
URL: https://iiasa.github.io/ibis.iSDM/
BugReports: https://github.com/iiasa/ibis.iSDM/issues
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Config/testthat/edition: 3
Roxygen: list(markdown = TRUE)
Biarch: true
Expand All @@ -98,8 +99,8 @@ Collate:
'add_constraint.R'
'add_constraint_MigClim.R'
'add_control_bias.R'
'add_control_extrapolation.R'
'add_latent.R'
'add_limits_extrapolation.R'
'class-log.R'
'add_log.R'
'add_offset.R'
Expand Down
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export(add_constraint_dispersal)
export(add_constraint_minsize)
export(add_constraint_threshold)
export(add_control_bias)
export(add_control_extrapolation)
export(add_latent_spatial)
export(add_limits_extrapolation)
export(add_log)
export(add_offset)
export(add_offset_bias)
Expand Down Expand Up @@ -134,7 +134,9 @@ export(project.BiodiversityScenario)
export(pseudoabs_settings)
export(render_html)
export(rm_biodiversity)
export(rm_control)
export(rm_latent)
export(rm_limits)
export(rm_offset)
export(rm_predictors)
export(rm_priors)
Expand Down
19 changes: 18 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# ibis.iSDM 0.1.3 (current dev branch)
# ibis.iSDM 0.1.4 (current dev branch)

#### New features
* Support for carnying over latent spatial effects (`add_latent_spatial()`) to `scenario()` projections.
* Convenience functions to remove limits and controls `rm_limits()`/`rm_control()` #121
* :fire: Enable stars and multi-temporal SpatRaster zones for `scenario()` and `distribution()` #121

#### Minor improvements and bug fixes
* :bug: fix for support of factor x continuous variable interaction #131
* Renamed `add_control_extrapolation` to `add_limits_extrapolation()`.
* :bug: fix to `engine_gdb` also to support non-linear smooth functions (again).
* Small fix to support deprecated `field_occurrence` field in `validate` for convenience.
* :bug: fix that prevented `BART` models to be saved/loaded from disk #127.
* :bug: fixes related to `factor` handling for all engines.
* :bug: fixes related to `is_comparable_raster` and `add_predictors`/`add_predictors_range` #130
* :bug: fix related to `partial` for `engine_gdb` and priors

# ibis.iSDM 0.1.3

#### New features
* Add functions that creates HTML file base on `DistributionModel`.
Expand Down
44 changes: 44 additions & 0 deletions R/add_control_bias.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,47 @@ methods::setMethod(
return(y)
}
)

#' Remove control from an existing distribution object
#'
#' @description This function allows to remove set control obtions from an existing [distribution]
#' object.
#'
#' @param x [distribution] (i.e. [`BiodiversityDistribution-class`]) object.
#'
#' @family control
#' @seealso [add_control_bias()]
#'
#' @examples
#' \dontrun{
#' x <- distribution(background) |>
#' add_predictors(covariates) |>
#' add_control_bias(method = "proximity")
#' x <- x |> rm_control()
#' x
#' }
#'
#' @name rm_control
NULL

#' @rdname rm_control
#' @export
methods::setGeneric(
"rm_control",
signature = methods::signature("x"),
function(x) standardGeneric("rm_control"))

#' @rdname rm_control
methods::setMethod(
"rm_control",
methods::signature(x = "BiodiversityDistribution"),
function(x) {
assertthat::assert_that(inherits(x, "BiodiversityDistribution") )
# Make a deep copy
y <- x$clone(deep = TRUE)

y <- y$rm_control()
# Return x without control
return(y)
}
)
65 changes: 64 additions & 1 deletion R/add_latent.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ methods::setMethod(
methods::signature(x = "BiodiversityDistribution"),
function(x, method = 'spde', priors = NULL, separate_spde = FALSE, ...) {
assertthat::assert_that(inherits(x, "BiodiversityDistribution"),
is.character(method) && !missing(method),
is.character(method),
is.null(priors) || inherits(priors, 'PriorList'),
is.logical(separate_spde)
)
Expand All @@ -110,6 +110,49 @@ methods::setMethod(
}
)

#### Latent for scenarios ####
#' Add latent spatial effect to the model equation
#' @param layer A [`SpatRaster`] layer describing alternative latent effects to be used instead
#' if \code{"reuse_latent"} is set to \code{FALSE}.
#' @param reuse_latent A [`logical`] flag on whether any latent effects found
#' in the fitted model should be reused (Default \code{TRUE}).
#' @rdname add_latent_spatial
methods::setMethod(
"add_latent_spatial",
methods::signature(x = "BiodiversityScenario"),
function(x, layer = NULL, reuse_latent = TRUE, ...) {
assertthat::assert_that(
inherits(x, "BiodiversityScenario"),
is.Raster(layer) || is.null(layer),
is.logical(reuse_latent)
)

# Check existing model if latent factors are set there
if(reuse_latent){
# Try and see if model has been defined?
fit <- x$get_model()
if(!is.Waiver(fit)){
# Latent-factors specified?
check <- fit$has_latent()
assertthat::assert_that(
check,
msg = "Latent factors are to be reused, but could not be found in fitted model?"
)
}
}

# Build latent object
lat <- list("layer" = layer, "reuse_latent" = reuse_latent)

# Make a clone copy of the object
y <- x$clone(deep = TRUE)

# Add to data to the BiodiversityDistribution object
y$set_latent(lat)
}
)


#' Function to remove a latent effect
#'
#' @description This is just a wrapper function for removing specified offsets
Expand Down Expand Up @@ -156,3 +199,23 @@ methods::setMethod(
y$rm_latent()
}
)

#' @rdname rm_latent
methods::setMethod(
"rm_latent",
methods::signature(x = "BiodiversityScenario"),
function(x) {
assertthat::assert_that(inherits(x, "BiodiversityScenario") )
# If no offset can be found, just return proto object
if(is.Waiver(x$latentfactors)){ return(x) }

# Messenger
if(getOption('ibis.setupmessages', default = TRUE)) myLog('[Setup]','yellow','Removing latent effects.')

# Make a clone copy of the object
y <- x$clone(deep = TRUE)

# Now remove the offset
y$rm_latent()
}
)
Loading

0 comments on commit 3011208

Please sign in to comment.