View source: R/ms_conversions.R
ms_conversions | R Documentation |
MacroSheds concentration data are represented in either mass, moles, or equivalents per liter (mg/L, mol/L, or uEq/L, respectively, but note that one variable, "ANC" is represented by default in Eq/L). Use this function to convert among these units. You may also use this function to convert SI prefixes, e.g. mg/L to kg/L, or to convert between molecular and atomic representations for some elements and compounds. For example, nitrate (NO3) can be converted to nitrate-N and vice versa.
ms_conversions(
d,
convert_units_from = "mg/l",
convert_units_to,
convert_molecules
)
d |
|
convert_units_from |
(named) character vector.
If named, names are variable_codes and values are the units of those variables (see |
convert_units_to |
(named) character vector. If named, names are
variable_codes and values are the units those variables should be converted to (see |
convert_molecules |
character vector. Molecules that will be converted according to the atomic mass of their main constituent. For example, this can be used to convert NO3-N to NO3, or NO3 to NO3-N. See details. |
In MacroSheds, concentrations of the following molecules are represented according to the atomic mass of their primary constituent atom: NO3, NO2, NO3_NO2 (variable code for NO3 + NO2), NH4, NH3, NH3_NH4, SO4, SiO2, SiO3, PO4, orthophosphate. For example, if MacroSheds retrieved SiO2 concentration in mg/L from some domain, we converted it to mg/L SiO2-Si (coded as "SiO2_Si"). You could use this function to convert it back to SiO2 by setting convert_molecules = 'SiO2_Si'. You could then convert it to SiO2-Si again by setting convert_molecules = 'SiO2. See examples for more.
Default units for all variables can be seen via ms_load_variables()
.
MacroSheds format (only var and val columns required as inputs to this function):
header value | column_definition |
date | Date in YYYY-mm-dd |
site_code | A unique identifier for each MacroSheds site, identical to primary source site code where possible. See ms_load_sites() . |
grab_sample | Boolean integer indicating whether the observation was obtained via grab sample or installed sensor. 1 = TRUE (grab sample), 0 = FALSE (installed sensor). |
var | Variable code. See ms_load_variables() . |
val | Data value. See ms_load_variables() for units. |
ms_status | Boolean integer. 0 = clean value. 1 = questionable value. See "Technical Validation" section of the MacroSheds data paper for details. |
ms_interp | Boolean integer. 0 = measured or imputed by primary source. 1 = interpolated by MacroSheds. See "Temporal Imputation and Aggregation" section of the MacroSheds data paper for details. |
val_err | The combined standard uncertainty associated with the corresponding data point, if estimable. See "Detection Limits and Propagation of Uncertainty" section of the MacroSheds data paper for details. |
returns a tibble
in MacroSheds format, containing concentration data converted to new units.
Spencer Rhea
Mike Vlah, vlahm13@gmail.com
Wes Slaughter
ms_load_product()
, ms_load_variables()
ms_root = 'data/macrosheds'
ms_download_core_data(macrosheds_root = ms_root,
domains = 'hbef')
d <- ms_load_product(macrosheds_root = ms_root,
prodname = 'stream_chemistry',
domains = 'hbef',
filter_vars = c('NO3_N', 'Na', 'Mg', 'SO4_S'))
# Convert all variables from mg/L to ug/L (micrograms per liter)
converted_data <- ms_conversions(d = d,
convert_units_from = 'mg/l',
convert_units_to = 'ug/l')
# Convert mg/L NO3-N to mg/L NO3
converted_data <- ms_conversions(d = d,
convert_units_from = 'mg/l',
convert_units_to = 'mg/l',
convert_molecules = 'NO3_N')
# Convert from mg/L to mmol/L
converted_data <- ms_conversions(d = d,
convert_units_from = 'mg/l',
convert_units_to = 'mmol/l')
# Convert from mg/L to mEq/L
converted_data <- ms_conversions(d = d,
convert_units_from = 'mg/l',
convert_units_to = 'meq/l')
# Convert variables to different units
converted_data <- ms_conversions(d = d,
convert_units_from = c('NO3_N' = 'mg/l',
'Na' = 'mg/l',
'Mg' = 'mg/l',
'SO4_S' = 'mg/l'),
convert_units_to = c('NO3_N' = 'meq/l',
'Na' = 'ug/l',
'Mg' = 'umol/l',
'SO4_S' = 'g/l'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.