Skip to content

Commit

Permalink
Version bump and small zoning-related fixes added #121
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Jung committed Aug 5, 2024
1 parent d0af641 commit 8d536e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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.4
Version: 0.1.5
Authors@R:
c(person(given = "Martin",
family = "Jung",
Expand Down
9 changes: 8 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# ibis.iSDM 0.1.4 (current dev branch)
# ibis.iSDM 0.1.5 (current dev branch)

#### New features

#### Minor improvements and bug fixes
* Minor :bug: fix related to misaligned thresholds and negative expontential kernels.

# ibis.iSDM 0.1.4

#### New features
* Support for carnying over latent spatial effects (`add_latent_spatial()`) to `scenario()` projections.
Expand Down
5 changes: 4 additions & 1 deletion R/add_constraint.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,11 @@ methods::setMethod(
# Divide alpha values by 2
alpha <- value/2

# Scale value for different projections
value_scale <- ifelse(terra::is.lonlat(baseline_threshold), terra::res(baseline_threshold)[1] * 10000, 1)

# Grow baseline raster by using an exponentially weighted kernel
ras_dis <- terra::gridDist(baseline_threshold, target = 1)
ras_dis <- terra::gridDist(baseline_threshold, target = 1, scale = value_scale)
# Normalized (with a constant) negative exponential kernel
ras_dis <- terra::app(ras_dis, fun = function(x) (1 / (2 * pi * value ^ 2)) * exp(-x / value) )
# Equivalent to alpha = 1/value and
Expand Down
16 changes: 11 additions & 5 deletions R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ methods::setMethod(
msg = "Model predictors are missing from the scenario predictor!")
}

# Create a template for use
template <- emptyraster( new_preds$get_data() )

# Get constraints, threshold values and other parameters
scenario_threshold <- mod$get_threshold()
if(!is.Waiver(scenario_threshold)){
Expand Down Expand Up @@ -264,8 +267,13 @@ methods::setMethod(
baseline_threshold <- baseline_threshold[[grep(layer, names(baseline_threshold))]]
}

# Set all NA values to 0 (and then mask by background?)
baseline_threshold[is.na(baseline_threshold)]<-0
# Set all NA values to 0
baseline_threshold[is.na(baseline_threshold)] <- 0
# Align with newpreds extend and
if(!terra::compareGeom(baseline_threshold, template, stopOnError = FALSE)){
baseline_threshold <- terra::extend(baseline_threshold, template)
baseline_threshold <- terra::crop(baseline_threshold, template)
}

} else {
baseline_threshold <- new_waiver()
Expand All @@ -275,9 +283,6 @@ methods::setMethod(
scenario_constraints <- mod$get_constraints()
scenario_simulations <- mod$get_simulation()

# Create a template for use
template <- emptyraster( new_preds$get_data() )

# --- Check that everything is there ---
# Check that thresholds are set for constrains
if("dispersal" %in% names(scenario_constraints)){
Expand Down Expand Up @@ -455,6 +460,7 @@ methods::setMethod(
scenario_threshold <- scenario_threshold[[1]]
out_thresh <- out
out_thresh[out_thresh < scenario_threshold] <- 0; out_thresh[out_thresh >= scenario_threshold] <- 1
out_thresh[is.na(out_thresh)] <- 0 # Added to avoid unnecessary clipping
names(out_thresh) <- "threshold"

# Apply minimum size constraint if set
Expand Down

0 comments on commit 8d536e7

Please sign in to comment.