-
Notifications
You must be signed in to change notification settings - Fork 4
/
PhotoGEA.Rmd
219 lines (179 loc) · 7.15 KB
/
PhotoGEA.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
---
title: "Getting Started With PhotoGEA"
output:
rmarkdown::html_vignette:
toc: true
number_sections: true
vignette: >
%\VignetteIndexEntry{Getting Started With PhotoGEA}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.width = 6,
fig.height = 5,
fig.align = "center"
)
```
# Overview
**PhotoGEA** (short for **photo**synthetic **g**as **e**xchange **a**nalysis) is
an R package that provides a suite of tools for loading, processing, and
analyzing photosynthetic gas exchange data.
# Installing PhotoGEA
The easiest way to install `PhotoGEA` is to type the following from within the R
terminal:
```{r, eval = FALSE}
remotes::install_github('eloch216/PhotoGEA')
```
Note that this method requires the `remotes` package, which can be installed
from within R by typing `install.packages('remotes')`.
# An Example: C~3~ CO~2~ Response Curves
As an example, we will read data from two Licor Li-6800 log files that
contain several A-Ci curves measured from tobacco and soybean plants, fit a
model to each response curve, and then plot some of the results. This is a
basic example that just scratches the surface of what is possible with
`PhotoGEA`.
(**Note:** When loading your own files for analysis, it is not advisable to use
`PhotoGEA_example_file_path` as we have done in the code below. Instead, file
paths can be directly written, or files can be chosen using an interactive
window. See the
[Analyzing C3 A-Ci Curves](analyzing_c3_aci_curves.html#input-files) vignette
for more information.)
## Fitting the Curves
The following code can be used to read the data and fit each curve:
```{r example, eval = FALSE}
# Load required packages
library(PhotoGEA)
library(lattice)
# Define a vector of paths to the files we wish to load; in this case, we are
# loading example files included with the PhotoGEA package
file_paths <- c(
PhotoGEA_example_file_path('c3_aci_1.xlsx'),
PhotoGEA_example_file_path('c3_aci_2.xlsx')
)
# Load the data from each file
licor_exdf_list <- lapply(file_paths, function(fpath) {
read_gasex_file(fpath, 'time')
})
# Get the names of all columns that are present in all of the Licor files
columns_to_keep <- do.call(identify_common_columns, licor_exdf_list)
# Extract just these columns
licor_exdf_list <- lapply(licor_exdf_list, function(x) {
x[ , columns_to_keep, TRUE]
})
# Combine the data from all the files
licor_data <- do.call(rbind, licor_exdf_list)
# Define a new column that uniquely identifies each curve
licor_data[, 'curve_id'] <-
paste(licor_data[, 'species'], '-', licor_data[, 'plot'] )
# Organize the data
licor_data <- organize_response_curve_data(
licor_data,
'curve_id',
c(9, 10, 16),
'CO2_r_sp'
)
# Specify separate mesophyll conductance values for each species
licor_data <- set_variable(
licor_data, 'gmc', 'mol m^(-2) s^(-1) bar^(-1)',
id_column = 'species',
value_table = list(soybean = 0.9, tobacco = 1.1)
)
# Calculate the total pressure
licor_data <- calculate_total_pressure(licor_data)
# Calculate Cc
licor_data <- apply_gm(licor_data)
# Calculate temperature-dependent values of C3 photosynthetic parameters
licor_data <- calculate_arrhenius(licor_data, c3_arrhenius_bernacchi)
# Fit all curves in the data set
aci_results <- consolidate(by(
licor_data,
licor_data[, 'curve_id'],
fit_c3_aci,
Ca_atmospheric = 420
))
```
```{r, echo = FALSE}
timing <- system.time({
<<example>>
})
```
When this document was generated, evaluating this code required the following
amount of time:
```{r, echo = FALSE}
timing
```
The timing results may vary depending on the particular machine used to run the
code. Nevertheless, this is a small time investment for an advanced algorithm
that uses maximum likeliood fitting and derivative-free optimizers for robust
fitting, and calculates confidence intervals to determine which estimated
parameter values are reliable.
This example contains 12 commands, so it certainly isn't short; however, a close
look reveals that much of the commands are general and would apply to _any_ set
of C~3~ response curves. In fact, only a few parts would need to be modified,
such as the list of files to read, the curve identifier, and the value of
mesophyll conductance. While using `PhotoGEA`, you are encouraged to copy this
example and any others to use as the base of your own scripts; work smarter, not
harder!
## Viewing the Results
Having fit the response curves, it is also possible to view the fits and the
extracted parameters. For example, we can plot the measured values of net
assimilation (black circles), the fitted values of net assimilation (`An`), and
each of the limiting assimilation rates calculated during the fitting procedure:
the Rubisco limited rate (`Ac`), the RuBP regeneration limited rate (`Aj`), and
the triose phosphate utilization limited rate (`Ap`).
```{r}
plot_c3_aci_fit(aci_results, 'curve_id', 'Ci', ylim = c(-10, 80))
```
Another way to check the quality of the fits is to plot the residuals, which
should be randomly distributed:
```{r}
xyplot(
A_residuals ~ Ci | curve_id,
data = aci_results$fits$main_data,
type = 'b',
pch = 16,
grid = TRUE,
xlab = paste0('Intercellular CO2 concentration (', aci_results$fits$units$Ci, ')'),
ylab = paste0('Assimilation rate residual (measured - fitted)\n(', aci_results$fits$units$A, ')'),
)
```
It is also possible to plot one or more of the fitting parameters averaged
across species in a bar chart with error bars; here we plot values of `Vcmax` at
25 degrees C.
```{r}
barchart_with_errorbars(
aci_results$parameters[, 'Vcmax_at_25'],
aci_results$parameters[, 'species'],
xlab = 'Species',
ylab = paste0('Vcmax at 25 degrees C (', aci_results$parameters$units$Vcmax_at_25, ')'),
ylim = c(0, 200)
)
```
# Learning More
The `PhotoGEA` package includes extensive documentation, and more articles are
being added all the time:
- [Developing a Data Analysis Pipeline](developing_a_data_analysis_pipeline.html):
Discusses how `PhotoGEA` provides functionality for all parts of a data
analysis pipeline, including loading and validating the data -- and how it can
help save your time and improve the reproducibility of your data analysis!
- [Working With Extended Data Frames](working_with_extended_data_frames.html):
Discusses how to work with extended data frames, which are a critical part of
`PhotoGEA`.
- Analysis case studies:
- [Analyzing C3 A-Ci Curves](analyzing_c3_aci_curves.html) (This example is
more detailed than the analysis demonstrated here.)
- [Analyzing C4 A-Ci Curves](analyzing_c4_aci_curves.html)
- [Analyzing Ball-Berry Data](analyzing_ball_berry_data.html)
- [Analyzing TDL Data](analyzing_tdl_data.html)
- [Analyzing Mesophyll Conductance Data](analyzing_gm_data.html)
- More advanced topics:
- [Creating Your Own Processing Tools](creating_your_own_processing_tools.html):
Discusses how to create functions compatible with `PhotoGEA` that apply new
types of processing.
- [Combining PhotoGEA With Other Packages](combining_with_other_packages.html):
Discusses how to create wrappers for functions from other packages to extend
the processing capabilities of `PhotoGEA`.