Skip to content

Commit

Permalink
Merge pull request #76 from iiasa/dev
Browse files Browse the repository at this point in the history
Merging latest dev branch to main.
  • Loading branch information
Martin-Jung authored Sep 22, 2023
2 parents e910e26 + d1da8e2 commit 068ad37
Show file tree
Hide file tree
Showing 65 changed files with 1,437 additions and 591 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get -y install \
libudunits2-dev libgdal-dev libgeos-dev libproj-dev libglpk-dev
libudunits2-dev libgdal-dev libgeos-dev libproj-dev libglpk-dev libglu1-mesa-dev
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install --cask xquartz
brew install pkg-config
Expand All @@ -68,6 +68,8 @@ jobs:
any::pdp,
stan-dev/cmdstanr,
any::igraph,
any::lwgeom,
any::ncmeta,
any::xgboost,
any::dbarts,
any::mboost,
Expand Down
41 changes: 28 additions & 13 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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.0.8
version: 0.0.9
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 @@ -64,7 +64,7 @@ references:
- family-names: Hesselbarth
given-names: Maximilian H.K.
year: '2023'
version: 0.0.5
version: 0.0.9
- type: software
title: assertthat
abstract: 'assertthat: Easy Pre and Post Assertions'
Expand Down Expand Up @@ -217,6 +217,17 @@ references:
given-names: David
email: dpierce@ucsd.edu
year: '2023'
- type: software
title: ncmeta
abstract: 'ncmeta: Straightforward ''NetCDF'' Metadata'
notes: Imports
url: https://github.com/hypertidy/ncmeta
repository: https://CRAN.R-project.org/package=ncmeta
authors:
- family-names: Sumner
given-names: Michael
email: mdsumner@gmail.com
year: '2023'
- type: software
title: Matrix
abstract: 'Matrix: Sparse and Dense Matrix Classes and Methods'
Expand All @@ -235,17 +246,6 @@ references:
given-names: Mikael
orcid: https://orcid.org/0000-0002-3542-2938
year: '2023'
- type: software
title: ncmeta
abstract: 'ncmeta: Straightforward ''NetCDF'' Metadata'
notes: Imports
url: https://github.com/hypertidy/ncmeta
repository: https://CRAN.R-project.org/package=ncmeta
authors:
- family-names: Sumner
given-names: Michael
email: mdsumner@gmail.com
year: '2023'
- type: software
title: parallel
abstract: 'R: A Language and Environment for Statistical Computing'
Expand Down Expand Up @@ -306,6 +306,18 @@ references:
orcid: https://orcid.org/0000-0001-5872-2872
year: '2023'
version: '>= 1.7-10'
- type: software
title: lwgeom
abstract: 'lwgeom: Bindings to Selected ''liblwgeom'' Functions for Simple Features'
notes: Imports
url: https://github.com/r-spatial/lwgeom/
repository: https://CRAN.R-project.org/package=lwgeom
authors:
- family-names: Pebesma
given-names: Edzer
email: edzer.pebesma@uni-muenster.de
orcid: https://orcid.org/0000-0001-8049-7069
year: '2023'
- type: software
title: sf
abstract: 'sf: Simple Features for R'
Expand Down Expand Up @@ -714,6 +726,9 @@ references:
- family-names: Goodrich
given-names: Ben
email: benjamin.goodrich@columbia.edu
- family-names: Johnson
given-names: Andrew
email: andrew.johnson@arjohnsonau.com
- family-names: Weber
given-names: Sebastian
email: sdw.post@waebers.de
Expand Down
7 changes: 5 additions & 2 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.0.8
Version: 0.0.9
Authors@R:
c(person(given = "Martin",
family = "Jung",
Expand All @@ -19,6 +19,7 @@ Description: Integrated framework of modelling the distribution of species and e
Language: en-GB
License: CC BY 4.0
Encoding: UTF-8
Additional_repositories: https://inla.r-inla-download.org/R/testing
Imports:
assertthat (>= 0.2.0),
doFuture (>= 0.12.2),
Expand All @@ -30,12 +31,13 @@ Imports:
graphics,
methods,
ncdf4,
Matrix,
ncmeta,
Matrix,
parallel,
posterior,
proto (>= 1.0.0),
terra (>= 1.7-10),
lwgeom,
sf (>= 1.0),
stars (>= 0.5),
stats,
Expand Down Expand Up @@ -122,6 +124,7 @@ Collate:
'get_data.R'
'ibis.iSDM-package.R'
'limiting.R'
'mask.R'
'misc.R'
'partial.R'
'plot.R'
Expand Down
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
S3method(as.Id,character)
S3method(coef,DistributionModel)
S3method(effects,DistributionModel)
S3method(mask,BiodiversityDatasetCollection)
S3method(mask,BiodiversityScenario)
S3method(mask,DistributionModel)
S3method(mask,PredictorDataset)
S3method(partial,DistributionModel)
S3method(plot,BiodiversityDatasetCollection)
S3method(plot,BiodiversityScenario)
Expand Down Expand Up @@ -211,4 +215,10 @@ importFrom(graphics,par)
importFrom(methods,as)
importFrom(stats,complete.cases)
importFrom(stats,effects)
importFrom(stats,mad)
importFrom(stats,residuals)
importFrom(stats,sd)
importFrom(stats,terms.formula)
importFrom(stats,update.formula)
importFrom(terra,mask)
importFrom(utils,install.packages)
20 changes: 17 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# ibis.iSDM 0.0.8 (current dev branch)
# ibis.iSDM 0.0.9 (current dev branch)
#### New features
* Added new vignette on available functions for data preparation #67
* Addition of small `mask()` function that emulates the for `terra`.

#### Minor improvements and bug fixes
* Small fix to `ensemble()` so that ensembles of future scenarios use correct standardization.
* Small fix to `threshold()` now returning threshold values correctly.
* Bug fix and error catching to `distribution()` and `ensemble_partial()`,`ensemble_spartial()`
* Further checks added to `check()` #45
* Small fix to `alignRasters()`.
* Small fix to harmonize field_column throughout.
* Improved error messages and handling of formula's.

# ibis.iSDM 0.0.8
#### New features
* Implemented min size constraint (`add_constraint_minsize()`) #56
* Added a function for estimating partial effects of ensembles `ensemble_spartial()`.

#### Minor improvements and bug fixes
* Added warnings and checks for missing crs in supplied layers #65
* Smaller bug and code hamornizations to `ensemble_partial()`, `partial()` and `spartial()`.
* Small fix to `threshold()` now returning threshold values correctly.
* Smaller bug and code harmonizations to `ensemble_partial()`, `partial()` and `spartial()`.
* Smaller bug fixes to `threshold()` in `scenario()` projections.
* Improved error messages in several functions.
* Further documentation fixes towards CRAN submission #38
* Allow to specify location of biodiversity point records in `threshold()`.

# ibis.iSDM 0.0.7
#### New features
Expand Down
18 changes: 9 additions & 9 deletions R/add_biodiversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ NULL
methods::setGeneric(
"add_biodiversity_poipo",
signature = methods::signature("x", "poipo"),
function(x, poipo, name = NULL, field_occurrence = "Observed", formula = NULL, family = "poisson", link = NULL,
function(x, poipo, name = NULL, field_occurrence = "observed", formula = NULL, family = "poisson", link = NULL,
weight = 1, separate_intercept = TRUE, docheck = TRUE, pseudoabsence_settings = NULL, ...) {standardGeneric("add_biodiversity_poipo") })

#' @name add_biodiversity_poipo
Expand All @@ -81,7 +81,7 @@ methods::setGeneric(
methods::setMethod(
"add_biodiversity_poipo",
methods::signature(x = "BiodiversityDistribution", poipo = "sf"),
function(x, poipo, name = NULL, field_occurrence = "Observed", formula = NULL, family = "poisson", link = NULL,
function(x, poipo, name = NULL, field_occurrence = "observed", formula = NULL, family = "poisson", link = NULL,
weight = 1, separate_intercept = TRUE, docheck = TRUE, pseudoabsence_settings = NULL, ...) {
assertthat::assert_that(inherits(x, "BiodiversityDistribution"),
inherits(poipo, "Spatial") || inherits(poipo, "sf") || inherits(poipo, "data.frame") || inherits(poipo, "tibble"),
Expand Down Expand Up @@ -171,7 +171,7 @@ methods::setMethod(
#' @param name The name of the biodiversity dataset used as internal identifier.
#' @param field_occurrence A [`numeric`] or [`character`] location of
#' biodiversity point records indicating presence/absence. By default set to
#' \code{"Observed"} and an error will be thrown if a [`numeric`] column with
#' \code{"observed"} and an error will be thrown if a [`numeric`] column with
#' that name does not exist.
#' @param formula A [`character`] or [`formula`] object to be passed. Default
#' (\code{NULL}) is to use all covariates (if specified).
Expand Down Expand Up @@ -214,7 +214,7 @@ NULL
methods::setGeneric(
"add_biodiversity_poipa",
signature = methods::signature("x", "poipa"),
function(x, poipa, name = NULL, field_occurrence = "Observed", formula = NULL, family = "binomial", link = NULL,
function(x, poipa, name = NULL, field_occurrence = "observed", formula = NULL, family = "binomial", link = NULL,
weight = 1, separate_intercept = TRUE, docheck = TRUE, ...) standardGeneric("add_biodiversity_poipa"))

#' @name add_biodiversity_poipa
Expand All @@ -224,7 +224,7 @@ methods::setGeneric(
methods::setMethod(
"add_biodiversity_poipa",
methods::signature(x = "BiodiversityDistribution", poipa = "sf"),
function(x, poipa, name = NULL, field_occurrence = "Observed", formula = NULL, family = "binomial", link = NULL,
function(x, poipa, name = NULL, field_occurrence = "observed", formula = NULL, family = "binomial", link = NULL,
weight = 1, separate_intercept = TRUE, docheck = TRUE, ... ) {
assertthat::assert_that(inherits(x, "BiodiversityDistribution"),
inherits(poipa, "Spatial") || inherits(poipa, "sf") || inherits(poipa, "data.frame") || inherits(poipa, "tibble"),
Expand Down Expand Up @@ -362,7 +362,7 @@ NULL
methods::setGeneric(
"add_biodiversity_polpo",
signature = methods::signature("x", "polpo"),
function(x, polpo, name = NULL, field_occurrence = "Observed", formula = NULL, family = "poisson", link = NULL,
function(x, polpo, name = NULL, field_occurrence = "observed", formula = NULL, family = "poisson", link = NULL,
weight = 1, simulate = FALSE, simulate_points = 100, simulate_bias = NULL, simulate_strategy = "random",
separate_intercept = TRUE, docheck = TRUE, pseudoabsence_settings = NULL, ...) standardGeneric("add_biodiversity_polpo"))

Expand All @@ -373,7 +373,7 @@ methods::setGeneric(
methods::setMethod(
"add_biodiversity_polpo",
methods::signature(x = "BiodiversityDistribution", polpo = "sf"),
function(x, polpo, name = NULL, field_occurrence = "Observed", formula = NULL,family = "poisson", link = NULL,
function(x, polpo, name = NULL, field_occurrence = "observed", formula = NULL,family = "poisson", link = NULL,
weight = 1, simulate = FALSE, simulate_points = 100, simulate_bias = NULL, simulate_strategy = "random",
separate_intercept = TRUE, docheck = TRUE, pseudoabsence_settings = NULL, ... ) {
assertthat::assert_that(inherits(x, "BiodiversityDistribution"),
Expand Down Expand Up @@ -559,7 +559,7 @@ NULL
methods::setGeneric(
"add_biodiversity_polpa",
signature = methods::signature("x", "polpa"),
function(x, polpa, name = NULL, field_occurrence = "Observed", formula = NULL, family = "binomial", link = NULL,
function(x, polpa, name = NULL, field_occurrence = "observed", formula = NULL, family = "binomial", link = NULL,
weight = 1, simulate = FALSE, simulate_points = 100, simulate_bias = NULL, simulate_strategy = "random",
separate_intercept = TRUE, docheck = TRUE, pseudoabsence_settings = NULL, ...) standardGeneric("add_biodiversity_polpa"))

Expand All @@ -570,7 +570,7 @@ methods::setGeneric(
methods::setMethod(
"add_biodiversity_polpa",
methods::signature(x = "BiodiversityDistribution", polpa = "sf"),
function(x, polpa, name = NULL, field_occurrence = "Observed", formula = NULL, family = "binomial", link = NULL,
function(x, polpa, name = NULL, field_occurrence = "observed", formula = NULL, family = "binomial", link = NULL,
weight = 1, simulate = FALSE, simulate_points = 100, simulate_bias = NULL, simulate_strategy = "random",
separate_intercept = TRUE, docheck = TRUE, pseudoabsence_settings = NULL, ... ) {
assertthat::assert_that(inherits(x, "BiodiversityDistribution"),
Expand Down
6 changes: 3 additions & 3 deletions R/add_offset.R
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ methods::setGeneric(
signature = methods::signature("x", "layer"),
function(x, layer, distance_max = Inf, family = "poisson", presence_prop = 0.9,
distance_clip = FALSE, distance_function = "negexp",
field_occurrence = "Observed", fraction = NULL,
field_occurrence = "observed", fraction = NULL,
point = FALSE, add = TRUE) standardGeneric("add_offset_range"))

#' Function for when raster is directly supplied (precomputed)
Expand Down Expand Up @@ -467,7 +467,7 @@ methods::setMethod(
methods::signature(x = "BiodiversityDistribution", layer = "sf"),
function(x, layer, distance_max = Inf, family = "poisson", presence_prop = 0.9,
distance_clip = FALSE, distance_function = "negexp",
field_occurrence = "Observed", fraction = NULL, point = FALSE, add = TRUE ) {
field_occurrence = "observed", fraction = NULL, point = FALSE, add = TRUE ) {
assertthat::assert_that(inherits(x, "BiodiversityDistribution"),
inherits(layer, 'sf'),
is.null(distance_max) || is.numeric(distance_max) || is.infinite(distance_max),
Expand All @@ -480,7 +480,7 @@ methods::setMethod(
is.character(field_occurrence),
is.logical(add)
)
# distance_max = Inf; family = "poisson"; presence_prop = 0.9; distance_clip = FALSE; distance_function = "negexp"; field_occurrence = "Observed"; fraction = NULL; add = TRUE
# distance_max = Inf; family = "poisson"; presence_prop = 0.9; distance_clip = FALSE; distance_function = "negexp"; field_occurrence = "observed"; fraction = NULL; add = TRUE
# Match the type if set
family <- match.arg(family, c("poisson", "binomial"), several.ok = FALSE)

Expand Down
38 changes: 37 additions & 1 deletion R/bdproto-biodiversitydataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ BiodiversityDatasetCollection <- bdproto(
# Return coordinates
if(utils::hasName(o,'geom')) sf::st_coordinates(o) else o[,c('x','y')]
},
# Masking function
mask = function(self, mask, inverse = FALSE){
# Check whether prediction has been created
biob <- self$data
if(!is.Waiver(biob)){
# If mask is SpatRaster, convert to polygons
if(!inherits(mask, 'sf')){
mask <- terra::as.polygons(mask) |> sf::st_as_sf()
}
# Now for each element in biob, mask
for(id in names(biob)){
biob[[id]]$mask(mask, inverse = inverse)
}
invisible()
}
},
# Remove a specific biodiversity dataset by id
rm_data = function(self, id) {
assertthat::assert_that(is.Id(id) || is.character(id),
Expand Down Expand Up @@ -300,5 +316,25 @@ BiodiversityDataset <- bdproto(
# Collect info statistics
get_observations = function(self) {
nrow(self$data)
}
},
# Masking function
mask = function(self, mask, inverse = FALSE){
# Check whether prediction has been created
biob <- self$data
if(!is.Waiver(biob)){
# If mask is SpatRaster, convert to polygons
if(!inherits(mask, 'sf')){
mask <- terra::as.polygons(mask) |> sf::st_as_sf()
}
# Now for each element in biob, mask
biob <-
suppressMessages(
suppressWarnings(
sf::st_crop(guess_sf(biob), mask)
)
)
self$data <- biob
invisible()
}
},
)
1 change: 1 addition & 0 deletions R/bdproto-biodiversitydistribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ BiodiversityDistribution <- bdproto(
plot = function(self){
message("No generic plotting implemented!")
},
# Summary function
summary = function(self){
message("No generic summary function implemented! Try print.")
}
Expand Down
Loading

0 comments on commit 068ad37

Please sign in to comment.