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

Aperta Adatta ai principianti
#4,243 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@coder-Yash886 ci sta già lavorando.

Dal 14/11/2026.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
r
Ambito
data

Direzione di ricerca

Leggi la catena condizionale intorno alle righe 90-96 di modules/data.land/R/prepare_pools.R, poi riproduci con pool_ic_list2netcdf() e prepare_pools() come nel report per confermare che $wood è NULL nel Caso 1. La modifica consiste nel proteggere il ramo AbvGrndWood con is.valid(coarse.roots) in modo che venga raggiunto il ramo TotLivBiom. Fatto quando l'esempio del Caso 1 restituisce $wood = 8 e i test del pacchetto sotto modules/data.land/tests continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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)
Lingua principale
R
Stelle
246
Fork
322
Merge medio
4g 15h
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PecanProject/pecan

Tutte le issue di PecanProject/pecan

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.