Skip to content

feat: implement Stand Density Index (SDI) autoselector and classification#26

Open
aitorvv wants to merge 3 commits into
mainfrom
avv-sdi-autoselector
Open

feat: implement Stand Density Index (SDI) autoselector and classification#26
aitorvv wants to merge 3 commits into
mainfrom
avv-sdi-autoselector

Conversation

@aitorvv

@aitorvv aitorvv commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR implements the automated selector for Reineke's Stand Density Index (SDI) and the maximum stand density classification, matching the library patterns established in the biomass predictors.

Key Changes:

  • silv_density_sdi_auto(): Dynamically retrieves the correct beta exponent from the sdi_coefficients dataset using a cascading fallback system (exact match -> country -> genus -> default Reineke -1.605).
  • Automated SDImax & Model Info: Integrates maximum density estimates via the internal sdimax_models dataset. The output data.frame now always includes the computed sdimax and the string descriptor sdimax_model (e.g. rodriguez-prado-2020 (Spain, basic)).
  • Classification (classify = TRUE): Enables qualitative density classes based on the relative density thresholds.
  • _pkgdown.yml: Registered silv_density_sdimax and sdimax_models in the documentation references.
  • Tests: Expanded suite test-stand-density.R to cover the fallback mechanisms, models, and outputs.

Verification

You can copy and paste the following R code to verify the changes:

devtools::load_all()

# 1. Verify datasets
str(sdi_coefficients)
str(sdimax_models)

# 2. Verify SDI Autoselector & Fallbacks
res1 <- silv_density_sdi_auto(
  ntrees = 800,
  dg = 23.4,
  species = "Pinus sylvestris",
  country = "Spain",
  region = "Castilla y León"
)
# Expected: beta = -1.75, sdi_model = "del-rio-2006 (Spain, Castilla y León)", sdimax_model = "rodriguez-prado-2020 (Spain, basic)"
print(res1)

# 3. Verify SDI Autoselector with fallback to Reineke default
res2 <- silv_density_sdi_auto(
  ntrees = 800,
  dg = 23.4,
  species = "Unknown species"
)
# Expected: beta = -1.605, sdi_model = "reineke-1933 (-1.605)"
print(res2)

# 4. Verify Classification and Climate models
res3 <- silv_density_sdi_auto(
  ntrees = 800,
  dg = 23.4,
  species = "Pinus canariensis",
  classify = TRUE,
  climatic_model = "P1",
  clim_value = 400
)
# Expected: sdimax_model = "rodriguez-prado-2020 (Spain, P1)", sdi_class should be computed.
print(res3)

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