-
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.
Merge pull request #44 from MindTheGap-ERC/dev
Dev
- Loading branch information
Showing
11 changed files
with
127 additions
and
16 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
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,63 @@ | ||
anchor = function(x, index = "last", t_anchor = NULL, n = 1000L){ | ||
#' @export | ||
#' | ||
#' @title anchor age-depth model | ||
#' | ||
#' @param x age-depth model | ||
#' @param index "last" or "first", specifying at which tie point the age-depth model will be anchored | ||
#' @param t_anchor time at which the adm is anchored. must be a function that takes no arguments and returns the timing of the tie point. see example or vignettes for details | ||
#' @param n integer, number of samples drawn from the tie point | ||
#' | ||
#' @description | ||
#' anchors a deterministic age-depth model (adm object) at a tie point that is associated with uncertainty. | ||
#' | ||
#' | ||
#' | ||
#' @returns a collection of age-depth models (a multiadm object) | ||
#' | ||
#' @examples | ||
#' t_anchor = function() rnorm(1) # normally distributed uncertainty | ||
#' x = tp_to_adm(t = c(1,2), h = c(2,3)) # simple age-depth model | ||
#' m = anchor(x, index = "last", t_anchor = t_anchor, n = 100) # anchor age-depth model | ||
#' plot(m) | ||
#' | ||
if (! index %in% c("last", "first")){ | ||
stop("can only anchor at first or last tie point") | ||
} | ||
|
||
if (! (is.function(t_anchor))){ | ||
stop("expect functions as inputs for t_anchor") | ||
} | ||
adm_list = list() | ||
if (index == "last"){ | ||
t_ref = max_time(x) | ||
} | ||
if (index == "first"){ | ||
t_ref = min_time(x) | ||
} | ||
|
||
for (i in seq_len(n)){ | ||
t_offset = t_anchor() | ||
t = get_T_tp(x) - t_ref + t_offset | ||
h = get_L_tp(x) | ||
L_unit = get_L_unit(x) | ||
T_unit = get_T_unit(x) | ||
adm_list[[i]] = tp_to_adm(t, h, T_unit, L_unit) | ||
} | ||
|
||
multiadm = list("t" = list(), | ||
"h" = list(), | ||
"destr" = list(), | ||
"no_of_entries" = length(adm_list), | ||
"T_unit" = get_T_unit(x), | ||
"L_unit" = get_L_unit(x)) | ||
|
||
for (i in seq_along(adm_list)){ | ||
adm = adm_list[[i]] | ||
multiadm[["t"]][[i]] = adm$t | ||
multiadm[["h"]][[i]] = adm$h | ||
multiadm[["destr"]][[i]] = adm$destr | ||
} | ||
class(multiadm) = "multiadm" | ||
return(multiadm) | ||
} |
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
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
test_that("incorrect input for index paramter is caught", { | ||
t_anchor = function() rnorm(n = 1) | ||
x = tp_to_adm(c(0,1), c(0,1), "Myr", "m") | ||
expect_no_condition(anchor(x, index = "last", t_anchor, n = 10)) | ||
expect_no_condition(anchor(x, index = "first", t_anchor, n = 10)) | ||
expect_error(anchor(x, index = 2, t_anchor, n = 10)) | ||
}) | ||
|
||
test_that("incorrect input for t_anchor parameter is caught", { | ||
x = tp_to_adm(c(0,1), c(0,1), "Myr", "m") | ||
t_anchor = 2 | ||
expect_error(anchor(x, "last", t_anchor, n = 10)) | ||
}) |
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