-
Notifications
You must be signed in to change notification settings - Fork 287
Fix input sampling validation and SIPNET IC handling #3498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mdietze
merged 23 commits into
PecanProject:develop
from
blesson-07:fix/input-sampling-validation
May 30, 2025
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c94077d
Add files via upload
blesson-07 6f09efe
Merge branch 'PecanProject:develop' into develop
blesson-07 6d1e32c
Merge branch 'PecanProject:develop' into develop
blesson-07 9519f47
Merge branch 'PecanProject:develop' into develop
blesson-07 e4d0284
Fix input sampling validation
7026682
Improve pkgdown build process and fix documentation generation
divine7022 6056493
Fixed the missing separator issue by replacing space indentation with…
divine7022 a3978f3
Removed the redundant document target from .PHONY, as it was listed t…
divine7022 385d398
Updated package documentation setup: modified .github/workflows/pkgdo…
divine7022 43483e2
changed according to the review
df75210
added test file
blesson-07 1ff2168
Delete wait
blesson-07 495614a
Added previous test file in the correct place
blesson-07 aebdcf3
Update dependencies and add the package detection codes.
38a17e0
changed the Indentation
blesson-07 7e460a7
added incomplete test file
blesson-07 159dd70
updated test
blesson-07 e4d6adc
Update modules/uncertainty/tests/testthat/test_ensemble.R
mdietze 49dd66a
Update modules/data.remote/DESCRIPTION
mdietze 124a884
Update docker/depends/pecan_package_dependencies.csv
mdietze d16fd19
updated pecan package dependencies
blesson-07 8b523a9
removed lib imports
blesson-07 6a73c75
Revert "Improve pkgdown build process and fix documentation generation"
blesson-07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| library(testthat) | ||
| library(mockery) | ||
blesson-07 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Source the ensemble config function | ||
|
|
||
| context("input validation for write.ensemble.configs") | ||
|
|
||
| # Mock a model write.configs function to avoid model-specific errors | ||
| write.configs.SIPNET <- function(...) TRUE | ||
|
|
||
| # Helper: make input with correct structure | ||
| make_input_sets <- function(paths) { | ||
| lapply(paths, function(p) list(path = p)) | ||
| } | ||
|
|
||
| # Helper: make ensemble.samples with the correct structure | ||
| make_samples <- function(samples) { | ||
| lapply(paths, function(p) list(path = p)) | ||
| } | ||
|
|
||
| # 1. One input, no samples → should pass | ||
| test_that("1 input, no samples: passes", { | ||
| settings <- list(run = list(inputs = list(input = list(path = "IC1")))) | ||
| ensemble.samples <- NULL | ||
| defaults <- list() | ||
|
|
||
| expect_silent(write.ensemble.configs( | ||
| defaults = defaults, | ||
| ensemble.samples = ensemble.samples, | ||
| settings = settings, | ||
| model = "SIPNET", | ||
| write.to.db = FALSE | ||
| )) | ||
| }) | ||
|
|
||
|
|
||
|
|
||
| test_that("no input error", { | ||
| settings <- list(run = list(inputs = list(input = NULL))) | ||
| ensemble.samples <- NULL | ||
| defaults <- list() | ||
|
|
||
| # Capture logger message | ||
| expect_silent(write.ensemble.configs( | ||
| defaults = defaults, | ||
| ensemble.samples = ensemble.samples, | ||
| settings = settings, | ||
| model = "SIPNET", | ||
| write.to.db = FALSE | ||
| )) | ||
| }) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| test_that("multiple inputs and multiple samples", { | ||
| # Mock the SIPNET config writer | ||
| mockery::stub(write.ensemble.configs, "write.config.SIPNET", function(...) TRUE) | ||
|
|
||
| # Create temp directories | ||
| temp_rundir <- tempfile() | ||
| temp_modeloutdir <- tempfile() | ||
| dir.create(temp_rundir) | ||
| dir.create(temp_modeloutdir) | ||
| on.exit({ | ||
| unlink(temp_rundir, recursive = TRUE) | ||
| unlink(temp_modeloutdir, recursive = TRUE) | ||
| }, add = TRUE) | ||
|
|
||
| # Complete settings | ||
| settings <- list( | ||
| run = list( | ||
| inputs = list(input = list(path = "IC1")), | ||
| site = list(id = 1, name = "Test Site"), | ||
| start.date = "2000-01-01", | ||
| end.date = "2000-12-31", | ||
| outdir = temp_modeloutdir | ||
| ), | ||
| ensemble = list(size = 5), | ||
| database = NULL, | ||
| rundir = temp_rundir, | ||
| modeloutdir = temp_modeloutdir, | ||
| host = list( | ||
| rundir = temp_rundir, | ||
| outdir = temp_modeloutdir | ||
| ), | ||
| model = list(id = "SIPNET", type = "SIPNET"), | ||
| pfts = list( | ||
| list(name = "temperate", | ||
| constants = list(1), | ||
| posteriorid = 1) | ||
| ) | ||
| ) | ||
|
|
||
| # Sample parameters | ||
| ensemble.samples <- list( | ||
| temperate = data.frame( | ||
| SLA = c(15.2, 16.8, 14.7, 18.1, 17.5), | ||
| Vm0 = c(45.0, 50.3, 47.8, 49.1, 51.0) | ||
| ) | ||
| ) | ||
|
|
||
| # Default PFT settings | ||
| defaults <- list( | ||
| list( | ||
| name = "temperate", | ||
| constants = list(1), | ||
| posteriorid = 1 | ||
| ) | ||
| ) | ||
|
|
||
| # Run test - should create directories and configs | ||
| result <- expect_silent( | ||
| write.ensemble.configs( | ||
| defaults = defaults, | ||
| ensemble.samples = ensemble.samples, | ||
| settings = settings, | ||
| model = "SIPNET", | ||
| write.to.db = FALSE | ||
| ) | ||
| ) | ||
|
|
||
| # Verify outputs | ||
| expect_type(result, "list") | ||
| expect_named(result, c("runs", "ensemble.id", "samples")) | ||
| expect_equal(nrow(result$runs), settings$ensemble$size) | ||
| }) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.