Skip to content

Commit

Permalink
update O2 formula to convert ml/l to umol/kg
Browse files Browse the repository at this point in the history
The factor is about 1000/(1000+sigma0) or say 1000/1030 i.e. it yields
about a 0.3 percent reduction in value compared to the formula in
the pilotingapp code.
  • Loading branch information
dankelley committed Jun 24, 2024
1 parent 1e56a4c commit e2236ce
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
17 changes: 12 additions & 5 deletions R/oxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#' \url{https://github.com/DFOglider/pilotingApp}, with minor
#' modifiations: (1) it has a new name to avoid conflicts, (2) the
#' calibration coefficients are collected into a single parameter,
#' `cal`, (3) `oxygenFrequency` is renamed `frequency`, and (4) `unit`
#' is added, to permit specifying the unit of the return value.
#' `cal`, (3) `oxygenFrequency` is renamed `frequency`, (3) `unit`
#' is added, to permit specifying the unit of the return value,
#' and (5) the conversion to umol/kg takes into account the density,
#' as indicated in Reference 1.
#'
#' @param temperature numeric value holding temperature in degrees C.
#'
Expand All @@ -23,8 +25,9 @@
#'
#' @param unit character value indicating the desired unit. The
#' default is `ml/l` but `umol/kg` is also accepted, the latter being
#' computed by multiplying the former by 44.6591 (see Reference 1,
#' which uses the mole fraction stated in Reference 2.)
#' computed by multiplying the former by `44.6591*1000/(1000+sigma0)`,
#' where `sigma0` is seawater potential density anomaly in kg/m^3
#' (see Reference 1, which uses the mole fraction stated in Reference 2).
#'
#' @references
#'
Expand Down Expand Up @@ -55,7 +58,11 @@ swOxygenFrequencyToSaturation <- function(temperature,
if (identical(unit, "ml/l")) {
mll
} else if (identical(unit, "umol/kg")) {
44.6591 * mll
sigma0 <- oce::swSigma0(
salinity = salinity,
temperature = temperature, pressure = pressure, eos = "unesco"
)
44.6591 * mll * 1000 / (1000 + sigma0)
} else {
stop("unit must be 'ml/l' or 'umol/kg', but it is '", unit, "'")
}
Expand Down
Binary file modified docs/articles/oceglider_files/figure-html/unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pkgdown_sha: ~
articles:
oceglider: oceglider.html
slocum_glider: slocum_glider.html
last_built: 2024-06-24T19:16Z
last_built: 2024-06-24T19:39Z

17 changes: 11 additions & 6 deletions docs/reference/swOxygenFrequencyToSaturation.html

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

11 changes: 7 additions & 4 deletions man/swOxygenFrequencyToSaturation.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test_oxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ test_that("oxygen computed against previously-computed values", {
expect_silent(g <- read.glider.seaexplorer.realtime(directory = directory, yo = 3, progressBar = FALSE))
g@metadata$oxycalib <- oxycalib
# consistency check (will fail if dataset is changed or code changes)
options(digits = 15)
g[["oxygen"]][1:3]
expect_equal(g[["oxygen"]][1:3], c(363.265784249780, 363.301998679272, 363.257645877092))
# options(digits = 15)
# g[["oxygen"]][1:3]
expect_equal(g[["oxygen"]][1:3], c(354.508135471242, 354.543025470803, 354.499770611843))
# test values from the calibration sheet
})

Expand Down

0 comments on commit e2236ce

Please sign in to comment.