calcpCO2 <- function(df, pool, ...) {
allColumns <- sum(
grepl(
paste(
c('WTW_Temp_degC_1',
'CO2_HS_Um'),
collapse = '|'
),
colnames(df)
)
) == 2
if (nrow(df) == 1 & allColumns) {
cst_to_get <- c('c_const')
constants <- getRows(pool, 'constants', name %in% cst_to_get, columns = c('name', 'value'))
co2 <- df %>% select(starts_with('CO2_HS_Um')) %>% pull()
water_temp_k <- 273.15 + df %>% pull('WTW_Temp_degC_1')
c_const <- constants %>% filter(name == 'c_const') %>% pull('value')
if (!any(is.na(c(co2, water_temp_k, c_const)))) {
dividend <- co2
divisor <- 0.034 * exp(c_const * (1/water_temp_k - 1/298.15))
if (divisor != 0) {
return(
dividend / divisor
)
}
}
}
as.numeric(NA)
}