How ashiklom/rrtm works
1. What this repository is
- rrtm is an R package for vegetation radiative transfer modeling. Its core purpose is to compute wavelength-resolved reflectance/transmittance spectra for leaves, canopies, and soils, and to combine those into higher-level remote-sensing models.
2. Primary user-facing layer
- The main API lives in R/*.R and is exported through NAMESPACE.
- Key entry points include prospect*, foursail, pro4sail_*, liberty, gpm, edr, hapke_soil, and spectral-response helpers. These are the functions a caller uses directly from R.
3. Model subsystem boundaries
- The code is organized by physical model rather than by application layer.
- Leaf optics are handled by PROSPECT-family code; canopy radiative transfer is handled by SAIL/4SAIL; soil/background reflectance is handled by Hapke-based logic; additional vegetation models include LIBERTY, GPM, and EDR-related routines.
4. Composition of models into end-to-end workflows
- The package’s main architectural pattern is model chaining: leaf spectra feed canopy scattering/transfer models, which then combine with soil/background reflectance.
- The README’s pro4sail_5() example illustrates this: PROSPECT-derived leaf spectra are coupled with 4SAIL canopy calculations and a soil model to produce multiple directional reflectance outputs.
5. Compiled numerical core
- The src/ directory contains the C++ implementation, with solvearray.cpp as the main compiled numerical routine and RcppExports.cpp/RcppExports.R providing the R-to-C++ bridge.
- This is the package’s performance boundary: higher-level model orchestration is in R, while the heavy numerical solving is pushed into compiled code.
6. Shared utilities and internal math
- R/utils.R, R/lidf.R, R/sail-volscatt.R, and related files hold reusable mathematical helpers and geometry/scattering calculations.
- These functions support multiple models rather than representing separate public workflows.
7. Data and parameter assets
- The package ships with precomputed/internal datasets in data/ and sysdata.rda, including sensor response data.
- extdata/ contains fixed reference tables used by models, such as soil and wood reflectance files.
8. Data preparation pipeline
- data-raw/ is the reproducible source for generated package data.
- Scripts there convert raw spectra, sensor descriptions, and reference tables into packaged .RData assets, separating ingestion/preprocessing from runtime model execution.
9. Validation and regression coverage
- tests/testthat/ contains model-specific tests for PROSPECT, LIBERTY, EDR, SAIL, spectral response, and an integration-style pecanrtm test.
- This indicates the package is validated both at the individual model level and across model combinations.
10. Documentation and reproducibility surface
- README.Rmd, the generated README.md, man/ Rd files, and the vignettes/inversion.Rmd vignette form the main documentation layer.
- The vignette suggests at least one higher-level workflow around parameter inversion, not just forward simulation.
11. Build and quality tooling
- The package uses standard R package tooling plus compiled-code build files (src/Makevars, src/Makevars.win).
- CI is run via GitHub Actions (.github/workflows/R-CMD-check.yaml), and .lintr indicates linting/static style checks are part of the repo’s quality boundary.
12. Likely architectural diagram framing
- A useful diagram would show: external user input parameters and sensor/soil reference data on the left; R model modules in the center; compiled C++ solver underneath as the performance layer; packaged datasets as a supporting store; and outputs as spectra/reflectance products returned to R callers.
Main entry points: NAMESPACE R API · testthat Tests · prosail.R PRO4SAIL · prospect.R PROSPECT
Components 16
R models
Public R-facing model layer and shared helpers
- R API · Main user-facing entry points exported through NAMESPACE
NAMESPACE - PROSPECT · Leaf reflectance/transmittance family
R/prospect.R - 4SAIL · Canopy scattering and transfer model
R/foursail.R - PRO4SAIL · Chains leaf and canopy models into end-to-end spectra
R/prosail.R - Hapke soil · Soil and background reflectance model
R/hapke-soil.R - Other veg models · LIBERTY, GPM, and EDR-related model routines
R/liberty.R - Shared math · Reusable utilities, leaf angle, and scattering math
R/utils.R - Spectral response · Sensor response and band integration helpers
R/spectral-response.R
Native core
Compiled numerical boundary
- Rcpp bridge · R-to-C++ bindings generated by Rcpp
R/RcppExports.R - Solve core · Compiled numerical routine for heavy radiative-transfer calculations
src/solvearray.cpp
Data assets
Packaged reference data and generation sources
- Package data · Bundled internal datasets such as sensor responses
R/sysdata.rda - Reference tables · External data files for soil, wood, and other references
extdata/hapke-soil.dat - Data prep · Reproducible scripts that build packaged data from raw sources
data-raw/dataspec.R
Connections 23
- R API → PROSPECT: exports · User calls reach leaf optics functions
- R API → 4SAIL: exports · User calls reach canopy model functions
- R API → PRO4SAIL: exports · User calls reach composition workflows
- R API → Hapke soil: exports · User calls reach soil reflectance functions
- R API → Other veg models: exports · User calls reach auxiliary vegetation models
- R API → Spectral response: exports · User calls reach spectral-response helpers
- PRO4SAIL → PROSPECT: uses · PRO4SAIL chains leaf spectra into canopy simulation
- PRO4SAIL → 4SAIL: uses · PRO4SAIL combines canopy transfer calculations
- PRO4SAIL → Hapke soil: uses · PRO4SAIL incorporates soil/background reflectance
- PROSPECT → Shared math: shares math · Leaf optics reuse shared numerical helpers
- 4SAIL → Shared math: shares math · Canopy model reuses geometry and scattering helpers
- Spectral response → Package data: loads · Sensor response helpers consume packaged response curves
- Data prep → Package data: builds · Data-raw scripts generate packaged RData assets
- Data prep → Reference tables: converts · Raw preparation ingests fixed reference tables
- Rcpp bridge → Solve core: bridges to · Rcpp exports call the compiled solver
- PROSPECT → Rcpp bridge: computes via · Leaf model delegates heavy numerics to native code
- 4SAIL → Rcpp bridge: computes via · Canopy model delegates heavy numerics to native code
- Tests → PROSPECT: covers · Tests exercise PROSPECT family behavior
- Tests → 4SAIL: covers · Tests exercise canopy scattering behavior
- Tests → Spectral response: covers · Tests exercise spectral response behavior
- Tests → Other veg models: covers · Tests exercise auxiliary model behavior
- Docs → PRO4SAIL: documents · README and vignette explain composed workflows
- CI/Lint → Tests: runs · CI executes package validation tests