A function for the correction of offsets in the whole gas-dataset. The basic assumption is that atmospheric values of these gases are fairly constant over long periods of time. If there are offsets in the atmospheric concentrations, then these are probably introduced via calibration differences or similar factors within the gas analysis. The time series is smoothed by subdividing the whole dataset per gas into homogeneous subsections (section). Mean values of the atmospheric concentrations are then calculated, or a linear model is fit against time. A correction factor is then calculated by dividing a target atmospheric value (gases_std) by the mean or the values predicted by the linear model. x_ppm values are then multiplied by that factor.
Arguments
- df
(dataframe) The gasdata-dataframe.
- corr_map
(dataframe) A dataframe of four columns ("gas","SAMPLE_NO","section","mode") mapping each pair of
gases
and sample-idSAMPLE_NO
of thegasdata
data.frame to a subsection-number (section). The column "mode" determines, whether the correction is performed using a linear regression, to account for drifts in time ("lin") or using the mean ("const"). This dataframe can be created using the helper-function offset_subsetting()- gases
(vector, character) A vector containing the names of the gases to be corrected. Spelling must match gasdata$gas.
- gases_std
(vector, numeric) A numeric vector with standard concentrations of the gases in the atmosphere. Unit is fraction of Volume (e.g. N2 = 0.78). Must match the order of
gases
.- depth_cal
(character) A character (-vector) containing the value(s) of
depth_cat
of the gasdata dataframe to be used for the calculation of the correction factor. Should be the depth_cat of the air concentration.
See also
Other gasdata:
balance_correction()
,
offset_subsetting()
Examples
{
data("gasdata")
library(dplyr)
gasdata <- gasdata %>%
mutate(depth_cat = ifelse(depth>0,"HU","MIN"),
SAMPLE_NO = row_number())
cmap <-
offset_subsetting(gasdata,
start = "2021-01-01",
end = "2022-01-01",
mode = "const")
offset_correction(gasdata,
corr_map = cmap,
gases = "CO2",
gases_std = 400e-6,
depth_cal = "HU")
}
#> Joining with `by = join_by(Date, SAMPLE_NO)`
#> Joining with `by = join_by(gas)`
#> Adding missing grouping variables: `section`
#> Joining with `by = join_by(Date, gas)`
#> # A tibble: 624 × 9
#> # Groups: gas, section [1]
#> section Date gas corr_fac site depth x_ppm depth_cat SAMPLE_NO
#> <int> <date> <chr> <dbl> <chr> <dbl> <dbl> <chr> <int>
#> 1 1 2021-01-01 CO2 0.952 site_a 5 403. HU 1
#> 2 1 2021-01-01 CO2 0.952 site_a 0 526. MIN 2
#> 3 1 2021-01-01 CO2 0.952 site_a 0 529. MIN 3
#> 4 1 2021-01-01 CO2 0.952 site_a 0 530. MIN 4
#> 5 1 2021-01-01 CO2 0.952 site_a -10 682. MIN 5
#> 6 1 2021-01-01 CO2 0.952 site_a -10 679. MIN 6
#> 7 1 2021-01-01 CO2 0.952 site_a -10 689. MIN 7
#> 8 1 2021-01-01 CO2 0.952 site_a -20 759. MIN 8
#> 9 1 2021-01-01 CO2 0.952 site_a -20 779. MIN 9
#> 10 1 2021-01-01 CO2 0.952 site_a -20 759. MIN 10
#> # ℹ 614 more rows