Skip to content

feat: add SNFI volume prediction module with compressed RDA coefficients and automatic fallback - #20

Merged
Cidree merged 1 commit into
mainfrom
avv-new-predict-snfi-volume
Jun 20, 2026
Merged

feat: add SNFI volume prediction module with compressed RDA coefficients and automatic fallback#20
Cidree merged 1 commit into
mainfrom
avv-new-predict-snfi-volume

Conversation

@aitorvv

@aitorvv aitorvv commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR implements the SNFI tree volume prediction module for the silviculture package, satisfying the requirements of PR 5.

Key additions:

  • Consolidated approximately 90 raw CSV files of SNFI3 and SNFI4 coefficients into package-level .rda data files, compressed using .xz to optimize disk footprint (~380 KB).
  • Added scripts/regenerate_volume_models.R to provide a reproducible compilation pipeline from source data.
  • Implemented silv_predict_snfi_volume(), which accepts vectors of species, provinces, DBH, height, and qualities and returns a consistent dataframe containing the four volume components (vcc, vsc, iavc, vle). It automatically falls back to SNFI3 parameters for provinces that do not have SNFI4 equations.
  • Implemented silv_snfi_provinces() and silv_snfi_species() to allow users to inspect available parameters directly in memory.
  • Created tests/testthat/test-predict-snfi-volume.R executing comprehensive combination checks (covering species, quality levels, and province lookup pathways).
  • Cleaned all non-ASCII character warnings in R/predict-snfi-volume.R and updated dataset documentation in R/data.R to comply with CRAN checks.

Verification

# Inspect new/modified datasets and check documentation definitions
devtools::load_all()
str(snfi3_volume_coefficients)   # 37730 rows x 16 cols
str(snfi4_volume_coefficients)   # 20925 rows x 15 cols
# Check documentation descriptions for F.c., Parametro, and D.n.m.
?snfi3_volume_coefficients
?snfi4_volume_coefficients

# Test public listing functions
head(silv_snfi_provinces())      # Shows province_id, province_name, snfi_version
head(silv_snfi_species("SNFI4")) # Shows species codes and names

# Verify prediction function with single tree (Pinus radiata in Álava)
res_single <- silv_predict_snfi_volume(
  province = 1,
  species  = 28,
  dbh      = 25,
  h        = 18
)
print(res_single)
# Expected structure: 1 row, columns: vcc, vsc, iavc, vle, snfi_version (SNFI4)

# Verify automatic fallback to SNFI3 for Cantabria (province 39)
res_fallback <- silv_predict_snfi_volume(
  province = c(1, 3),
  species  = c(28, 28),
  dbh      = c(25, 30),
  h        = c(18, 20)
)
print(res_fallback)
# Expected: row 1 uses SNFI4, row 2 falls back to SNFI3

@Cidree
Cidree merged commit 7957307 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