File size: 20,432 Bytes
c223bdd |
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
context("unitless values match unit-ed values")
library(photosynthesis)
test_that("unitless values match unit-ed values (!tealeaves, new g_tc)", {
cs1 = make_constants(use_tealeaves = FALSE)
cs2 = purrr::map_if(cs1, function(x) is(x, "units"), drop_units)
lp1 = leaf_par(list(
A_mes_A = set_units(runif(1, 5, 40), 1),
delta_ias_lower = set_units(runif(1, 0, 1000), um),
delta_ias_upper = set_units(runif(1, 0, 1000), um),
g_liqc25 = set_units(runif(1, 0, 0.1), mol/m^2/s),
g_mc25 = set_units(runif(1), mol/m^2/s),
g_sc = set_units(runif(1), mol/m^2/s),
g_uc = set_units(runif(1), mol/m^2/s),
gamma_star25 = set_units(runif(1, 30, 50), umol/mol),
J_max25 = set_units(runif(1, 50, 200), umol/m^2/s),
K_C25 = set_units(268.3, umol/mol),
K_O25 = set_units(165084.2, umol/mol),
k_mc = set_units(runif(1, 0.01, 100)),
k_sc = set_units(runif(1, 0.01, 100)),
k_uc = set_units(runif(1, 0.01, 100)),
leafsize = set_units(runif(1), m),
phi_J = set_units(0.331),
R_d25 = set_units(runif(1, 0, 5), umol/m^2/s),
T_leaf = set_units(runif(1, 273.15, 313.15), K),
theta_J = set_units(0.825),
V_cmax25 = set_units(runif(1, 50, 200), umol/m^2/s),
V_tpu25 = set_units(runif(1, 50, 200), umol/m^2/s)
), use_tealeaves = FALSE)
lp2 = purrr::map_if(lp1, function(x) is(x, "units"), drop_units)
ep1 = enviro_par(list(
C_air = set_units(runif(1, 10, 2000), umol/mol),
O = set_units(0.21, mol/mol),
P = set_units(101.3246, kPa),
RH = set_units(runif(1)),
PPFD = set_units(runif(1, 0, 2000), umol/m^2/s),
wind = set_units(runif(1, 0, 20), m/s)
), use_tealeaves = FALSE)
ep1$T_air = lp1$T_leaf
ep2 = purrr::map_if(ep1, function(x) is(x, "units"), drop_units)
bp1 = make_bakepar()
bp2 = purrr::map_if(bp1, ~ is(.x, "units"), drop_units)
lp1 %<>% bake(ep1, bp1, cs1, assert_units = TRUE)
lp2 %<>% bake(ep2, bp2, cs2, assert_units = FALSE)
purrr::map2(lp1, lp2[names(lp1)], function(.x, .y) {
dplyr::near(drop_units(.x), drop_units(.y))
}) %>%
purrr::map(expect_true)
C_chl = set_units(runif(1, 200, 400), umol/mol)
pars1 = c(cs1, lp1, ep1)
pars2 = purrr::map_if(pars1, function(x) is(x, "units"), drop_units)
Ad1 = A_demand(C_chl, pars1, unitless = FALSE)
Ad2 = A_demand(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(drop_units(Ad1), Ad2)
As1 = A_supply(C_chl, pars1, unitless = FALSE, use_legacy_version = FALSE)
As2 = A_supply(drop_units(C_chl), pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(drop_units(As1), As2)
gbc1 = drop_units(.get_gbc(pars1, "lower", unitless = FALSE, use_legacy_version = FALSE))
gbc2 = .get_gbc(pars2, "lower", unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gbc1, gbc2)
gbc3 = drop_units(.get_gbc(pars1, "upper", unitless = FALSE, use_legacy_version = FALSE))
gbc4 = .get_gbc(pars2, "upper", unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gbc3, gbc4)
gmc1 = drop_units(.get_gmc(pars1, "lower", unitless = FALSE))
gmc2 = .get_gmc(pars2, "lower", unitless = TRUE)
expect_equal(gmc1, gmc2)
gmc3 = drop_units(.get_gmc(pars1, "upper", unitless = FALSE))
gmc4 = .get_gmc(pars2, "upper", unitless = TRUE)
expect_equal(gmc3, gmc4)
gsc1 = drop_units(.get_gsc(pars1, "lower", unitless = FALSE))
gsc2 = .get_gsc(pars2, "lower", unitless = TRUE)
expect_equal(gsc1, gsc2)
gsc3 = drop_units(.get_gsc(pars1, "upper", unitless = FALSE))
gsc4 = .get_gsc(pars2, "upper", unitless = TRUE)
expect_equal(gsc3, gsc4)
gtc1 = drop_units(.get_gtc(pars1, unitless = FALSE, use_legacy_version = FALSE))
gtc2 = .get_gtc(pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gtc1, gtc2)
gtc3 = drop_units(.get_gtc(pars1, unitless = FALSE, use_legacy_version = FALSE))
gtc4 = .get_gtc(pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gtc3, gtc4)
guc1 = drop_units(.get_guc(pars1, "lower", unitless = FALSE))
guc2 = .get_guc(pars2, "lower", unitless = TRUE)
expect_equal(guc1, guc2)
guc3 = drop_units(.get_guc(pars1, "upper", unitless = FALSE))
guc4 = .get_guc(pars2, "upper", unitless = TRUE)
expect_equal(guc3, guc4)
FvCB1 = FvCB(C_chl, pars1, unitless = FALSE)
FvCB2 = FvCB(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(drop_units(FvCB1$A), FvCB2$A)
J1 = drop_units(J(pars1, unitless = FALSE))
J2 = J(pars2, unitless = TRUE)
expect_equal(J1, J2)
Wc1 = drop_units(W_carbox(C_chl, pars1, unitless = FALSE))
Wc2 = W_carbox(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wc1, Wc2)
Wr1 = drop_units(W_regen(C_chl, pars1, unitless = FALSE))
Wr2 = W_regen(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wr1, Wr2)
Wt1 = drop_units(W_tpu(C_chl, pars1, unitless = FALSE))
Wt2 = W_tpu(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wt1, Wt2)
})
test_that("unitless values match unit-ed values (!tealeaves, old g_tc)", {
cs1 = make_constants(use_tealeaves = FALSE)
cs2 = purrr::map_if(cs1, function(x) is(x, "units"), drop_units)
lp1 = leaf_par(list(
A_mes_A = set_units(numeric(0), 1),
delta_ias_lower = set_units(numeric(0), um),
delta_ias_upper = set_units(numeric(0), um),
g_liqc25 = set_units(numeric(0), mol/m^2/s),
g_mc25 = set_units(runif(1), mol/m^2/s),
g_sc = set_units(runif(1), mol/m^2/s),
g_uc = set_units(runif(1), mol/m^2/s),
gamma_star25 = set_units(runif(1, 30, 50), umol/mol),
J_max25 = set_units(runif(1, 50, 200), umol/m^2/s),
K_C25 = set_units(268.3, umol/mol),
K_O25 = set_units(165084.2, umol/mol),
k_mc = set_units(runif(1, 0.01, 100)),
k_sc = set_units(runif(1, 0.01, 100)),
k_uc = set_units(runif(1, 0.01, 100)),
leafsize = set_units(runif(1), m),
phi_J = set_units(0.331),
R_d25 = set_units(runif(1, 0, 5), umol/m^2/s),
T_leaf = set_units(runif(1, 273.15, 313.15), K),
theta_J = set_units(0.825),
V_cmax25 = set_units(runif(1, 50, 200), umol/m^2/s),
V_tpu25 = set_units(runif(1, 50, 200), umol/m^2/s)
), use_tealeaves = FALSE)
lp2 = purrr::map_if(lp1, function(x) is(x, "units"), drop_units)
ep1 = enviro_par(list(
C_air = set_units(runif(1, 10, 2000), umol/mol),
O = set_units(0.21, mol/mol),
P = set_units(101.3246, kPa),
RH = set_units(runif(1)),
PPFD = set_units(runif(1, 0, 2000), umol/m^2/s),
wind = set_units(runif(1, 0, 20), m/s)
), use_tealeaves = FALSE)
ep1$T_air = lp1$T_leaf
ep2 = purrr::map_if(ep1, function(x) is(x, "units"), drop_units)
bp1 = make_bakepar()
bp2 = purrr::map_if(bp1, ~ is(.x, "units"), drop_units)
lp1 %<>% bake(ep1, bp1, cs1, assert_units = TRUE)
lp2 %<>% bake(ep2, bp2, cs2, assert_units = FALSE)
purrr::map2(lp1, lp2[names(lp1)], function(.x, .y) {
if (length(.x) == 0) {TRUE} else {dplyr::near(drop_units(.x), drop_units(.y))}
}) |>
purrr::map(expect_true)
C_chl = set_units(runif(1, 200, 400), umol/mol)
pars1 = c(cs1, lp1, ep1)
pars2 = purrr::map_if(pars1, function(x) is(x, "units"), drop_units)
Ad1 = A_demand(C_chl, pars1, unitless = FALSE)
Ad2 = A_demand(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(drop_units(Ad1), Ad2)
As1 = A_supply(C_chl, pars1, unitless = FALSE, use_legacy_version = FALSE)
As2 = A_supply(drop_units(C_chl), pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(drop_units(As1), As2)
gbc1 = drop_units(.get_gbc(pars1, "lower", unitless = FALSE, use_legacy_version = FALSE))
gbc2 = .get_gbc(pars2, "lower", unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gbc1, gbc2)
gbc3 = drop_units(.get_gbc(pars1, "upper", unitless = FALSE, use_legacy_version = FALSE))
gbc4 = .get_gbc(pars2, "upper", unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gbc3, gbc4)
gmc1 = drop_units(.get_gmc(pars1, "lower", unitless = FALSE))
gmc2 = .get_gmc(pars2, "lower", unitless = TRUE)
expect_equal(gmc1, gmc2)
gmc3 = drop_units(.get_gmc(pars1, "upper", unitless = FALSE))
gmc4 = .get_gmc(pars2, "upper", unitless = TRUE)
expect_equal(gmc3, gmc4)
gsc1 = drop_units(.get_gsc(pars1, "lower", unitless = FALSE))
gsc2 = .get_gsc(pars2, "lower", unitless = TRUE)
expect_equal(gsc1, gsc2)
gsc3 = drop_units(.get_gsc(pars1, "upper", unitless = FALSE))
gsc4 = .get_gsc(pars2, "upper", unitless = TRUE)
expect_equal(gsc3, gsc4)
gtc1 = drop_units(.get_gtc(pars1, unitless = FALSE, use_legacy_version = FALSE))
gtc2 = .get_gtc(pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gtc1, gtc2)
gtc3 = drop_units(.get_gtc(pars1, unitless = FALSE, use_legacy_version = FALSE))
gtc4 = .get_gtc(pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gtc3, gtc4)
guc1 = drop_units(.get_guc(pars1, "lower", unitless = FALSE))
guc2 = .get_guc(pars2, "lower", unitless = TRUE)
expect_equal(guc1, guc2)
guc3 = drop_units(.get_guc(pars1, "upper", unitless = FALSE))
guc4 = .get_guc(pars2, "upper", unitless = TRUE)
expect_equal(guc3, guc4)
FvCB1 = FvCB(C_chl, pars1, unitless = FALSE)
FvCB2 = FvCB(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(drop_units(FvCB1$A), FvCB2$A)
J1 = drop_units(J(pars1, unitless = FALSE))
J2 = J(pars2, unitless = TRUE)
expect_equal(J1, J2)
Wc1 = drop_units(W_carbox(C_chl, pars1, unitless = FALSE))
Wc2 = W_carbox(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wc1, Wc2)
Wr1 = drop_units(W_regen(C_chl, pars1, unitless = FALSE))
Wr2 = W_regen(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wr1, Wr2)
Wt1 = drop_units(W_tpu(C_chl, pars1, unitless = FALSE))
Wt2 = W_tpu(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wt1, Wt2)
})
test_that("unitless values match unit-ed values (tealeaves, new g_tc)", {
T_leaf = NA
while (is.na(T_leaf)) {
cs1 = make_constants(use_tealeaves = TRUE)
lp1 = leaf_par(list(
A_mes_A = set_units(runif(1, 5, 40), 1),
abs_l = set_units(runif(1), 1),
abs_s = set_units(runif(1), 1),
delta_ias_lower = set_units(runif(1, 0, 1000), um),
delta_ias_upper = set_units(runif(1, 0, 1000), um),
g_liqc25 = set_units(runif(1, 0, 0.1), mol/m^2/s),
g_mc25 = set_units(runif(1), mol/m^2/s),
g_sc = set_units(runif(1), mol/m^2/s),
g_uc = set_units(runif(1), mol/m^2/s),
gamma_star25 = set_units(runif(1, 30, 50), umol/mol),
J_max25 = set_units(runif(1, 50, 200), umol/m^2/s),
K_C25 = set_units(268.3, umol/mol),
K_O25 = set_units(165084.2, umol/mol),
k_mc = set_units(runif(1, 0.01, 100)),
k_sc = set_units(runif(1, 0.01, 100)),
k_uc = set_units(runif(1, 0.01, 100)),
leafsize = set_units(runif(1), m),
phi_J = set_units(0.331),
R_d25 = set_units(runif(1, 0, 5), umol/m^2/s),
theta_J = set_units(0.825),
V_cmax25 = set_units(runif(1, 50, 200), umol/m^2/s),
V_tpu25 = set_units(runif(1, 50, 200), umol/m^2/s)
), use_tealeaves = TRUE)
ep1 = enviro_par(list(
C_air = set_units(runif(1, 10, 2000), umol/mol),
E_q = set_units(220, kJ/mol),
f_par = set_units(runif(1), 1),
O = set_units(0.21, mol/mol),
P = set_units(101.3246, kPa),
r = set_units(runif(1), 1),
RH = set_units(runif(1)),
PPFD = set_units(runif(1, 0, 2000), umol/m^2/s),
T_air = set_units(runif(1, 273.15, 313.15), K),
T_sky = photosynthesis:::get_f_parameter("T_sky"),
wind = set_units(runif(1, 0, 20), m/s)
), use_tealeaves = TRUE)
bp1 = make_bakepar()
lp1 = photosynthesis:::add_Tleaf_photo(lp1, ep1, cs1, TRUE)
T_leaf = lp1$T_leaf
}
lp1 %<>% bake(ep1, bp1, cs1, assert_units = TRUE)
# Drop units
cs2 = purrr::map_if(cs1, function(x) is(x, "units"), drop_units)
lp2 = purrr::map_if(lp1, function(x) is(x, "units"), drop_units)
ep2 = purrr::map_if(ep1, function(x) is(x, "units"), drop_units)
bp2 = purrr::map_if(bp1, ~ is(.x, "units"), drop_units)
lp2 %<>% bake(ep2, bp2, cs2, assert_units = FALSE)
purrr::map2(lp1, lp2[names(lp1)], function(.x, .y) {
dplyr::near(drop_units(.x), drop_units(.y))
}) %>%
purrr::map(expect_true)
C_chl = set_units(runif(1, 200, 400), umol/mol)
pars1 = c(cs1, lp1, ep1)
pars2 = purrr::map_if(pars1, function(x) is(x, "units"), drop_units)
Ad1 = A_demand(C_chl, pars1, unitless = FALSE)
Ad2 = A_demand(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(drop_units(Ad1), Ad2)
As1 = A_supply(C_chl, pars1, unitless = FALSE, use_legacy_version = FALSE)
As2 = A_supply(drop_units(C_chl), pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(drop_units(As1), As2)
gbc1 = drop_units(.get_gbc(pars1, "lower", unitless = FALSE, use_legacy_version = FALSE))
gbc2 = .get_gbc(pars2, "lower", unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gbc1, gbc2)
gbc3 = drop_units(.get_gbc(pars1, "upper", unitless = FALSE, use_legacy_version = FALSE))
gbc4 = .get_gbc(pars2, "upper", unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gbc3, gbc4)
gmc1 = drop_units(.get_gmc(pars1, "lower", unitless = FALSE))
gmc2 = .get_gmc(pars2, "lower", unitless = TRUE)
expect_equal(gmc1, gmc2)
gmc3 = drop_units(.get_gmc(pars1, "upper", unitless = FALSE))
gmc4 = .get_gmc(pars2, "upper", unitless = TRUE)
expect_equal(gmc3, gmc4)
gsc1 = drop_units(.get_gsc(pars1, "lower", unitless = FALSE))
gsc2 = .get_gsc(pars2, "lower", unitless = TRUE)
expect_equal(gsc1, gsc2)
gsc3 = drop_units(.get_gsc(pars1, "upper", unitless = FALSE))
gsc4 = .get_gsc(pars2, "upper", unitless = TRUE)
expect_equal(gsc3, gsc4)
gtc1 = drop_units(.get_gtc(pars1, unitless = FALSE, use_legacy_version = FALSE))
gtc2 = .get_gtc(pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gtc1, gtc2)
gtc3 = drop_units(.get_gtc(pars1, unitless = FALSE, use_legacy_version = FALSE))
gtc4 = .get_gtc(pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gtc3, gtc4)
guc1 = drop_units(.get_guc(pars1, "lower", unitless = FALSE))
guc2 = .get_guc(pars2, "lower", unitless = TRUE)
expect_equal(guc1, guc2)
guc3 = drop_units(.get_guc(pars1, "upper", unitless = FALSE))
guc4 = .get_guc(pars2, "upper", unitless = TRUE)
expect_equal(guc3, guc4)
FvCB1 = FvCB(C_chl, pars1, unitless = FALSE)
FvCB2 = FvCB(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(drop_units(FvCB1$A), FvCB2$A)
J1 = drop_units(J(pars1, unitless = FALSE))
J2 = J(pars2, unitless = TRUE)
expect_equal(J1, J2)
Wc1 = drop_units(W_carbox(C_chl, pars1, unitless = FALSE))
Wc2 = W_carbox(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wc1, Wc2)
Wr1 = drop_units(W_regen(C_chl, pars1, unitless = FALSE))
Wr2 = W_regen(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wr1, Wr2)
Wt1 = drop_units(W_tpu(C_chl, pars1, unitless = FALSE))
Wt2 = W_tpu(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wt1, Wt2)
})
test_that("unitless values match unit-ed values (tealeaves, old g_tc)", {
T_leaf = NA
while (is.na(T_leaf)) {
cs1 = make_constants(use_tealeaves = TRUE)
lp1 = leaf_par(list(
A_mes_A = set_units(numeric(0), 1),
abs_l = set_units(runif(1), 1),
abs_s = set_units(runif(1), 1),
delta_ias_lower = set_units(numeric(0), um),
delta_ias_upper = set_units(numeric(0), um),
g_liqc25 = set_units(numeric(0), mol/m^2/s),
g_mc25 = set_units(runif(1), mol/m^2/s),
g_sc = set_units(runif(1), mol/m^2/s),
g_uc = set_units(runif(1), mol/m^2/s),
gamma_star25 = set_units(runif(1, 30, 50), umol/mol),
J_max25 = set_units(runif(1, 50, 200), umol/m^2/s),
K_C25 = set_units(268.3, umol/mol),
K_O25 = set_units(165084.2, umol/mol),
k_mc = set_units(runif(1, 0.01, 100)),
k_sc = set_units(runif(1, 0.01, 100)),
k_uc = set_units(runif(1, 0.01, 100)),
leafsize = set_units(runif(1), m),
phi_J = set_units(0.331),
R_d25 = set_units(runif(1, 0, 5), umol/m^2/s),
theta_J = set_units(0.825),
V_cmax25 = set_units(runif(1, 50, 200), umol/m^2/s),
V_tpu25 = set_units(runif(1, 50, 200), umol/m^2/s)
), use_tealeaves = TRUE)
ep1 = enviro_par(list(
C_air = set_units(runif(1, 10, 2000), umol/mol),
E_q = set_units(220, kJ/mol),
f_par = set_units(runif(1), 1),
O = set_units(0.21, mol/mol),
P = set_units(101.3246, kPa),
r = set_units(runif(1), 1),
RH = set_units(runif(1)),
PPFD = set_units(runif(1, 0, 2000), umol/m^2/s),
T_air = set_units(runif(1, 273.15, 313.15), K),
T_sky = photosynthesis:::get_f_parameter("T_sky"),
wind = set_units(runif(1, 0, 20), m/s)
), use_tealeaves = TRUE)
bp1 = make_bakepar()
lp1 = photosynthesis:::add_Tleaf_photo(lp1, ep1, cs1, TRUE)
T_leaf = lp1$T_leaf
}
lp1 %<>% bake(ep1, bp1, cs1, assert_units = TRUE)
# Drop units
cs2 = purrr::map_if(cs1, function(x) is(x, "units"), drop_units)
lp2 = purrr::map_if(lp1, function(x) is(x, "units"), drop_units)
ep2 = purrr::map_if(ep1, function(x) is(x, "units"), drop_units)
bp2 = purrr::map_if(bp1, ~ is(.x, "units"), drop_units)
lp2 %<>% bake(ep2, bp2, cs2, assert_units = FALSE)
purrr::map2(lp1, lp2[names(lp1)], function(.x, .y) {
if (length(.x) == 0) {TRUE} else {dplyr::near(drop_units(.x), drop_units(.y))}
}) |>
purrr::map(expect_true)
C_chl = set_units(runif(1, 200, 400), umol/mol)
pars1 = c(cs1, lp1, ep1)
pars2 = purrr::map_if(pars1, function(x) is(x, "units"), drop_units)
Ad1 = A_demand(C_chl, pars1, unitless = FALSE)
Ad2 = A_demand(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(drop_units(Ad1), Ad2)
As1 = A_supply(C_chl, pars1, unitless = FALSE, use_legacy_version = FALSE)
As2 = A_supply(drop_units(C_chl), pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(drop_units(As1), As2)
gbc1 = drop_units(.get_gbc(pars1, "lower", unitless = FALSE, use_legacy_version = FALSE))
gbc2 = .get_gbc(pars2, "lower", unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gbc1, gbc2)
gbc3 = drop_units(.get_gbc(pars1, "upper", unitless = FALSE, use_legacy_version = FALSE))
gbc4 = .get_gbc(pars2, "upper", unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gbc3, gbc4)
gmc1 = drop_units(.get_gmc(pars1, "lower", unitless = FALSE))
gmc2 = .get_gmc(pars2, "lower", unitless = TRUE)
expect_equal(gmc1, gmc2)
gmc3 = drop_units(.get_gmc(pars1, "upper", unitless = FALSE))
gmc4 = .get_gmc(pars2, "upper", unitless = TRUE)
expect_equal(gmc3, gmc4)
gsc1 = drop_units(.get_gsc(pars1, "lower", unitless = FALSE))
gsc2 = .get_gsc(pars2, "lower", unitless = TRUE)
expect_equal(gsc1, gsc2)
gsc3 = drop_units(.get_gsc(pars1, "upper", unitless = FALSE))
gsc4 = .get_gsc(pars2, "upper", unitless = TRUE)
expect_equal(gsc3, gsc4)
gtc1 = drop_units(.get_gtc(pars1, unitless = FALSE, use_legacy_version = FALSE))
gtc2 = .get_gtc(pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gtc1, gtc2)
gtc3 = drop_units(.get_gtc(pars1, unitless = FALSE, use_legacy_version = FALSE))
gtc4 = .get_gtc(pars2, unitless = TRUE, use_legacy_version = FALSE)
expect_equal(gtc3, gtc4)
guc1 = drop_units(.get_guc(pars1, "lower", unitless = FALSE))
guc2 = .get_guc(pars2, "lower", unitless = TRUE)
expect_equal(guc1, guc2)
guc3 = drop_units(.get_guc(pars1, "upper", unitless = FALSE))
guc4 = .get_guc(pars2, "upper", unitless = TRUE)
expect_equal(guc3, guc4)
FvCB1 = FvCB(C_chl, pars1, unitless = FALSE)
FvCB2 = FvCB(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(drop_units(FvCB1$A), FvCB2$A)
J1 = drop_units(J(pars1, unitless = FALSE))
J2 = J(pars2, unitless = TRUE)
expect_equal(J1, J2)
Wc1 = drop_units(W_carbox(C_chl, pars1, unitless = FALSE))
Wc2 = W_carbox(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wc1, Wc2)
Wr1 = drop_units(W_regen(C_chl, pars1, unitless = FALSE))
Wr2 = W_regen(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wr1, Wr2)
Wt1 = drop_units(W_tpu(C_chl, pars1, unitless = FALSE))
Wt2 = W_tpu(drop_units(C_chl), pars2, unitless = TRUE)
expect_equal(Wt1, Wt2)
})
|