data.land: prepare_pools fails to calculate woody biomass from TotLivBiom when AbvGrndWood is present without coarse roots
Maintainers usually reply within 1 day
@coder-Yash886 is already working on this.
Since Nov 14, 2026.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 82/100
Research direction
Read the conditional chain around lines 90-96 of modules/data.land/R/prepare_pools.R, then reproduce with pool_ic_list2netcdf() and prepare_pools() as in the report to confirm $wood is NULL in Case 1. The change is to guard the AbvGrndWood branch with is.valid(coarse.roots) so the TotLivBiom branch is reached. Done when the Case 1 example returns $wood = 8 and the package tests under modules/data.land/tests still pass.
Written by the indexing model from the issue text.
Description
Bug Description
In PEcAn.data.land::prepare_pools(), there is a control-flow bug when attempting to calculate the initial woody biomass pool (IC.params[["wood"]]).
Lines 90–96 of modules/data.land/R/prepare_pools.R:
} else if (is.valid(AbvGrndWood)) {
if (is.valid(coarse.roots)) {
IC.params[["wood"]] <- (AbvGrndWood + coarse.roots)
} else {
PEcAn.logger::logger.error("prepare_pools can't calculate total woody biomass with only AbvGrndWood; checking for total biomass.")
}
} else if (is.valid(TotLivBiom) && is.valid(leaf) && is.valid(fine.roots)) {
wood <- (TotLivBiom - leaf - fine.roots)
When an IC file contains TotLivBiom, leaf_carbon_content, fine_root_carbon_content, and AbvGrndWood (but lacks coarse_root_carbon_content):
- Execution enters
else if (is.valid(AbvGrndWood))at line 90. - Because
coarse.rootsis not valid, it hits theelseblock at line 94, which logs:
"prepare_pools can't calculate total woody biomass with only AbvGrndWood; checking for total biomass." - However, because the total biomass check is an
else if (is.valid(TotLivBiom)...)at line 96, it is mutually exclusive withelse if (is.valid(AbvGrndWood)). - As a result, the code exits the conditional chain without ever checking
TotLivBiom, leaving$woodcompletely uncalculated (NULL), despite having all necessary data to compute it (TotLivBiom - leaf - fine.roots).
Paradoxically, removing AbvGrndWood from the IC file causes prepare_pools() to calculate $wood successfully, but supplying AbvGrndWood causes the calculation to fail.
Steps to Reproduce
Run the following in R:
out <- tempdir()
# Case 1: Input file with TotLivBiom, leaf, fine roots, AND AbvGrndWood (no coarse roots)
list(
vals = list(leaf_carbon_content = 1, fine_root_carbon_content = 1, TotLivBiom = 10, AbvGrndWood = 5),
dims = list(time = 1)
) |> PEcAn.data.land::pool_ic_list2netcdf(outdir = out, siteid = 1)
PEcAn.data.land::prepare_pools(file.path(out, "IC_site_1.nc"), constants = list())
# 2026-11-14 15:28:19 ERROR [PEcAn.data.land::prepare_pools] :
# prepare_pools can't calculate total woody biomass with only AbvGrndWood; checking for total biomass.
# $leaf
# [1] 1
# $fine.roots
# [1] 1
# Note: $wood is NULL / missing!
# Case 2: Exact same input file, but omitting AbvGrndWood
list(
vals = list(leaf_carbon_content = 1, fine_root_carbon_content = 1, TotLivBiom = 10),
dims = list(time = 1)
) |> PEcAn.data.land::pool_ic_list2netcdf(outdir = out, siteid = 2)
PEcAn.data.land::prepare_pools(file.path(out, "IC_site_2.nc"), constants = list())
# $leaf
# [1] 1
# $wood
# [1] 8
# $fine.roots
# [1] 1
Expected Behavior
When AbvGrndWood is provided without coarse.roots, prepare_pools should fall through to check TotLivBiom (as indicated by the log message "checking for total biomass.") and compute $wood = TotLivBiom - leaf - fine.roots (yielding 8 in the example above).
Proposed Fix
Change line 90 so that the AbvGrndWood branch only matches when both AbvGrndWood and coarse.roots are valid, allowing the TotLivBiom branch to be evaluated when coarse.roots is missing:
- } else if (is.valid(AbvGrndWood)) {
- if(is.valid(coarse.roots)){
- IC.params[["wood"]] <- (AbvGrndWood + coarse.roots)
- } else{
- PEcAn.logger::logger.error("prepare_pools can't calculate total woody biomass with only AbvGrndWood; checking for total biomass.")
- }
+ } else if (is.valid(AbvGrndWood) && is.valid(coarse.roots)) {
+ IC.params[["wood"]] <- (AbvGrndWood + coarse.roots)
- Dominant language
- R
- Stars
- 246
- Forks
- 322
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 15
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PecanProject/pecan
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PecanProject/pecan#4255 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PecanProject/pecan#4254 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PecanProject/pecan#4253 · 2 comments ·
Maintainers usually reply within 1 day
-
Annual NetCDF merge writes values to the wrong ensemble members and timestepsPossibly taken @ANAMASGARD claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
PecanProject/pecan#4251 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PecanProject/pecan#4236 ·
Maintainers usually reply within 1 day
All issues in PecanProject/pecan
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
OHDSI/PhenotypeR#728 ·
-
DataSet inherits from DotNetWrapper but has no .NET pointer, so NetObject methods failPossibly taken @PavelBal claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Open-Systems-Pharmacology/OSPSuite-R#2076 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
rfordatascience/tidytuesday#1105 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Huber-group-EMBL/remart#17 · 1 comment ·
-
teaching-followup
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Openscapes/kyber#197 ·