Wrapper function for the Fluxible workflow. We recommand using the step-by-step workflow for more control over the process.
Usage
stupeflux(
raw_conc,
field_record,
datetime_col,
start_col,
end_col,
conc_col,
startcrop,
measurement_length,
fit_type,
temp_air_col,
chamber_volume,
atm_pressure,
plot_area,
conc_unit,
flux_unit,
fixed_length = TRUE,
cols_keep = c(),
cols_ave = c(),
cols_sum = c(),
cols_med = c(),
tube_volume,
ratio_threshold = 0.5,
time_diff = 0,
start_cut = 0,
end_cut = 0,
cz_window = 15,
b_window = 10,
a_window = 10,
roll_width = 15,
t_zero = 0,
force_discard = c(),
force_ok = c(),
force_zero = c(),
ambient_conc = 421,
error = 100,
pvalue_threshold = 0.3,
rsquared_threshold = 0.7,
rmse_threshold = 25,
cor_threshold = 0.5,
b_threshold = 1,
temp_air_unit = "celsius",
cut = TRUE,
slope_correction = TRUE
)
Arguments
- raw_conc
dataframe of CO2 concentration measured continuously. Has to contain at least a datetime column in ymd_hms format and a gas concentration column as double.
- field_record
dataframe recording which measurement happened when. Has to contain at least a column containing the start of each measurement, and any other column identifying the measurements.
- datetime_col
datetime column in raw_conc (dmy_hms format)
- start_col
start column in field_record (dmy_hms format)
- end_col
end columne in field_record (
ymd_hms
format)- conc_col
concentration column in raw_conc
- startcrop
how many seconds should be discarded at the beginning of the measurement
- measurement_length
length of the measurement (in seconds) from the start specified in the field_record
- fit_type
exp_zhao18
,exp_tz
,quadratic
orlinear.
exp_zhao18
is using the exponential modelC(t) = C_m + a (t - t_z) + (C_z - C_m) exp(-b (t - t_z))
from Zhao et al (2018).expt_tz
is a modified version which allows the user to fixt_zero
:C(t) = C_m + a * t + (C_z - C_m) exp(-b * t)
.- temp_air_col
column containing the air temperature used to calculate fluxes. Will be averaged with NA removed.
- chamber_volume
volume of the flux chamber in L, can also be a column in case it is a variable
- atm_pressure
atmospheric pressure, can be a constant (numerical) or a variable (column name)
- plot_area
area of the plot in m^2, can also be a column in case it is a variable
- conc_unit
unit in which the concentration of gas was measured
ppm
orppb
- flux_unit
unit in which the calculated flux will be
mmol
outputs fluxes in mmol * m^(-2)*h^(-1);micromol
outputs fluxes in micromol * m^(-2)*h^(-1)- fixed_length
if
TRUE
(default), themeasurement_length
is used to create the end column. IfFALSE
,end_col
has to be provided.- cols_keep
columns to keep from the input to the output. Those columns need to have unique values for each flux, as distinct() is applied.
- cols_ave
columns with values that should be averaged for each flux in the output. Note that NA are removed in mean calculation.
- cols_sum
columns with values for which is sum is provided for each flux in the output. Note that NA are removed in sum calculation.
- cols_med
columns with values for which is median is provided for each flux in the output. Note that NA are removed in median calculation.
- tube_volume
volume of the tubing in L, can also be a column in case it is a variable
- ratio_threshold
ratio of gas concentration data points over length of measurement (in seconds) below which the measurement will be considered as not having enough data points to be considered for calculations
- time_diff
time difference (in seconds) between the two datasets. Will be added to the datetime column of the raw_conc dataset. For situations where the time was not synchronized correctly.
- start_cut
time to discard at the start of the measurements (in seconds)
- end_cut
time to discard at the end of the measurements (in seconds)
- cz_window
window used to calculate Cz, at the beginning of cut window (exponential fit)
- b_window
window to estimate b. It is an interval after tz where it is assumed that the model fits the data perfectly (exponential fit)
- a_window
window at the end of the flux to estimate a (exponential fit)
- roll_width
width of the rolling mean for CO2 when looking for tz, ideally same as cz_window (exponential fit)
- t_zero
time at which the slope should be calculated (for
quadratic
andexp_tz
fits)- force_discard
vector of fluxIDs that should be discarded by the user's decision
- force_ok
vector of fluxIDs for which the user wants to keep the calculated slope despite a bad quality flag
- force_zero
vector of fluxIDs that should be replaced by zero by the user's decision
- ambient_conc
ambient gas concentration in ppm at the site of measurement (used to detect measurement that started with a polluted setup)
- error
error of the setup, defines a window outside of which the starting values indicate a polluted setup
- pvalue_threshold
threshold of p-value below which the change of gas concentration over time is considered not significant (linear and quadratic fit)
- rsquared_threshold
threshold of r squared value below which the linear model is considered an unsatisfactory fit (linear and quadratic fit)
- rmse_threshold
threshold for the RMSE of each flux above which the fit is considered unsatisfactory (exponential fit)
- cor_threshold
threshold for the correlation coefficient of gas concentration with time below which the correlation is considered not significant (exponential fit)
- b_threshold
threshold for the b parameter. Defines a window with its opposite inside which the fit is considered good enough (exponential fit)
- temp_air_unit
units in which air temperature was measured. Has to be either
celsius
(default),fahrenheit
orkelvin.
- cut
if 'TRUE' (default), the measurements will be cut according to 'f_cut' before calculating fluxes. This has no influence on the flux itself since the slope is provided from flux_fitting, but it will influence the values of the columns in
cols_ave
.- slope_correction
logical. If
TRUE
, the flux will be calculated with the slope corrected according to the recommandations of the quality flags.
Value
a dataframe containing flux IDs, datetime of measurements' starts,
fluxes in mmol*m^(-2)h^(-1) or micromolm^(-2)*h^(-1) (f_flux
) according
to flux_unit
, temperature average for each flux in Kelvin (f_temp_ave
),
the total volume of the setup for each measurement (f_volume_setup
),
the model used in flux_fitting,
any column specified in cols_keep
, any column specified in cols_ave
with
their value averaged over the measurement after cuts and discarding NA.
References
Zhao, P., Hammerle, A., Zeeman, M., Wohlfahrt, G., 2018.
On the calculation of daytime CO2 fluxes measured by automated closed
transparent chambers. Agricultural and Forest Meteorology 263, 267–275.
https://doi.org/10.1016/j.agrformet.2018.08.022
exponential
is equal to exp_zhao18
, for backwards compatibility
Examples
data(co2_df_short)
data(record_short)
stupeflux(
raw_conc = co2_df_short,
field_record = record_short,
datetime_col = datetime,
start_col = start,
conc_col = conc,
startcrop = 10,
measurement_length = 180,
fit_type = "exp_zhao18",
temp_air_col = temp_air,
conc_unit = "ppm",
flux_unit = "mmol",
chamber_volume = 24.5,
tube_volume = 0.075,
atm_pressure = 1,
plot_area = 0.0625
)
#> Cutting measurements...
#> Estimating starting parameters for optimization...
#> Optimizing fitting parameters...
#> Calculating fits and slopes...
#> Done.
#>
#> Total number of measurements: 6
#>
#> ok 5 83 %
#> zero 1 17 %
#> discard 0 0 %
#> force_discard 0 0 %
#> start_error 0 0 %
#> no_data 0 0 %
#> force_ok 0 0 %
#> force_zero 0 0 %
#> force_lm 0 0 %
#> Cutting data according to 'keep_arg'...
#> Averaging air temperature for each flux...
#> Calculating fluxes...
#> R constant set to 0.082057
#> Concentration was measured in ppm
#> Fluxes are in mmol/m2/h
#> # A tibble: 6 × 7
#> f_fluxid f_slope_corr f_temp_air_ave datetime f_volume_setup f_flux
#> <fct> <dbl> <dbl> <dttm> <dbl> <dbl>
#> 1 1 0.785 7.28 2022-07-28 23:43:35 24.6 48.3
#> 2 2 0.503 7.37 2022-07-28 23:47:22 24.6 30.9
#> 3 3 0.344 7.45 2022-07-28 23:52:10 24.6 21.1
#> 4 4 0.693 7.77 2022-07-28 23:59:32 24.6 42.5
#> 5 5 0 7.69 2022-07-29 00:03:10 24.6 0
#> 6 6 0.433 7.74 2022-07-29 00:06:35 24.6 26.6
#> # ℹ 1 more variable: f_model <chr>