-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
97 lines (72 loc) · 3.59 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# FluxGapsR
<!-- badges: start -->
<!-- badges: end -->
**Updates**
Since the dependent package `spectral.methods` is not available from CRAN now, and also has problems with the code from Github, the SSA method is not supported in this package anymore.
-------------
This is a package including four gap-filling methods for soil respiration data investigated in the study of Zhao et al. (2020, see the citation at the end). The four methods are referred to as non-linear least squares (NLS), artificial neural networks (ANN), singular spectrum analysis (SSA) and expectation-maximization (EM).
**Data preparation**
1. The dataset with missing values to be gap-filled needs to be imported into R as a data frame with the missing values replaced by `NA`.
2. In addition to the flux data to be gap-filled, a column with soil temperature data (in the same data frame) is needed for gap-filling with *NLS*.
3. For *ANN*, up to three independent variables can be included (e.g. soil/air temperature, soil moisture) as inputs in the same data frame.
4. *SSA* requires only the flux data to be filled.
5. For *EM*, 1-3 reference flux datasets measured at the same time as the target flux series are required as inputs, which could be either in the same data frame or separate ones.
6. Note that the date and time are required for *SSA* and *EM* as one column in each data frame in the format of either "ymd_hms", "mdy_hms" or "dmy_hms".
**Package installation**
First, make sure the package `remotes` is installed in R. If not,
install the package by:
``` r
install.packages("remotes")
```
Then, install the `FluxGapsR` package in R by:
``` r
remotes::install_github("junbinzhao/FluxGapsR")
```
The functioning of the package is based on other R packages:
`dplyr`,`lubridate`,`spectral.methods`,`minpack.lm`,`mtsdi`,`neuralnet` and they
must be installed before using the functions in the `FluxGapsR` package.
*Note: in case the installation fails in Rstudio, try to install the package in the original R program and then load the package in Rstudio.*
**Examples**
``` {r}
library(FluxGapsR)
# load a fraction of example data for visualizing purpose
df <- read.csv(file = system.file("extdata", "Soil_resp_example.csv", package = "FluxGapsR"),
header = T)[4000:8000,]
# load the example reference
df_ref <- read.csv(file = system.file("extdata", "Soil_resp_ref_example.csv", package = "FluxGapsR"),
header = T)[4000:8000,]
# use NLS
df_nls <- Gapfill_nls(data = df)
# use ANN
df_ann <- Gapfill_ann(data = df,var1 = "Ts",var2 = "Ta",var3 = "Moist")
# use SSA
# df_ssa <- Gapfill_ssa(data = df)
# use EM
df_em <- Gapfill_em(data = df,ref1 = df_ref)
# plot the results
plot(df_nls$filled,col="red",type = "l",
ylab=expression("Soil respiration rate ("*mu*"mol CO"[2]*" m"^-2*" s"^-1*")"))
lines(df_ann$filled,col="blue",lty="dashed")
# lines(df_ssa$filled,col="green",lty="dotted")
lines(df_em$filled,col="grey")
lines(df_nls$Flux)
legend(3000,7,
legend=c("NLS","ANN","SSA","EM"),
col=c("red","blue","green","grey"),
lty=c("solid","dashed","dotted","solid"),
box.lty=0)
```
**Please cite the package as:**
Junbin Zhao, Holger Lange and Helge Meissner. Gap-filling continuously-measured soil respiration data: a highlight of the time-series-based methods. Agricultural and Forest Meteorology, 2020, doi: 10.1016/j.agrformet.2020.107912