### Install photosynthesis from GitHub Source: https://cran.r-project.org/web/packages/photosynthesis/readme/README.html Install the photosynthesis package from GitHub using the 'remotes' package. Ensure 'remotes' is installed first. ```r install.packages("remotes") remotes::install_github("cdmuir/photosynthesis") ``` -------------------------------- ### Install photosynthesis from CRAN Source: https://cran.r-project.org/web/packages/photosynthesis/readme/README.html Use this command to install the photosynthesis package from the Comprehensive R Archive Network (CRAN). ```r install.packages("photosynthesis") ``` -------------------------------- ### Minimum Worked Example with Default Parameters Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/photosynthesis-introduction.html Demonstrates how to simulate photosynthetic rate using default parameter settings with the `make_*()` functions and `photo()` from the photosynthesis package. Ensure 'dplyr', 'magrittr', and 'photosynthesis' libraries are loaded. ```R library(dplyr) library(magrittr) library(photosynthesis) # Leaving the make_* functions empty will automatically default to defaults # parameters. bake_par = make_bakepar() # temperature response parameters constants = make_constants(use_tealeaves = FALSE) # physical constants leaf_par = make_leafpar(use_tealeaves = FALSE) # leaf parameters enviro_par = make_enviropar(use_tealeaves = FALSE) # environmental parameters photo(leaf_par, enviro_par, bake_par, constants, quiet = TRUE, use_tealeaves = FALSE) #> C_chl value convergence g_tc #> 1 258.1218 [umol/mol] -1.363227e-06 0 0.1726157 [mol/m^2/s] #> A J_max J_max25 K_C #> 1 27.94273 [umol/m^2/s] 200 [umol/m^2/s] 200 [umol/m^2/s] 268.3 [umol/mol] #> K_C25 K_O K_O25 R_d #> 1 268.3 [umol/mol] 165084.2 [umol/mol] 165084.2 [umol/mol] 2 [umol/m^2/s] #> R_d25 T_leaf V_cmax V_cmax25 V_tpu #> 1 2 [umol/m^2/s] 298.15 [K] 150 [umol/m^2/s] 150 [umol/m^2/s] 200 [umol/m^2/s] #> V_tpu25 g_mc g_mc25 g_sc #> 1 200 [umol/m^2/s] 0.4 [mol/m^2/s] 0.4 [mol/m^2/s] 0.4 [mol/m^2/s] #> g_uc gamma_star gamma_star25 k_mc k_sc k_uc #> 1 0.01 [mol/m^2/s] 37.9258 [umol/mol] 37.9258 [umol/mol] 1 [1] 1 [1] 1 [1] #> leafsize phi_J theta_J C_air O P #> 1 0.1 [m] 0.331 [1] 0.825 [1] 420 [umol/mol] 0.21 [mol/mol] 101.3246 [kPa] #> PPFD RH wind Ds_Jmax Ds_gmc #> 1 1500 [umol/m^2/s] 0.5 [1] 2 [m/s] 388.04 [J/K/mol] 487.29 [J/K/mol] #> Ea_Jmax Ea_KC Ea_KO Ea_Rd #> 1 56095.18 [J/mol] 80989.78 [J/mol] 23719.97 [J/mol] 40446.75 [J/mol] #> Ea_Vcmax Ea_Vtpu Ea_gammastar Ea_gmc #> 1 52245.78 [J/mol] 52245.78 [J/mol] 24459.97 [J/mol] 68901.56 [J/mol] #> Ed_Jmax Ed_gmc D_c0 D_h0 #> 1 121244.8 [J/mol] 148788.6 [J/mol] 1.29e-05 [m^2/s] 1.9e-05 [m^2/s] #> D_m0 D_w0 G R eT #> 1 1.33e-05 [m^2/s] 2.12e-05 [m^2/s] 9.8 [m/s^2] 8.31446 [J/K/mol] 1.75 [1] #> epsilon sigma C_i #> 1 0.622 [1] 5.67e-08 [W/K^4/m^2] 350.1432 [umol/mol] ``` -------------------------------- ### Load photosynthesis package Source: https://cran.r-project.org/web/packages/photosynthesis/readme/README.html Load the installed photosynthesis package into your R session to use its functions. ```r library("photosynthesis") ``` -------------------------------- ### Setting up and Baking Leaf Parameters Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Demonstrates how to initialize and bake leaf parameters using various make functions. This is a prerequisite for calculating photosynthetic rates. The example shows both direct function calls and piping with the magrittr library. ```R bake_par = make_bakepar() constants = make_constants(use_tealeaves = FALSE) enviro_par = make_enviropar(use_tealeaves = FALSE) leaf_par = make_leafpar(use_tealeaves = FALSE) leaf_par = bake(leaf_par, enviro_par, bake_par, constants) # Or bake with piping (need library(magrittr)) # leaf_par %<>% bake(enviro_par, bake_par, constants) enviro_par$T_air = leaf_par$T_leaf pars = c(leaf_par, enviro_par, constants) C_chl = set_units(350, umol/mol) A_supply(C_chl, pars) A_demand(C_chl, pars) ``` -------------------------------- ### Data Manipulation and Plotting Setup Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/photosynthesis-introduction.html Prepares the data by dropping units and categorizing 'g[s]' based on 'g_sc' before plotting. This snippet sets up the data frame for visualization. ```r ph %<>% mutate_if(~ is(.x, "units"), drop_units) %>% mutate(`g[s]` = ifelse(g_sc == 0.2, "low", "high")) ``` -------------------------------- ### parameter_names Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Get a vector of parameter names for leaf, environmental, bake, or constants. This helps in understanding the available parameters for simulation. ```APIDOC ## parameter_names ### Description Get vector of parameter names ### Usage ``` parameter_names(which, use_tealeaves) ``` ### Arguments `which` | A character string indicating which parameter names to retrieve: "leaf", "enviro", "bake", or "constants". Partial matching allowed. `use_tealeaves` | Logical. Should leaf energy balance be used to calculate leaf temperature (T_leaf)? If TRUE, `tleaf()` calculates T_leaf. If FALSE, user-defined T_leaf is used. Additional parameters and constants are required, see `make_parameters()`. ### Value A character vector with parameter names associated with each type, "leaf", "enviro", "bake", or "constants". ### Examples ``` parameter_names("leaf", use_tealeaves = FALSE) ``` ``` -------------------------------- ### Load and Prepare A-Ci Curve Data Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Reads A-Ci curve data from the package's example files and preprocesses it for fitting. This includes creating a grouping factor for light intensity and converting leaf temperature to Kelvin. ```R # Read in your data # Note that this data is coming from data supplied by the package # hence the complicated argument in read.csv() # This dataset is a CO2 by light response curve for a single sunflower data <- read.csv(system.file("extdata", "A_Ci_Q_data_1.csv", package = "photosynthesis" )) # Define a grouping factor based on light intensity to split the ACi # curves data$Q_2 <- as.factor((round(data$Qin, digits = 0))) # Convert leaf temperature to K data$T_leaf <- data$Tleaf + 273.15 ``` -------------------------------- ### Fit Many Functions Across Groups (ACi Example) Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Fits a specified function (e.g., `fit_aci_response`) across different groups in the data. This example demonstrates fitting ACi response curves grouped by light intensity. ```R # Read in your data # Note that this data is coming from data supplied by the package # hence the complicated argument in read.csv() # This dataset is a CO2 by light response curve for a single sunflower data = read.csv(system.file("extdata", "A_Ci_Q_data_1.csv", package = "photosynthesis" )) # Define a grouping factor based on light intensity to split the ACi # curves data$Q_2 = as.factor((round(data$Qin, digits = 0))) # Convert leaf temperature to K data$T_leaf = data$Tleaf + 273.15 # Fit many curves fits = fit_many( data = data, varnames = list( A_net = "A", T_leaf = "T_leaf", C_i = "Ci", PPFD = "Qin" ), funct = fit_aci_response, group = "Q_2" ) # Print the parameters # First set of double parentheses selects an individual group value # Second set selects an element of the sublist fits[[3]][[1]] # Print the graph fits[[3]][[2]] # Compile graphs into a list for plotting fits_graphs = compile_data(fits, list_element = 2 ) # Compile parameters into dataframe for analysis fits_pars = compile_data(fits, output_type = "dataframe", list_element = 1 ) ``` -------------------------------- ### Parallel Processing with photosynthesis Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/photosynthesis-introduction.html To speed up simulations of many parameter sets, use `parallel = TRUE` in the `photosynthesis` function. Ensure you have set up a `future::plan()` before calling the function. This example simulates an A-CcA-Cc curve. ```r # NOTE: parallel example is not evaluated because it was causing an issue with CRAN, but you can copy-and-paste the code to run on your own machine. library(future) plan("multisession") # Set up plan # We'll use the `replace` argument to enter multiple atmospheric CO2 concentrations bake_par = make_bakepar() constants = make_constants(use_tealeaves = FALSE) enviro_par = make_enviropar( replace = list( C_air = set_units(seq(10, 2000, length.out = 20), umol / mol) ), use_tealeaves = FALSE ) leaf_par = make_leafpar(use_tealeaves = FALSE) ph = photosynthesis(leaf_par, enviro_par, bake_par, constants, use_tealeaves = FALSE, progress = FALSE, quiet = TRUE, parallel = TRUE) # Plot C_c versus A library(ggplot2) ## Drop units for plotting ph %<>% mutate_if(~ is(.x, "units"), drop_units) ggplot(ph, aes(C_chl, A)) + geom_line(size = 2) + xlab(expression(paste(C[chl], " [ppm] "))) + ylab(expression(paste("A [", mu, "mol ", m^-2~s^-1, "]"))) + theme_bw() + NULL ``` -------------------------------- ### Get default model Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Get the name of the default model used for different plant ecophysiological data analysis methods implemented in photosynthesis. Currently only used for fit_aq_response2() and fit_r_light2(). ```APIDOC ## get_default_model ### Description Get the name of the default model used for different plant ecophysiological data analysis methods implemented in **photosynthesis**. Currently only used for `fit_aq_response2()` and `fit_r_light2()`. **Light response models:** * `marshall_biscoe_1980()`: Non-rectangular hyperbolic model of light responses * `photoinhibition()`: Non-rectangular hyperbolic model of light responses with photoinhibition of `k_sat` at increasing Q_abs ### Usage ```R get_default_model(.photo_fun) get_all_models(method) marshall_biscoe_1980(Q_abs, k_sat, phi_J, theta_J) photoinhibition(Q_abs, k_sat, phi_J, theta_J, b_inh) ``` ### Arguments `.photo_fun` | A character string of **photosynthesis** function to call. One of: `⁠aq_response, r_light`. ---|--- `method` | A character string of the statistical method to use: 'ls' for least-squares and 'brms' for Bayesian model using `brms::brm()`. Default is 'ls'. `Q_abs` | Absorbed light intensity (`μ μ μ`mol m`−2^{-2}−2` s`−1^{-1}−1`) `k_sat` | Light saturated rate of process k `phi_J` | Quantum efficiency of process k `theta_J` | Curvature of the light response `b_inh` | Inhibition parameter ### Value A character string with name of model. ### Examples ```R get_default_model("aq_response") get_default_model("r_light") ``` ``` -------------------------------- ### Get All Available Models Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Retrieves all available models for a given statistical method. The 'method' argument can be 'ls' for least-squares or 'brms' for Bayesian models. ```R get_all_models(method) ``` -------------------------------- ### Get Cuticular Conductance to CO2 Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Calculates the cuticular conductance to CO2 (g_uc). Requires parameters and the leaf surface (lower or upper). Unitless calculations can be enabled. ```R .get_guc(pars, surface, unitless) ``` -------------------------------- ### Initialize Photosynthesis Parameters Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Sets up default parameters for leaf, environment, and constants for photosynthesis simulations. Allows for overriding specific leaf parameters like stomatal conductance (g_sc) and Vcmax at 25°C. ```r bake_par = make_bakepar() constants = make_constants(use_tealeaves = FALSE) enviro_par = make_enviropar(use_tealeaves = FALSE) leaf_par = make_leafpar(use_tealeaves = FALSE) leaf_par = make_leafpar( replace = list( g_sc = set_units(0.3, mol / m^2 / s), V_cmax25 = set_units(100, umol / m^2 / s) ), use_tealeaves = FALSE ) ``` -------------------------------- ### Baking Leaf Parameters with Temperature Response Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Demonstrates how to initialize leaf, environmental, and bake parameters, then use the `bake` function to incorporate temperature sensitivity into leaf parameters. This is useful for simulating photosynthesis under varying temperatures. ```R bake_par = make_bakepar() constants = make_constants(use_tealeaves = FALSE) enviro_par = make_enviropar(use_tealeaves = FALSE) leaf_par = make_leafpar( replace = list(T_leaf = set_units(293.15, K)), use_tealeaves = FALSE ) baked_leafpar = bake(leaf_par, enviro_par, bake_par, constants) baked_leafpar$V_cmax25 baked_leafpar$V_cmax ``` -------------------------------- ### Single Parameter Set with 'photo' Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Demonstrates how to use the 'photo' function with a single set of parameters to simulate photosynthesis. ```R # Single parameter set with 'photo' bake_par = make_bakepar() constants = make_constants(use_tealeaves = FALSE) enviro_par = make_enviropar(use_tealeaves = FALSE) leaf_par = make_leafpar(use_tealeaves = FALSE) photo(leaf_par, enviro_par, bake_par, constants, use_tealeaves = FALSE ) ``` -------------------------------- ### Get citation information Source: https://cran.r-project.org/web/packages/photosynthesis/readme/README.html Retrieve citation information for the photosynthesis package in R. This is useful for academic referencing. ```r citation(package = 'photosynthesis') ``` -------------------------------- ### Multiple Parameter Sets with 'photosynthesis' Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Illustrates using the 'photosynthesis' function to simulate gas exchange with multiple parameter sets, specifically varying leaf temperature. ```R # Multiple parameter sets with 'photosynthesis' leaf_par = make_leafpar( replace = list( T_leaf = set_units(c(293.14, 298.15), "K") ), use_tealeaves = FALSE ) photosynthesis(leaf_par, enviro_par, bake_par, constants, use_tealeaves = FALSE ) ``` -------------------------------- ### Replacing Default Photosynthesis Parameters Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/photosynthesis-introduction.html Demonstrates how to replace default parameters for photosynthesis simulation using the `replace` argument in `make_*()` functions. Ensure units are correctly specified using `set_units()`. ```R # Use the `replace` argument to replace defaults. This must be a named list, and # each named element must have the proper units specified. See `?make_parameters` # for all parameter names and proper units. # Temperature response parameters can be updated (but we won't do that here) bake_par = make_bakepar() # Physical constants probably do not need to be replaced in most cases, # that's why we call them 'constants'! constants = make_constants(use_tealeaves = FALSE) # First, we'll change photosynthetic photon flux density to 1000 umol / (m^2 s) enviro_par = make_enviropar( replace = list( PPFD = set_units(1000, "umol/m^2/s") ), use_tealeaves = FALSE ) # Next, we'll change stomatal conductance to 0.3 mol / m^2 / s. leaf_par = make_leafpar( replace = list( g_sc = set_units(0.3, mol / m^2 / s) ), use_tealeaves = FALSE ) photo <- photo(leaf_par, enviro_par, bake_par, constants, quiet = TRUE, use_tealeaves = FALSE) photo |> select(PPFD, C_chl, A) |> knitr::kable() ``` -------------------------------- ### Get Required Variables for Photosynthesis Models Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Retrieves the list of variables required for a specified photosynthesis model. Allows suppressing informational messages. ```R required_variables(.model, quiet) ``` -------------------------------- ### Get Default Functions for Calculated Parameters Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Retrieves default functions for calculated parameters in photosynthesis. This function is used internally or for advanced customization. ```r get_f_parameter(.f_name) ``` -------------------------------- ### Get Stomatal Conductance to CO2 Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Calculates the stomatal conductance to CO2 (g_sc). It requires parameters and the leaf surface, and offers a unitless calculation option. ```R .get_gsc(pars, surface, unitless) ``` -------------------------------- ### Get Mesophyll Conductance to CO2 Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Calculates the mesophyll conductance to CO2 (g_mc). This function takes parameters and the leaf surface as input, with an option for unitless calculations. ```R .get_gmc(pars, surface, unitless) ``` -------------------------------- ### Read and Prepare Data for Photosynthesis Analysis Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/light-respiration.html Reads a CSV file and prepares the data by rounding CO2 concentrations and renaming columns for use in photosynthesis models. ```r dat = system.file("extdata", "A_Ci_Q_data_1.csv", package = "photosynthesis") |> read.csv() |> mutate(group = photosynthesis:::round_to_nearest(CO2_s, values = c(50, 100, 200, 300, 410, 600, 820, 1200, 1600))) |> rename(A_net = A, PPFD = Qin, phi_PSII = PhiPS2, C_i = Ci) ``` -------------------------------- ### Make Lists of Parameters for Photosynthesis Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Functions to create parameter lists for various components used in the photosynthesis package. Includes options to replace default values and specify whether to use tealeaves for calculations. ```R make_leafpar(replace = NULL, use_tealeaves) make_enviropar(replace = NULL, use_tealeaves) make_bakepar(replace = NULL) make_constants(replace = NULL, use_tealeaves) ``` -------------------------------- ### Get Total Conductance to CO2 Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Calculates the total conductance to CO2 (g_tc). This function can optionally use a legacy version and allows control over unit handling for performance. ```R .get_gtc(pars, unitless, use_legacy_version) ``` -------------------------------- ### Fitting Multiple Stomatal Conductance Models Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/stomatal-conductance.html Fits various stomatal conductance models to the dataset, grouped by PPFD, and suppresses the progress bar for cleaner output. ```R # Fit many g_sw models fits = fit_many(dat, funct = fit_gs_model, group = "PPFD", progress = FALSE) ``` -------------------------------- ### photosynthesis Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Simulate C3 photosynthesis over multiple parameter sets using the Farquhar-von Caemmerer-Berry model. ```APIDOC ## photosynthesis ### Description `photosynthesis`: simulate C3 photosynthesis over multiple parameter sets `photo`: simulate C3 photosynthesis over a single parameter set ### Usage ``` photosynthesis( leaf_par, enviro_par, bake_par, constants, use_tealeaves, progress = TRUE, quiet = FALSE, assert_units = TRUE, check = TRUE, parallel = FALSE, use_legacy_version = FALSE ) photo( leaf_par, enviro_par, bake_par, constants, use_tealeaves, quiet = FALSE, assert_units = TRUE, check = TRUE, prepare_for_tleaf = use_tealeaves, use_legacy_version = FALSE ) ``` ### Arguments `leaf_par` | A list of leaf parameters inheriting class `leaf_par`. This can be generated using the `make_leafpar` function. `enviro_par` | A list of environmental parameters inheriting class `enviro_par`. This can be generated using the `make_enviropar` function. `bake_par` | A list of temperature response parameters inheriting class `bake_par`. This can be generated using the `make_bakepar` function. `constants` | A list of physical constants inheriting class `constants`. This can be generated using the `make_constants` function. `use_tealeaves` | Logical. Should leaf energy balance be used to calculate leaf temperature (T_leaf)? If TRUE, `tleaf()` calculates T_leaf. If FALSE, user-defined T_leaf is used. Additional parameters and constants are required, see `make_parameters()`. `progress` | Logical. Should a progress bar be displayed? `quiet` | Logical. Should messages be displayed? `assert_units` | Logical. Should parameter `units` be checked? The function is faster when FALSE, but input must be in correct units or else results will be incorrect without any warning. `check` | Logical. Should arguments checks be done? This is intended to be disabled when `photo()` is called from `photosynthesis()` Default is TRUE. `parallel` | Logical. Should parallel processing be used via `furrr::future_map()`? `use_legacy_version` | Logical. Should legacy model (<2.1.0) be used? See NEWS for further information. Default is FALSE. `prepare_for_tleaf` | Logical. Should arguments additional calculations for `tleaf()`? This is intended to be disabled when `photo()` is called from `photosynthesis()`. Default is `use_tealeaves`. ### Details `photo`: This function takes simulates photosynthetic rate using the Farquhar-von Caemmerer-Berry (`FvCB()`) model of C3 photosynthesis for single combined set of leaf parameters (`leaf_par()`), environmental parameters (`enviro_par()`), and physical constants (`constants()`). Leaf parameters are provided at reference temperature (25 °C) and then "baked" to the appropriate leaf temperature using temperature response functions (see `bake()`). `photosynthesis`: This function uses `photo` to simulate photosynthesis over multiple parameter sets that are generated using `cross_df()`. ``` -------------------------------- ### Get Photosynthesis Parameter Names Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Retrieves a vector of parameter names for a specified category (leaf, enviro, bake, or constants). Useful for understanding the available parameters within each group. ```r parameter_names("leaf", use_tealeaves = FALSE) ``` -------------------------------- ### Get Default Model for Photosynthesis Functions Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Retrieves the default model name used for specific photosynthesis functions like fit_aq_response2() and fit_r_light2(). Supported functions are 'aq_response' and 'r_light'. ```R get_default_model("aq_response") get_default_model("r_light") ``` -------------------------------- ### Fit Single and Multiple Photosynthesis Light-Response Curves Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Demonstrates fitting a single light-response curve using `fit_photosynthesis` and then fitting multiple curves by splitting the data. Requires the `broom`, `dplyr`, and `photosynthesis` packages. ```R library(broom) library(dplyr) library(photosynthesis) # Read in your data dat = system.file("extdata", "A_Ci_Q_data_1.csv", package = "photosynthesis") |> read.csv() |> # Set grouping variable mutate(group = round(CO2_s, digits = 0)) |> # For this example, round sequentially due to CO2_s set points mutate(group = as.factor(round(group, digits = -1))) # Fit one light-response curve fit = fit_photosynthesis( .data = filter(dat, group == 600), .photo_fun = "aq_response", .vars = list(.A = A, .Q = Qabs) ) # The 'fit' object inherits class 'nls' and many methods can be used ## Model summary: summary(fit) ## Estimated parameters: coef(fit) ## 95% confidence intervals: confint(fit) ## Tidy summary table using 'broom::tidy()' tidy(fit, conf.int = TRUE, conf.level = 0.95) # Fit multiple curves with **photosynthesis** and **purrr** library(purrr) fits = dat | split(~ group) | map(fit_photosynthesis, .photo_fun = "aq_response", .vars = list(.A = A, .Q = Qabs)) ``` -------------------------------- ### Get Boundary Layer Conductance to CO2 Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Calculates the boundary layer conductance to CO2 (g_bc). Supports an option to use a legacy model version and allows control over unitless calculations. ```R .get_gbc(pars, surface, unitless, use_legacy_version) ``` -------------------------------- ### Constructor for enviro_par class Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Use this function to construct a list into enviro_par. It ensures environmental parameter inputs are properly formatted. ```R enviro_par(.x, use_tealeaves) ``` -------------------------------- ### Fit Mesophyll Conductance (Variable J Method) Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/mesophyll-conductance.html This snippet demonstrates how to fit mesophyll conductance using the `fit_g_mc_variableJ` function. Ensure your data is correctly formatted and that parameters like `gamma_star`, `R_d`, `alpha_Q`, `beta_Q`, and `P` are accurately set. Note that some calculated `g_mc` values may be unreliable. ```R library(dplyr) library(photosynthesis) # Read in your data dat = system.file("extdata", "A_Ci_Q_data_1.csv", package = "photosynthesis") |> read.csv() |> rename(A_net = A, J_etr = ETR, C_i = Ci, PPFD = Qin, phi_PSII = PhiPS2) # Note: there will be issues here if the alpha value used for calculating ETR is # off, if GammaStar is incorrect, if Rd is incorrect. fit = fit_g_mc_variableJ(dat, gamma_star = 46, R_d = 0.153, usealpha_Q = TRUE, alpha_Q = 0.84, beta_Q = 0.5, P = 84) # Note that many g_mc values from this method can be unreliable # ggplot(fit, aes(x = CO2_s, y = g_mc, colour = reliable)) + # labs(x = expression(CO[2]~"("~mu*mol~mol^{-1}*")"), # y = expression(g[m]*"("~mol~m^{-2}~s^{-1}~Pa^{-1}*")")) + # geom_point(size = 2) + # theme_bw() + # theme(legend.position = 'bottom') # Plot QAQC graph according to Harley et al. 1992 # ggplot(fit, aes(x = CO2_s, y = dCcdA, colour = reliable)) + # labs(x = expression(CO[2]~"("~mu*mol~mol^{-1}*")"), # y = expression(delta*C[c]*"/"*delta*A)) + # geom_hline(yintercept = 10) + # geom_point(size = 2) + # theme_bw() + # theme(legend.position = 'bottom') # ggplot(fit, aes(x = dCcdA, y = g_mc, colour = reliable)) + # labs(x = expression(delta*C[c]*"/"*delta*A), # y = expression(g[m]*"("~mol~m^{-2}~s^{-1}~Pa^{-1}*")")) + # geom_point(size = 2) + # theme_bw() + # theme(legend.position = 'bottom') ``` -------------------------------- ### Fit Light Respiration using Kok Method Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/light-respiration.html Fits the light respiration model using the Kok method within a specified PPFD range. Ensure data is prepared before use. ```r r_light = fit_r_light_kok(data = dat, PPFD_lower = 20, PPFD_upper = 150) ``` -------------------------------- ### Model typical hypostomatous leaf Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/modeling-recommendations.html Implements a simplified C3 photosynthesis model for a hypostomatous leaf. Assumes high boundary layer conductance, zero cuticular conductance, all stomatal conductance through the lower surface, and a single mesophyll conductance. Use this for basic modeling when complexities are not critical. ```r library(photosynthesis) bake_par = make_bakepar() # temperature response parameters constants = make_constants(use_tealeaves = FALSE) # physical constants # leaf parameters leaf_par = make_leafpar( replace = list( # Set cuticular conductance to 0 g_uc = set_units(0, mol / m^2 / s), # All conductance through lower stomata and mesophyll k_mc = set_units(0, 1), k_sc = set_units(0, 1) ), use_tealeaves = FALSE ) enviro_par = make_enviropar(use_tealeaves = FALSE) # environmental parameters photo(leaf_par, enviro_par, bake_par, constants, use_tealeaves = FALSE) | dplyr::select(g_sc, A) | knitr::kable(caption = "Stomatal conductance to CO2 (g_sc) and net photosynthetic carbon assimilation (A) from C3 photosynthesis model.") ``` -------------------------------- ### Make lists of parameters for photosynthesis Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Functions to create parameter lists for various components of the photosynthesis package. ```APIDOC ## Make lists of parameters for `photosynthesis` ### Description Make lists of parameters for `photosynthesis` make_leafpar make_enviropar make_bakepar make_constants ### Usage ```R make_leafpar(replace = NULL, use_tealeaves) make_enviropar(replace = NULL, use_tealeaves) make_bakepar(replace = NULL) make_constants(replace = NULL, use_tealeaves) ``` ``` -------------------------------- ### Fit a Single CO2 Response Curve Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/co2-response.html Fits a single ACi curve using the `fit_aci_response` function from the photosynthesis package. This example filters the data to include only measurements for a specific light level (group == 1500). ```R # Fit ACi curve. # Note that we are filtering the data.frame to fit for a single light value fit = fit_aci_response(filter(dat, group == 1500)) ``` -------------------------------- ### Fit Bayesian Light-Response Curve with brms Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/light-response.html Use this function to fit a single Bayesian light-response curve using the brms package. It's suitable for complex datasets where Bayesian methods offer advantages. Ensure brms and Stan are installed. ```R fit = fit_photosynthesis( .data = filter(dat, group == 600), .photo_fun = "aq_response", .vars = list(.A = A, .Q = Qabs), .method = "brms", brm_options = list(chains = 1) ) # The 'fit' object inherits class 'brmsfit' and many methods can be used summary(fit) ``` -------------------------------- ### Read and Prepare Photosynthesis Data Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/sensitivity-analysis.Rmd Reads a CSV dataset and prepares it for analysis by creating a grouping factor based on light intensity and converting leaf temperature to Kelvin. This is a prerequisite for running sensitivity analyses. ```r #Read in your data #Note that this data is coming from data supplied by the package #hence the complicated argument in read.csv() #This dataset is a CO2 by light response curve for a single sunflower data <- read.csv(system.file("extdata", "A_Ci_Q_data_1.csv", package = "photosynthesis")) #Define a grouping factor based on light intensity to split the ACi #curves data$Q_2 <- as.factor((round(data$Qin, digits = 0))) #Convert data temperature to K data$T_leaf <- data$Tleaf + 273.15 ``` -------------------------------- ### Incorporating Leaf Temperature with tealeaves Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/photosynthesis-introduction.html Set `use_tealeaves = TRUE` in `make_constants`, `make_enviropar`, and `make_leafpar` to calculate leaf temperature using the `tealeaves` package's energy balance model within `photosynthesis`. This example varies air temperature and stomatal conductance. ```r # NOTE: parallel example is not evaluated because it was causing an issue with CRAN, but you can copy-and-paste the code to run on your own machine. # You will need to set use_tealeaves = TRUE when making parameters because additional parameters are needed for tealeaves. bake_par = make_bakepar() constants = make_constants(use_tealeaves = TRUE) enviro_par = make_enviropar( replace = list( T_air = set_units(seq(288.15, 313.15, 1), K) ), use_tealeaves = TRUE ) leaf_par = make_leafpar(replace = list( g_sc = set_units(c(0.2, 0.4), mol / m^2 / s) ), use_tealeaves = TRUE ) ph = photosynthesis(leaf_par, enviro_par, bake_par, constants, use_tealeaves = TRUE, progress = FALSE, quiet = TRUE, parallel = TRUE) # Plot temperature and photosynthesis library(ggplot2) ``` -------------------------------- ### Load photosynthesis package Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/modeling-recommendations.html Loads the 'photosynthesis' R package. This is a prerequisite for using any functions within the package. ```r library(photosynthesis) ``` -------------------------------- ### Solving for Multiple Parameter Sets with photosynthesis Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/photosynthesis-introduction.html Use the `photosynthesis` function to solve for multiple parameter sets by specifying multiple values for leaf or environmental parameters. The function uses `purrr::cross` to fit all combinations. This example demonstrates crossing PPFD and stomatal conductance. ```r # As before, use the `replace` argument to replace defaults, but this time we # enter multiple values bake_par = make_bakepar() constants = make_constants(use_tealeaves = FALSE) # First, we'll change the PPFD to 1000 and 1500 umol / (m^2 s) enviro_par = make_enviropar( replace = list( PPFD = set_units(c(1000, 1500), umol / m^2 / s) ), use_tealeaves = FALSE ) # Next, we'll change stomatal conductance to to 0.2 and 0.4 mol / m^2 / s leaf_par = make_leafpar( replace = list( g_sc = set_units(c(0.2, 0.4), mol / m^2 / s) ), use_tealeaves = FALSE ) # Now there should be 4 combinations (high and low g_sc crossed with high and low PPFD) ph = photosynthesis(leaf_par, enviro_par, bake_par, constants, use_tealeaves = FALSE, progress = FALSE, quiet = TRUE) ph |> select(g_sc, PPFD, A) |> knitr::kable() ``` -------------------------------- ### Conductance Partitioning Formula Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Formulas for partitioning total cuticular and stomatal conductances between upper and lower surfaces using partitioning factors. ```mathematica gx,lower=gx(1/(1+kx)) ``` ```mathematica gx,upper=gx(kx/(1+kx)) ``` ```mathematica gx=gx,lower+gx,upper ``` -------------------------------- ### Compiling Model Outputs Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/stomatal-conductance.html Compiles the results from multiple fitted stomatal conductance models. It first compiles the BallBerry models into a list and then extracts their parameters into a dataframe. ```R # Compile parameter outputs for BallBerry model # Note that it's the first element for each PAR value # First compile list of BallBerry fits bbmods = compile_data(data = fits, output_type = "list", list_element = 1) # Now compile the parameters (2nd element) into a dataframe bbpars = compile_data(data = bbmods, output_type = "dataframe", list_element = 2) #Compile graphs graphs = compile_data(data = bbmods, output_type = "list", list_element = 3) ``` -------------------------------- ### Fit Light Respiration using Yin Method Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/light-respiration.html Fits the light respiration model using the Yin method within a specified PPFD range. Ensure data is prepared before use. ```r r_light = fit_r_light_yin(data = dat, PPFD_lower = 20, PPFD_upper = 250) ``` -------------------------------- ### Data Preparation and Ball-Berry Model Fitting Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/stomatal-conductance.html Reads CSV data, preprocesses it by converting RH and rounding PPFD, and fits the Ball-Berry stomatal conductance model for a specific PPFD value. ```R library(dplyr) library(photosynthesis) round_to_nearest = function(x, values) { sapply(x, function(y, values) { values[which.min(abs(y - values))] }, values = values) } # Read in data dat = system.file("extdata", "A_Ci_Q_data_1.csv", package = "photosynthesis") |> read.csv() |> # Convert RH to a proportion mutate( RH = RHcham / 100, PPFD = round_to_nearest(Qin, c(25, 50, 75, 100, 125, 375, 750, 1500)) ) |> rename(A_net = A, C_air = Ca, g_sw = gsw, VPD = VPDleaf) # Fit the Ball-Berry stomatal conductance models fit = fit_gs_model( data = filter(dat, PPFD == 750), model = c("BallBerry") ) # Look at BallBerry model summary: summary(fit[["BallBerry"]][["Model"]]) ``` -------------------------------- ### Simulate Photosynthesis with Error Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html This snippet demonstrates setting leaf, environmental, and background parameters, then simulating photosynthesis and adding simulated error based on chamber conditions. It's useful for generating realistic data for analysis. ```R lp = make_leafpar(replace = list( g_sc = set_units(0.1, mol/m^2/s), g_uc = set_units(0, mol/m^2/s), k_mc = set_units(0, 1), k_sc = set_units(0, 1), k_uc = set_units(0, 1) ), use_tealeaves = FALSE) ep = make_enviropar(replace = list( wind = set_units(Inf, m/s) ), use_tealeaves = FALSE) bp = make_bakepar() cs = make_constants(use_tealeaves = FALSE) chamber_pars = data.frame( flow = set_units(600, umol / s), leaf_area = set_units(6, cm ^ 2), sigma_CO2_s = 0.1, sigma_CO2_r = 0.1, sigma_H2O_s = 0.1, sigma_H2O_r = 0.1 ) ph = photosynthesis(lp, ep, bp, cs, use_tealeaves = FALSE, quiet = TRUE) |> simulate_error(chamber_pars, n = 1L) ``` -------------------------------- ### Accessing Fitted Temperature Response Graphs Source: https://cran.r-project.org/web/packages/photosynthesis/vignettes/temperature-response.html Illustrates how to access the generated graphs for different temperature response models from the 'fit' object. The graphs are stored within a list structure. ```R # Graphs # fit[["Arrhenius"]][["Graph"]] # fit[["Heskel"]][["Graph"]] # fit[["Kruse"]][["Graph"]] # fit[["Medlyn"]][["Graph"]] # fit[["MMRT"]][["Graph"]] # fit[["Quadratic"]][["Graph"]] # fit[["Topt"]][["Graph"]] ``` -------------------------------- ### Data Preparation and CO2 Response Curve Fitting Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html This snippet demonstrates reading CSV data, performing temperature rounding and grouping, creating unique IDs, calculating mean temperatures for groups, and fitting multiple CO2 response curves using the `fit_many` function. It also shows how to extract fitted parameters and graphs. ```R # Read in data data <- read.csv(system.file("extdata", "A_Ci_T_data.csv", package = "photosynthesis" ), stringsAsFactors = FALSE ) library(tidyr) # Round temperatures to group them appropriately # Use sequential rounding data$T2 <- round(data$Tleaf, 1) data$T2 <- round(data$Tleaf, 0) # Look at unique values to detect rounding issues unique(data$T2) # Some still did not round correctly, # manually correct for (i in 1:nrow(data)) { if (data$T2[i] == 18) { data$T2[i] <- 17 } if (data$T2[i] == 23) { data$T2[i] <- 22 } if (data$T2[i] == 28) { data$T2[i] <- 27 } if (data$T2[i] == 33) { data$T2[i] <- 32 } if (data$T2[i] == 38) { data$T2[i] <- 37 } } # Make sure it is a character string for grouping data$T2 <- as.character(data$T2) # Create grouping variable by ID and measurement temperature data <- unite( data, col = "ID2", c("ID", "T2"), sep = "_" ) # Split by temperature group data <- split(data, data$ID2) # Obtain mean temperature for group so temperature # response fitting is acceptable later, round to # 2 decimal places for (i in 1:length(data)) { data[[i]]$Curve_Tleaf <- round(mean(data[[i]]$Tleaf), 2) } # Convert from list back to dataframe data <- do.call("rbind", data) # Parse grouping variable by ID and measurement temperature data <- separate( data, col = "ID2", into = c("ID", "T2"), sep = "_" ) # Make sure number of values matches number of measurement # temperatures. May vary slightly if plants had slightly # different leaf temperatures during the measurements unique(data$Curve_Tleaf) # Create ID column to curve fit by ID and temperature data <- unite( data, col = "ID2", c("ID", "Curve_Tleaf"), sep = "_" ) # Convert leaf temperature to K data$T_leaf <- data$Tleaf + 273.15 # Fit many CO2 response curves fits2 <- fit_many( data = data, group = "ID2", varnames = list( A_net = "A", C_i = "Ci", T_leaf = "T_leaf", PPFD = "Qin", g_mc = "g_mc" ), funct = fit_aci_response, alphag = 0 ) # Extract ACi parameters pars <- compile_data( fits2, output_type = "dataframe", list_element = 1 ) # Extract ACi graphs graphs <- compile_data( fits2, output_type = "list", list_element = 2 ) ``` -------------------------------- ### Calculate Entropy Parameter (dS) Source: https://cran.r-project.org/web/packages/photosynthesis/refman/photosynthesis.html Calculates the entropy parameter (dS) from fitted optimum temperature (Topt) model parameters. Requires activation energy, deactivation energy, and optimum temperature. ```R t_response_calc_dS(Ea, Hd, Topt) ```