Title: | Discovery, Retrieval, and Analysis of Water Isotope Data |
---|---|
Description: | The wiDB...() functions provide an interface to the public API of the wiDB <https://github.com/SPATIAL-Lab/isoWater/blob/master/Protocol.md>: build, check and submit queries, and receive and unpack responses. Data analysis functions support Bayesian inference of the source and source isotope composition of water samples that may have experienced evaporation. Algorithms adapted from Bowen et al. (2018, <doi:10.1007/s00442-018-4192-5>). |
Authors: | Gabe Bowen [aut, cre] |
Maintainer: | Gabe Bowen <[email protected]> |
License: | GPL-3 |
Version: | 1.2.0 |
Built: | 2024-11-21 06:46:42 UTC |
Source: | CRAN |
Calculates deuterium excess or line-conditioned excess.
dex(HO, form = "dex", MWL = NULL)
dex(HO, form = "dex", MWL = NULL)
HO |
data.frame. Hydrogen (column 1) and oxygen (column 2) isotope values for 1 or more water samples. |
form |
character. Calculate deuterium excess (“dex”), line-conditioned excess (“lcex”), or “both”. |
MWL |
numeric. Vector the first two elements of which contain the meteoric water line slope and intercept (e.g., as created by |
Returns a copy of HO
with an added field(s) “dex” and/or “lcex” containing the calculated values. Deuterium excess is calculated following Dansgaard (1964) as: dex = 2H - 8 *
18O, and lc-excess following Landwehr & Coplen (2006) as lcex =
2H - m *
18O - b, where m and b are the slope and intercept of
MWL
, respectively.
Bowen et al. (2019) Isotopes in the water cycle: Regional- to global-Scale patterns and applications. Annual Review of Earth and Planetary Sciences 47 453–479. doi:10.1146/annurev-earth-053018-060220.
Dansgaard (1964) Stable isotopes in precipitation. Tellus 16 436–468. doi:10.1111/j.2153-3490.1964.tb00181.x.
Landwehr & Coplen (2006) Line-conditioned excess: A new method for characterizing stable hydrogen and oxygen isotope ratios in hydrologic systems. In Isotopes in Environmental Studies, International Atomic Energy Agency, 132–135. http://www-pub.iaea.org/MTCD/publications/PDF/CSP_26_web.pdf.
O = runif(10, -15, -2) H = O * 8 + 10 + rnorm(10, 0, 6) d = dex(data.frame(H, O), form = "both") print(d)
O = runif(10, -15, -2) H = O * 8 + 10 + rnorm(10, 0, 6) d = dex(data.frame(H, O), form = "both") print(d)
Parameters for the Global Meteoric Water Line fit to a global precipitation compilation in Bowen, et al. (2019).
data("GMWL")
data("GMWL")
The format is: num [1:6] slope, intercept, average d18O, sum of squares in d18O, root mean square error, number of samples
Bowen et al. (2019) Isotopes in the water cycle: Regional- to global-Scale patterns and applications. Annual Review of Earth and Planetary Sciences 47 453–479. doi:10.1146/annurev-earth-053018-060220.
data(GMWL)
data(GMWL)
Creates objects of type "iso"
iso(H, O = 0, Hsd = 0, Osd = 0, HOc = 0)
iso(H, O = 0, Hsd = 0, Osd = 0, HOc = 0)
H |
numeric or data.frame. If numeric, hydrogen isotope value or vector of hydrogen isotope values. If data.frame, data frame including five numeric fields that contain the H, O, Hsd, Osd, and HOc values (respectively). |
O |
numeric. Oxygen isotope value or vector of oxygen isotope values. |
Hsd |
numeric. 1 standard deviation uncertainty of |
Osd |
numeric. 1 standard deviation uncertainty of |
HOc |
numeric. Covariance of |
For numeric vector arguments, values in Hsd
, Osd
, and HOc
are recycled if their length is shorter than that of H
and O
.
Returns an object of class “iso”, a data.frame containing the provided values.
obs = iso(-30, -5, 2, 0.2, 0.3) str(obs)
obs = iso(-30, -5, 2, 0.2, 0.3) str(obs)
wiDB_ functions provide interface to the public API of the wiDB: https://github.com/SPATIAL-Lab/isoWater/blob/master/Protocol.md. Build, check and submit queries, and receive and unpack responses. Data analysis functions support Bayesian inference of the source and source isotope composition of water samples that may have experienced evaporation. Algorithms adapted from Bowen et al. (2018, doi:10.1007/s00442-018-4192-5).
Maintainer: Gabriel Bowen [email protected] Authors: Gabriel Bowen
Given isotopic compositions of two or more potential sources, generate a posterior sample of source mixtures conditioned on one or more sample values.
mixSource(obs, sources, slope, prior=rep(1,nrow(sources)), shp = 1, edist = "unif", eprior = NULL, ngens = 1e5, ncores = 1)
mixSource(obs, sources, slope, prior=rep(1,nrow(sources)), shp = 1, edist = "unif", eprior = NULL, ngens = 1e5, ncores = 1)
obs |
|
sources |
|
slope |
numeric. Vector of length two specifying prior parameters for the evaporation line slope (mean, standard deviation). |
prior |
numeric. Vector of length equal to the number of sources, giving prior estimates of relative contributions of different sources. |
shp |
numeric. Shape parameter constant used in specifying prior estimates of source contributions (see Details). |
edist |
character. One of |
eprior |
numeric. Vector of length 2 giving prior parameter estimates for the oxygen isotope evaporation effect. For |
ngens |
integer. Number of posterior samples to obtain (per chain). |
ncores |
integer. Number of cores to use for parallel processing. |
The Dirichlet distribution is used to represent the fractional contribution of each source. The prior estimate is a Dirchlet where the shape parameter for source i
is given by prior[i] / min(prior) * shp
.
If ncores
= 1, three chains will be run on a single core. If ncores
> 1, ncores
chains will be run in parallel on ncores
cores.
Returns an object of class “mixSource”, a list containing:
summary |
matrix. Summary table of JAGS MCMC results, including parameter posterior distributions and convergence statistics. |
results |
data.frame. Posterior samples of model parameters.
|
#Prep sources O = runif(3, -15, -2) H = O * 8 + 10 + rnorm(3, 0, 6) sources = iso(H, O, 1, 0.2, 0.17) #Sample data obs = iso(-60, -6, 0.5, 0.1, 0) #Evaporation slope slope = c(5, 0.3) #Run and report...likely not converged! ws = mixSource(obs, sources, slope, ngens = 1e3) ws$summary #A traceplot plot(ws$results$mixture_d18O[1:1000], type = "l") lines(ws$results$mixture_d18O[1001:2000], col = 2) lines(ws$results$mixture_d18O[2001:3000], col = 3)
#Prep sources O = runif(3, -15, -2) H = O * 8 + 10 + rnorm(3, 0, 6) sources = iso(H, O, 1, 0.2, 0.17) #Sample data obs = iso(-60, -6, 0.5, 0.1, 0) #Evaporation slope slope = c(5, 0.3) #Run and report...likely not converged! ws = mixSource(obs, sources, slope, ngens = 1e3) ws$summary #A traceplot plot(ws$results$mixture_d18O[1:1000], type = "l") lines(ws$results$mixture_d18O[1001:2000], col = 2) lines(ws$results$mixture_d18O[2001:3000], col = 3)
Creates objects of type "mwl" containing statistics for a meteoric water line in H and O isotope space.
mwl(HO, plot = TRUE)
mwl(HO, plot = TRUE)
HO |
data.frame. Hydrogen (column 1) and oxygen (column 2) isotope values for 3 or more water samples. |
plot |
logical. Plot the data, MWL, and standard error of prediction? |
mwl
will return an error if fewer than 3 sample values are provided and a warning if fewer than 10 samples are provided or if the correlation coefficient between H and O values is less than 0.7. Sample values should span a broad enough range of isotope values to strongly constrain the MWL.
Model II (reduced major axis) regression is used to accommodate errors on both isotope values.
Returns an object of class “mwl”, a numeric vector containing meteoric water line statistics. See mwlSource
.
O = runif(10, -15, -2) H = O * 8 + 10 + rnorm(10, 0, 6) MWL = mwl(data.frame(H, O)) str(MWL)
O = runif(10, -15, -2) H = O * 8 + 10 + rnorm(10, 0, 6) MWL = mwl(data.frame(H, O)) str(MWL)
Given parameters describing a meteoric water line in H-O isotope space, generate a posterior sample of unevaporated source water values conditioned on one or more sample values.
mwlSource(obs, MWL = NULL, slope, stype = 1, edist = "unif", eprior = NULL, ngens=1e4, ncores = 1)
mwlSource(obs, MWL = NULL, slope, stype = 1, edist = "unif", eprior = NULL, ngens=1e4, ncores = 1)
obs |
|
MWL |
numeric. Vector of length 6 containing parameters describing a meteoric water line (see Details). |
slope |
numeric. Vector of length two specifying prior parameters for the evaporation line slope (mean, standard deviation). |
stype |
integer. Line statistic used to constrain the source prior: 1 = confidence interval, 2 = prediction interval (see Details). |
edist |
character. One of |
eprior |
numeric. Vector of length 2 giving prior parameter estimates for the oxygen isotope evaporation effect. For |
ngens |
integer. Number of posterior samples to obtain (per chain). |
ncores |
integer. Number of cores to use for parallel processing. |
The prior distribution of source values is constrained by MWL
, which contains the parameters: slope, intercept, average d18O, sum of squares in d18O, root mean square error, and number of samples for an empirically-determined meteoric water line. This object can be created from a H and O isotope dataset using the function mwl
. The default value (if MWL = NULL
) reflects the Global Meteoric Water Line estimated from a global precipitation compilation in Bowen, et al. (2019). stype
determines how the source uncertainty about the MWL is calculated; the default (1, confidence interval) is appropriate if the source is best represented as an integrated mixture of the samples defining the MWL, whereas option 2 (prediction interval) is appropriate if the source is best represented as a single sample.
If ncores
= 1, three chains will be run on a single core. If ncores
> 1, ncores
chains will be run in parallel on ncores
cores.
Returns an object of class “mwlSource”, a list containing:
summary |
matrix. Summary table of JAGS MCMC results, including parameter posterior distributions and convergence statistics. |
results |
data.frame. Posterior samples of model parameters.
|
Bowen et al. (2019) Isotopes in the water cycle: Regional- to global-Scale patterns and applications. Annual Review of Earth and Planetary Sciences 47 453–479. doi:10.1146/annurev-earth-053018-060220.
#Prep MWL O = runif(10, -15, -2) H = O * 8 + 10 + rnorm(10, 0, 6) MWL = mwl(data.frame(H, O), plot = FALSE) #Sample data obs = iso(-60, -6, 0.5, 0.1, 0) #Evaporation slope slope = c(5, 0.3) #Run and report...likely not converged! ws = mwlSource(obs, MWL, slope, ngens = 1e3) ws$summary #A traceplot plot(ws$results$source_d18O[1:1000], type = "l") lines(ws$results$source_d18O[1001:2000], col = 2) lines(ws$results$source_d18O[2001:3000], col = 3)
#Prep MWL O = runif(10, -15, -2) H = O * 8 + 10 + rnorm(10, 0, 6) MWL = mwl(data.frame(H, O), plot = FALSE) #Sample data obs = iso(-60, -6, 0.5, 0.1, 0) #Evaporation slope slope = c(5, 0.3) #Run and report...likely not converged! ws = mwlSource(obs, MWL, slope, ngens = 1e3) ws$summary #A traceplot plot(ws$results$source_d18O[1:1000], type = "l") lines(ws$results$source_d18O[1001:2000], col = 2) lines(ws$results$source_d18O[2001:3000], col = 3)
Obtain data from wiDB using a query
wiDB_data(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NULL, minElev = NULL, maxElev = NULL, minDate = NULL, maxDate = NULL, countries = NULL, states = NULL, types = NULL, projects = NULL, fields = NULL, tmpdir = tempdir(), clean = TRUE)
wiDB_data(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NULL, minElev = NULL, maxElev = NULL, minDate = NULL, maxDate = NULL, countries = NULL, states = NULL, types = NULL, projects = NULL, fields = NULL, tmpdir = tempdir(), clean = TRUE)
minLat |
numeric. Minimum latitude for query region, in decimal degrees. South negative. |
maxLat |
numeric. Maximum latitude for query region, in decimal degrees. South negative. |
minLong |
numeric. Minimum longitude for query region, in decimal degrees. West negative. |
maxLong |
numeric. Maximum longitude for query region, in decimal degrees. West negative. |
minElev |
numeric. Minimum elevation for query. Meters. |
maxElev |
numeric. Maximum elevation for query. Meters. |
minDate |
character. Minimum date for query. Format: "YYYY-MM-DD" |
maxDate |
character. Maximum date for query. Format: "YYYY-MM-DD" |
countries |
character. Vector of one or more two-letter country codes for query. |
states |
character. Vector of one or more two-letter state or province codes for query. |
types |
character. Vector of one or more sample types for query. See vocabulary in the wiDB template. |
projects |
character. Vector of one or more project codes for query. |
fields |
character. Vector of one or more data fields to return from database. If omitted, returns all default fields. See here for details. |
tmpdir |
character. Directory path to use for unpacking data object. |
clean |
logical. Remove working files after data object is unpacked? |
One or more arguments must be provided.
named list. See here for details.
data |
dataframe. Data records for isotope samples returned by query. |
projects |
dataframe. Provenance information associated with samples returned by query. |
Note that some data are embargoed or have been shared under a license that prohibits redistribution. In dataframe data values of 9999 indicate that a measurement is available but can't be obtained directly from the wiDB. Project information in projects can be used to contact or visit the primary data source to learn about access to these data. Values of -9999 in data indicate no measurement.
#Download data for US precipitation in the 1990s vals = wiDB_data(minDate = "1990-01-01", maxDate = "2000-01-01", countries = "US", types = "Precipitation") #Download data for US Rivers and streams, requesting a subset of data fields vals = wiDB_data(minDate = "1980-01-01", maxDate = "2000-01-01", countries = "US", types = "River_or_stream", fields = "Site_Name,Latitude,Longitude,d2H")
#Download data for US precipitation in the 1990s vals = wiDB_data(minDate = "1990-01-01", maxDate = "2000-01-01", countries = "US", types = "Precipitation") #Download data for US Rivers and streams, requesting a subset of data fields vals = wiDB_data(minDate = "1980-01-01", maxDate = "2000-01-01", countries = "US", types = "River_or_stream", fields = "Site_Name,Latitude,Longitude,d2H")
Obtain information on wiDB sites using a query
wiDB_sites(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NULL, minElev = NULL, maxElev = NULL, minDate = NULL, maxDate = NULL, countries = NULL, states = NULL, types = NULL, projects = NULL)
wiDB_sites(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NULL, minElev = NULL, maxElev = NULL, minDate = NULL, maxDate = NULL, countries = NULL, states = NULL, types = NULL, projects = NULL)
minLat |
numeric. Minimum latitude for query region, in decimal degrees. South negative. |
maxLat |
numeric. Maximum latitude for query region, in decimal degrees. South negative. |
minLong |
numeric. Minimum longitude for query region, in decimal degrees. West negative. |
maxLong |
numeric. Maximum longitude for query region, in decimal degrees. West negative. |
minElev |
numeric. Minimum elevation for query. Meters. |
maxElev |
numeric. Maximum elevation for query. Meters. |
minDate |
character. Minimum date for query. Format: "YYYY-MM-DD" |
maxDate |
character. Maximum date for query. Format: "YYYY-MM-DD" |
countries |
character. Vector of one or more two-letter country codes for query. |
states |
character. Vector of one or more two-letter state or province codes for query. |
types |
character. Vector of one or more sample types for query. See vocabulary in the wiDB template. |
projects |
character. Vector of one or more project codes for query. |
One or more arguments must be provided.
dataframe. Contains location and summary information for all wiDB sites returned by query. See here for details.
#Find all sites with tap water data since September, 2019 sites = wiDB_sites(minDate = "2019-09-01", types = "Tap")
#Find all sites with tap water data since September, 2019 sites = wiDB_sites(minDate = "2019-09-01", types = "Tap")
Obtain value lists for categorical fields in wiDB
wiDB_values(fields)
wiDB_values(fields)
fields |
character. One or more field names for which to obtain value lists. Limited to: "countries", "states", "types", and "projects". |
named list. Each element is a vector or dataframe containing values for the named field.
#List all projects in the wiDB wiDB_values("projects")
#List all projects in the wiDB wiDB_values("projects")