Skip to content

Commit

Permalink
abstract extraction of tie points
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasHohmann committed Aug 28, 2024
1 parent 8f39e1a commit 26621d4
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: admtools
Title: Estimate and Manipulate Age-Depth Models
Version: 0.3.0
Version: 0.3.1
Authors@R:
person("Niklas", "Hohmann", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1559-1838"))
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

S3method(condensation,adm)
S3method(condensation,multiadm)
S3method(get_L_tp,adm)
S3method(get_L_tp,sac)
S3method(get_L_unit,adm)
S3method(get_L_unit,multiadm)
S3method(get_L_unit,sac)
S3method(get_T_tp,adm)
S3method(get_T_tp,sac)
S3method(get_T_unit,adm)
S3method(get_T_unit,multiadm)
S3method(get_T_unit,sac)
Expand Down Expand Up @@ -68,7 +72,9 @@ export(condensation_fun)
export(flux_const)
export(flux_linear)
export(flux_quad)
export(get_L_tp)
export(get_L_unit)
export(get_T_tp)
export(get_T_unit)
export(get_completeness)
export(get_data_from_eTimeOpt)
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# admtools (development version)
# admtools 0.3.1

* more options for sedimentation rate generator `sed_rate_from_matrix`

* abstracted exctraction of tie points

# admtools 0.3.0

Expand Down
29 changes: 29 additions & 0 deletions R/get_L_tp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
get_L_tp = function(x, ...){
#' @export
#'
#' @title get height/length tie point
#'
#' @param x age-depth model (adm) or sediment accumulation curve (sac)
#' @param ... other options, currently not used
#'
#' @description
#' extracts the height/length time points from an age-depth model or sediment accumulation curve
#'
#' @returns numeric vector of the time/length tie points
#'
#' @seealso [get_T_tp()] to extract time tie points
#'
UseMethod("get_L_tp")
}

get_L_tp.adm = function(x, ...){
#' @export
#'
return(x$h)
}

get_L_tp.sac = function(x, ...){
#' @export
#'
return(x$h)
}
27 changes: 27 additions & 0 deletions R/get_T_tp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
get_T_tp = function(x, ...){
#' @export
#'
#' @title extract time tie points
#'
#' @param x age-depth model (adm) or sediment accumulation curve (sac)
#' @param ... other options, currently unused
#'
#' @description
#' Extracts the time tie points from an age-depth model or sediment accumulation curve
#'
#' @returns a vector, containing the time tie points
#'
#' @seealso [get_L_tp()] to extract length/height tie points
#'
UseMethod("get_T_tp")
}

get_T_tp.adm = function(x, ...){
#' @export
return(x$t)
}

get_T_tp.sac = function(x, ...){
#' @export
return(x$t)
}
2 changes: 1 addition & 1 deletion R/tp_to_adm.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tp_to_adm = function(t, h, T_unit = NULL, L_unit = NULL){
#'
#' @returns object of class `adm`
#'
#' @seealso [is_adm()] to check validity of `adm` objects
#' @seealso [is_adm()] to check validity of `adm` objects, [get_T_tp()] and [get_L_tp()] to extract time and height/length tie points
#'
#'
#' @examples
Expand Down
2 changes: 2 additions & 0 deletions R/tp_to_sac.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ tp_to_sac = function(t, h, T_unit = NULL, L_unit = NULL){
#' @param L_unit length unit
#'
#' @returns a _sac_ object reflecting a sediment accumulation curve
#'
#' @seealso [sac_to_adm()] to transform sediment accumulation curves into age-depth models, [get_T_tp()] and [get_L_tp()] to extract time and height/length tie points

li = list(t = t,
h = h,
Expand Down
22 changes: 22 additions & 0 deletions man/get_L_tp.Rd

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

22 changes: 22 additions & 0 deletions man/get_T_tp.Rd

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

2 changes: 1 addition & 1 deletion man/tp_to_adm.Rd

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

3 changes: 3 additions & 0 deletions man/tp_to_sac.Rd

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

10 changes: 10 additions & 0 deletions tests/testthat/test_get_L_tp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test_that("correct heights are returned",{
h = 1:4
t = 1:4
adm = tp_to_adm(t, h)
expect_equal(get_L_tp(adm), h)

h = rev(h)
sac = tp_to_sac(t, h)
expect_equal(get_L_tp(sac), h)
})
10 changes: 10 additions & 0 deletions tests/testthat/test_get_T_tp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test_that("correct times are returned",{
h = 1:4
t = 1:4
adm = tp_to_adm(t, h)
expect_equal(get_T_tp(adm), t)

h = rev(h)
sac = tp_to_sac(t, h)
expect_equal(get_T_tp(sac), t)
})
2 changes: 1 addition & 1 deletion vignettes/admtools.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ If you want to inspect the insides of the object, use `str`:
str(my_adm)
```

You can manually manipulate the fields of the `adm` object by treating it like a list. I do not recommend doing so, as it might result in unexpected downstream behavior.
You can manually manipulate the fields of the `adm` object by treating it like a list. I do not recommend doing so, as it might result in unexpected downstream behavior. If you want to extract tie points use `get_L_tp` and `get_T_tp`.

You can plot `adm` objects via the standard `plot` function. Here, I use the option to highlight hiatuses in red, and increase the linw width of the conservative ( = non-destructive) intervals.

Expand Down
4 changes: 3 additions & 1 deletion vignettes/admtools_doc.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ The following functions extract information from `adm` objects:
- `max_height.adm` extracts highest stratigraphic point in adm
- `min_height.adm` extracts lowest stratigaphic point in adm
- `min_time.adm` extracts timing of first tie point in adm
_ `max_time.adm` extracts timing of last tie point in adm
- `max_time.adm` extracts timing of last tie point in adm
- `get_L_tp` and `get_T_tp` to extract tie points.

#### Transformation into other S3 classes

Expand Down Expand Up @@ -144,6 +145,7 @@ The following functions modify `sac` objects:
The following functions extract information from `sac` objects:

- `get_L_unit` and `get_T_unit` to extract units
- `get_T_tp` and `get_L_tp` to extract tie points

#### Transformation into other S3 classes

Expand Down

0 comments on commit 26621d4

Please sign in to comment.