Skip to content

fix(uncertainty): resolve SA median manifest lookup (#3882)#3906

Open
man080107 wants to merge 3 commits intoPecanProject:developfrom
man080107:fix/3882-sa-median-manifest-lookup
Open

fix(uncertainty): resolve SA median manifest lookup (#3882)#3906
man080107 wants to merge 3 commits intoPecanProject:developfrom
man080107:fix/3882-sa-median-manifest-lookup

Conversation

@man080107
Copy link
Copy Markdown
Contributor

@man080107 man080107 commented Mar 29, 2026

Summary

Fixes #3882 -
read.sa.output() was silently dropping the median (q50) run when using the manifest-based OAT sensitivity path.

Root Cause

write.sa.configs() writes a single shared median run with pft_name = "NA" and rait = "NA" in the manifest. However,
ead.sa.output() performed an exact per-trait/per-PFT lookup, so no row ever matched for the median quantile - the result was always NA, and the median was excluded from downstream sensitivity analyses.

Fix

Added a fallback in
ead.sa.output(): when quantile == "50" and no exact match is found, the function now searches for the shared NA/NA median entry before emitting a warning.

Changes

  • modules/uncertainty/R/sensitivity.R - fallback median lookup logic
  • modules/uncertainty/tests/testthat/test-read_sa_output_median.R - two regression tests:
    • positive: median row is correctly resolved via the fallback
    • negative: warns when neither exact match nor fallback entry exists
  • modules/uncertainty/NEWS.md - changelog entry

Testing

New tests added in est-read_sa_output_median.R covering both the happy path (fallback resolves correctly) and the error path (warning emitted when no match at all).

read.sa.output() performed a strict per-trait/per-PFT lookup, but
write.sa.configs() writes the median run as a single shared manifest
row with pft_name='NA' and trait='NA'. This mismatch caused the q50
cell to always be NA in sensitivity.output in the manifest-based OAT
SA path.

Fix: add a fallback in read.sa.output() -- when quantile == '50' and
no exact trait/PFT match is found, look up the shared median entry
(pft_name='NA', trait='NA') before issuing a warning. The manifest
format written by write.sa.configs() is unchanged.

Also adds two regression tests:
  - happy path: shared median row resolves correctly, no NA
  - negative: warns when neither exact nor fallback row exists

Fixes PecanProject#3882
@man080107
Copy link
Copy Markdown
Contributor Author

@dlebauer!!! please do quick review on it....

Copy link
Copy Markdown
Member

@dlebauer dlebauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic looks right to me. The fallback matches how write.sa.configs() stores the shared median run, and the regression tests test the failure mode.

Thank you for fixing this!

@dlebauer dlebauer enabled auto-merge April 9, 2026 04:42
@dlebauer
Copy link
Copy Markdown
Member

@man080107 Please check test failures

The regression test for issue PecanProject#3882 had two bugs:

1. The test passed PEcAn.utils::convert.expr('NPP') directly
   as the �ariable argument to read.sa.output(), but the function
   expects only the \.eqn sub-list (containing \
   and \). The full convert.expr() output has those fields
   one level deeper (\.eqn\), so variable\
   and variable\ were both NULL, causing read.output() to
   fail silently. Fix: append \.eqn to both call sites,
   matching how get.results.R passes the value in production.

2. The test creates real NetCDF files with ncdf4::nc_create() etc.,
   but ncdf4 was not listed in DESCRIPTION Suggests, so it would
   not be installed in CI. Fix: add ncdf4 to Suggests, and add the
   corresponding row to pecan_package_dependencies.csv so the
   'check for out-of-date dependencies files' CI step stays green.

Also replace the placeholder '<issue-number>' with 3882 in the
test file comment.

Fixes PecanProject#3882 (follow-up)
auto-merge was automatically disabled April 11, 2026 04:17

Head branch was pushed to by a user without write access

@man080107
Copy link
Copy Markdown
Contributor Author

@dlebauer !! now i think it is ready to merge

@man080107 man080107 requested a review from dlebauer April 11, 2026 12:00
@dlebauer dlebauer enabled auto-merge April 13, 2026 16:55
@dlebauer
Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manifest-based OAT sensitivity drops median row for shared SA-median run

2 participants