Skip to content

Commit

Permalink
add option to use land mask with max land extent to compute delta
Browse files Browse the repository at this point in the history
  • Loading branch information
avpozzi committed Dec 18, 2024
1 parent adbe58f commit 5166cb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions R/delta_compute.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#' time steps of interest
#' @param ref_time the time (BP) of the slice that is used to compute the delta
#' @param obs the observations
#' @param max_land a [`terra::SpatRaster`] with the maximum land extent
#' @returns a [`terra::SpatRaster`] of the delta
#' @export

delta_compute <- function(x, ref_time, obs) {
delta_compute <- function(x, ref_time, obs, max_land = NULL) {
ref_index <- which(time_bp(x)==ref_time)
if(length(ref_index)!=1){
stop("ref_time should be a time in x")
Expand All @@ -44,8 +45,10 @@ delta_compute <- function(x, ref_time, obs) {
# compute anomalies against the modern
delta <- obs - x_modern_high
# mask for maximum land extent
max_land <- max(x,na.rm=TRUE)
max_land <- resample(max_land, obs)
if (is.null(max_land)) {
max_land <- max(x,na.rm=TRUE)
max_land <- resample(max_land, obs)
}
delta_interp <- idw_interp(delta,max_land)
return(delta_interp)
}
4 changes: 3 additions & 1 deletion man/delta_compute.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5166cb4

Please sign in to comment.