aelab

Installation

Install aelab package from Github. devtools need to be install though install.packges("devtools").

library(aelab)

Load other required packages. Install through install.packages("package_name") if not already installed.

library(readxl)
library(tibble)
library(lubridate)
library(stats)
library(dplyr)
library(openxlsx)

Load and process data from LI-COR

Unnecessary rows and columns are removed. NaN values of GHG data are removed.

ghg_data_path <- system.file("extdata", "ch4.xlsx", package = "aelab", mustWork = T)
ch4 <- tidy_licor(ghg_data_path, "ch4")
ch4[c(1:5), ]
##         DATE     TIME       CO2      CH4           date_time
## 1 2023/03/11 07:31:59  799.9406 2999.952 2023-03-11 07:31:59
## 2 2023/03/11 07:32:00  770.1415 2995.596 2023-03-11 07:32:00
## 3 2023/03/11 07:32:01  771.6826 2993.581 2023-03-11 07:32:01
## 4 2023/03/11 07:32:02 1304.2191 2940.007 2023-03-11 07:32:02
## 5 2023/03/11 07:32:03 1974.0665 2885.650 2023-03-11 07:32:03

Convert LI-COR time

Convert the time in LI-COR to match the time in real life (if there are any differences).

ch4 <- convert_time(ch4, min = -15, sec = 30)
ch4[c(1:5), ]
##         DATE     TIME       CO2      CH4           date_time
## 1 2023/03/11 07:31:59  799.9406 2999.952 2023-03-11 07:31:59
## 2 2023/03/11 07:32:00  770.1415 2995.596 2023-03-11 07:32:00
## 3 2023/03/11 07:32:01  771.6826 2993.581 2023-03-11 07:32:01
## 4 2023/03/11 07:32:02 1304.2191 2940.007 2023-03-11 07:32:02
## 5 2023/03/11 07:32:03 1974.0665 2885.650 2023-03-11 07:32:03
##         real_datetime
## 1 2023-03-11 07:17:29
## 2 2023-03-11 07:17:30
## 3 2023-03-11 07:17:31
## 4 2023-03-11 07:17:32
## 5 2023-03-11 07:17:33

Calculate the slope based on the measurement start time

Method 1: Load from excel

Type the date and time of GHG flux measurement (start time) in excel, then load the file into R.

ref_data_path <- system.file("extdata", "reference.xlsx", package = "aelab", mustWork = T)
ref <- read_excel(ref_data_path)
ref
## # A tibble: 3 × 3
##   real_date           real_time           date_time          
##   <dttm>              <dttm>              <dttm>             
## 1 2023-03-11 00:00:00 1899-12-31 07:32:00 2023-03-11 07:32:00
## 2 2023-03-11 00:00:00 1899-12-31 08:32:00 2023-03-11 08:32:00
## 3 2023-03-11 00:00:00 1899-12-31 09:32:00 2023-03-11 09:32:00

Calculation of the slope of methane concentration over time using the date_time value in the ref data. In the results, start_time and end_time are the time range of the data used to perform regression. slope is the slope and R-square is the R^2 of the regression. reference_time is the start time of the measurement from the input.

calculate_regression(ch4, ghg = "CH4", reference_time = ref$date_time)
## # A tibble: 3 × 5
##   start_time          end_time              slope r_square reference_time     
##   <chr>               <chr>                 <dbl>    <dbl> <dttm>             
## 1 2023/03/11 07:33:42 2023/03/11 07:38:41 -0.0406    0.671 2023-03-11 07:32:00
## 2 2023/03/11 08:32:00 2023/03/11 08:36:59 -0.207     0.671 2023-03-11 08:32:00
## 3 2023/03/11 09:34:01 2023/03/11 09:39:00  0.104     0.444 2023-03-11 09:32:00

The default duration of measurement is set to 7 minutes, and the number of rows selected to perform regression is 300. You can modify these values if desired using the input variables duration_minutes and num_rows according to your needs.

calculate_regression(ch4, ghg = "CH4", reference_time = ref$date_time,
                     duration_minutes = 5, num_rows = 300)
## # A tibble: 3 × 5
##   start_time          end_time               slope r_square reference_time     
##   <chr>               <chr>                  <dbl>    <dbl> <dttm>             
## 1 2023/03/11 07:32:00 2023/03/11 07:36:59 -0.0412   0.326   2023-03-11 07:32:00
## 2 2023/03/11 08:32:00 2023/03/11 08:36:59 -0.207    0.671   2023-03-11 08:32:00
## 3 2023/03/11 09:32:00 2023/03/11 09:36:59 -0.00523  0.00546 2023-03-11 09:32:00

Method 2: Type from R

The start time of measurement can also be input directly into the function. Note that as.POSIXct() is necessary.

calculate_regression(ch4, ghg = "CH4", reference_time = as.POSIXct("2023-03-11 07:32:00", tz = "UTC"))
## # A tibble: 1 × 5
##   start_time          end_time              slope r_square reference_time     
##   <chr>               <chr>                 <dbl>    <dbl> <dttm>             
## 1 2023/03/11 07:33:42 2023/03/11 07:38:41 -0.0406    0.671 2023-03-11 07:32:00