Skip to content

feat: add silv_predict_biomass_auto and silv_predict_biomass_components - #18

Merged
Cidree merged 7 commits into
mainfrom
avv-new-biomass-auto-components
Jun 20, 2026
Merged

feat: add silv_predict_biomass_auto and silv_predict_biomass_components#18
Cidree merged 7 commits into
mainfrom
avv-new-biomass-auto-components

Conversation

@aitorvv

@aitorvv aitorvv commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

This PR implements two new features for predictive biomass modelling:

  1. silv_predict_biomass_auto(): automatically selects the best available model per species/component based on priority tables, with automatic fallback to montero-2005 (which doesn't require height) if tree height is NULL, NA, or 0.
  2. silv_predict_biomass_components(): returns a wide-format data frame containing predicted weights for all pure structural components (stem, bark, branches, roots, etc.) for each tree. It also implements AGB/BGB capitalization consistency and species support validation.
  3. Bugfix in core silv_predict_biomass() to prevent returning empty lists/NULLs when height = NULL is supplied.

Verification

# Inspect new/modified datasets
devtools::load_all()

# 1. Verify auto priority model selection (Pinus pinaster with height -> ruiz-peinado-2011)
silv_predict_biomass_auto("Pinus pinaster", 20, 12, component = "tree")

# 2. Verify height fallback (height is NULL -> forces montero-2005)
silv_predict_biomass_auto("Pinus pinaster", 20, NULL, component = "tree")

# 3. Verify component calculation with uppercase column names
silv_predict_biomass_components(
  species = "Fagus sylvatica",
  diameter = 2,
  height = 3,
  model_fn = eq_biomass_menendez_2022,
  rcd = 2
)

# 4. Verify early abort for unsupported species
try(silv_predict_biomass_components(
  species = "Quercus petraea",
  diameter = 25,
  height = 15,
  model_fn = eq_biomass_ruiz_peinado_2012
))

aitorvv added 7 commits May 17, 2026 11:03
- Add rcd and bp parameters to silv_predict_biomass(); rcd defaults to
  diameter when not provided, bp defaults to NA_real_
- Replace model-specific dispatch (ruiz-peinado only) with universal
  calc_biomass() inner function using eval_env = list(d,h,rcd,bp);
  now all 7 allometric models work out of the box
- Add return_rmse / return_r2 handling inside calc_biomass()
- Fix eq_biomass_cudjoe_2024() returning equation = 'cudjoe-2017' instead
  of 'cudjoe-2024'

Documentation (Roxygen2):
- silv_predict_biomass(): add @param rcd/@param bp; @details lists all 7
  models with input-variable requirements (rcd/bp for menendez-2022)
- eq_biomass_ruiz_peinado_2011(): add explicit softwood species list (10)
  and component hierarchy (AGB/BGB -> structural groups -> components)
- eq_biomass_ruiz_peinado_2012(): add explicit hardwood species list (13)
  and component hierarchy; fix missing comma in @Seealso
- eq_biomass_dieguez_aranda_2009(): rewrite @details with consistent
  format; fix typo 'Pinaster radiata' -> 'Pinus radiata'
- eq_biomass_montero_2005(): replace 'There are 35 species' with explicit
  bulleted species list; add component hierarchy; fix @Seealso comma
- eq_biomass_manrique_2017(): rewrite @details in structured format; fix
  'thin branches' -> 'small branches' to match biomass_models column
- eq_biomass_menendez_2022(): correct species count 15 -> 18 + 3
  functional groups; add non-standard input note (rcd/bp)
- eq_biomass_cudjoe_2024(): rewrite @details in structured format; fix
  'brances' typo in component name

README.md:
- Add 'Suggested companion reading' section with poster DOI
  https://doi.org/10.13140/RG.2.2.28098.75205

inst/references.bib:
- Resolve unresolved merge conflict: keep menendez-2022 and cudjoe-2024
  entries (HEAD), discard palahi-2003 (other branch)
- Add poster BibTeX entry (vazquez-veloso_poster_2025)
…issing BGB and total tree components and update Roxygen2 docs
@Cidree
Cidree merged commit f65b6df into main Jun 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants