cdmuir / tealeaves

Solve for leaf temperature using energy balance
Other
11 stars 1 forks source link

Predicting transpiration from Tleaf #7

Open jstinzi opened 5 years ago

jstinzi commented 5 years ago

Would it be possible to alter the functions to predict transpiration/stomatal conductance given Tleaf? For example, using thermal imaging data?

cdmuir commented 5 years ago

Thanks for the question and suggestion. This will work:

library(magrittr)
library(purrr)
library(tealeaves)

cs <- make_constants()
lp <- make_leafpar()
ep <- make_enviropar()

# Remove units for speed
upars <- c(cs, lp, ep) %>%
  purrr::map_if(~ inherits(.x, "units"), drop_units)

# Function to find g_sw that balances energy budget given a leaf temperature
fn <- function(log_gs, tleaf_K, unitless_pars) {
  unitless_pars$g_sw <- exp(log_gs)
  ret <- abs(energy_balance(tleaf_K, unitless_pars, unitless_pars, unitless_pars, 
                            unitless = TRUE, check = FALSE))
  ret
}

# Find solution
fit <- optim(1, fn, tleaf_K = 310, unitless_pars = upars, 
      lower = log(0.01), upper = log(10), method = "Brent")
exp(fit$par) # g_sw in units of umol/m^2/s/Pa

I am going to start overhauling the tealeaves code for speed and making some other improvements. I will make a function that does this in a more elegant way, but hopefully this can get your started!