data.land: prepare_pools fails to calculate woody biomass from TotLivBiom when AbvGrndWood is present without coarse roots

Open Beginner friendly
#4,243 3 comments 0 reactions 0 assignees View on GitHub

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
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
data

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):

  1. Execution enters else if (is.valid(AbvGrndWood)) at line 90.
  2. Because coarse.roots is not valid, it hits the else block at line 94, which logs:
    "prepare_pools can't calculate total woody biomass with only AbvGrndWood; checking for total biomass."
  3. However, because the total biomass check is an else if (is.valid(TotLivBiom)...) at line 96, it is mutually exclusive with else if (is.valid(AbvGrndWood)).
  4. As a result, the code exits the conditional chain without ever checking TotLivBiom, leaving $wood completely 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PecanProject/pecan

All issues in PecanProject/pecan

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.