Fitting a model to concentration data and estimating the slope
flux_fitting.Rd
fits gas concentration over time data with a model (exponential, quadratic or linear) and provides the slope later used to calculate gas fluxes with flux_calc
Usage
flux_fitting(
conc_df,
start_cut = 0,
end_cut = 0,
start_col = "f_start",
end_col = "f_end",
datetime_col = "f_datetime",
conc_col = "f_conc",
fluxid_col = "f_fluxID",
t_window = 20,
cz_window = 15,
b_window = 10,
a_window = 10,
roll_width = 15,
t_zero = 0,
fit_type
)
Arguments
- conc_df
dataframe of gas concentration over time
- 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)
- start_col
column with datetime when the measurement started
- end_col
column with datetime when the measurement ended
- datetime_col
column with datetime of each concentration measurement
- conc_col
column with gas concentration data
- fluxid_col
column with ID of each flux
- t_window
enlarge focus window before and after tmin and tmax (exponential fit)
- 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 fit)
- fit_type
exponential, quadratic or linear. Exponential is using the exponential model from Zhao et al (2018)
Value
a dataframe with the slope at t zero, and parameters of a model of gas concentration over time
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
Examples
data(co2_conc)
flux_fitting(co2_conc, fit_type = "exp")
#> Cutting measurements...
#> Estimating starting parameters for optimization...
#> Optimizing fitting parameters...
#> Calculating fits and slopes...
#> Done.
#> Warning:
#> fluxID 5 : slope was estimated on 205 points out of 210 seconds
#> fluxID 6 : slope was estimated on 206 points out of 210 seconds
#> # A tibble: 1,251 × 29
#> f_datetime temp_air temp_soil f_conc PAR turfID type
#> <dttm> <dbl> <dbl> <dbl> <dbl> <fct> <fct>
#> 1 2022-07-28 23:43:35 NA NA 447. NA 156 AN2C 156 ER
#> 2 2022-07-28 23:43:36 7.22 10.9 447. 1.68 156 AN2C 156 ER
#> 3 2022-07-28 23:43:37 NA NA 448. NA 156 AN2C 156 ER
#> 4 2022-07-28 23:43:38 NA NA 449. NA 156 AN2C 156 ER
#> 5 2022-07-28 23:43:39 NA NA 449. NA 156 AN2C 156 ER
#> 6 2022-07-28 23:43:40 NA NA 450. NA 156 AN2C 156 ER
#> 7 2022-07-28 23:43:41 NA NA 451. NA 156 AN2C 156 ER
#> 8 2022-07-28 23:43:42 NA NA 451. NA 156 AN2C 156 ER
#> 9 2022-07-28 23:43:43 NA NA 453. NA 156 AN2C 156 ER
#> 10 2022-07-28 23:43:44 NA NA 453. NA 156 AN2C 156 ER
#> # ℹ 1,241 more rows
#> # ℹ 22 more variables: f_start <dttm>, f_end <dttm>, f_fluxID <fct>,
#> # n_conc <int>, ratio <dbl>, flag <chr>, f_time <dbl>, f_cut <fct>,
#> # Cm_est <dbl>, a_est <dbl>, b_est <dbl>, tz_est <dbl>, f_Cz <dbl>,
#> # time_diff <dbl>, f_Cm <dbl>, f_a <dbl>, f_b <dbl>, f_tz <dbl>,
#> # f_slope <dbl>, f_fit <dbl>, f_fit_slope <dbl>, f_start_z <dttm>
flux_fitting(co2_conc, fit_type = "quadratic", t_zero = 10, end_cut = 30)
#> # A tibble: 1,251 × 24
#> f_datetime temp_air temp_soil f_conc PAR turfID type
#> <dttm> <dbl> <dbl> <dbl> <dbl> <fct> <fct>
#> 1 2022-07-28 23:43:35 NA NA 447. NA 156 AN2C 156 ER
#> 2 2022-07-28 23:43:36 7.22 10.9 447. 1.68 156 AN2C 156 ER
#> 3 2022-07-28 23:43:37 NA NA 448. NA 156 AN2C 156 ER
#> 4 2022-07-28 23:43:38 NA NA 449. NA 156 AN2C 156 ER
#> 5 2022-07-28 23:43:39 NA NA 449. NA 156 AN2C 156 ER
#> 6 2022-07-28 23:43:40 NA NA 450. NA 156 AN2C 156 ER
#> 7 2022-07-28 23:43:41 NA NA 451. NA 156 AN2C 156 ER
#> 8 2022-07-28 23:43:42 NA NA 451. NA 156 AN2C 156 ER
#> 9 2022-07-28 23:43:43 NA NA 453. NA 156 AN2C 156 ER
#> 10 2022-07-28 23:43:44 NA NA 453. NA 156 AN2C 156 ER
#> # ℹ 1,241 more rows
#> # ℹ 17 more variables: f_start <dttm>, f_end <dttm>, f_fluxID <fct>,
#> # n_conc <int>, ratio <dbl>, flag <chr>, f_time <dbl>, f_cut <fct>,
#> # f_rsquared <dbl>, f_adj_rsquared <dbl>, f_pvalue <dbl>, f_intercept <dbl>,
#> # f_param1 <dbl>, f_param2 <dbl>, f_slope <dbl>, f_fit <dbl>,
#> # f_fit_slope <dbl>