Skip to content

Conversation

dayantur
Copy link

@dayantur dayantur commented Oct 14, 2025

Problem

This PR proposes a solution for the problem discussed in #712 . In fact, different parameters arrays have different dimension requirements:

  • height: nlayer + 1 elements
  • veg_frac, veg_scale, building_frac, building_scale: nlayer elements
  • roofs, walls (in both vertical_layers and initial_states): nlayer elements with complex nested structures

No validation existed to detect these mismatches at configuration time, and currently (if nlayer user < nlayer standard config), the validator "fills up" the remaining dimensions with dummy values.

Main Changes

  • Updated orchestrator.py with detect_nlayer_from_user_yaml() to extract nlayer value from user configuration
  • Updated phase_a.py with validate_nlayer_dimensions() (core validation logic for all array types), create_null_roof_wall_template() (replicates complex nested roof/wall structures with null values), annotate_missing_parameters() and create_analysis_report().

Testing

Added comprehensive tests in test/data_model/test_validation.py.

Solution

Implemented Phase A validation that:

If nlayer user < nlayer sample config:

  1. Detects nlayer from user configuration automatically
  2. Validates dimensions of all vertical layer arrays against nlayer requirements
  3. Adds null placeholders to help users:
    - Simple arrays: pads with None values
    - Complex structures (roofs/walls): creates complete null template structures matching reference element
  4. Fails validation and generates clear, actionable reports asking users to replace nulls with actual values
  5. Writes updated YAML with padded arrays so users can fill in values

If nlayer user > nlayer sample config:

  1. Detects nlayer from user configuration automatically
  2. Validates dimensions of all vertical layer arrays against nlayer requirements
  3. Fails validation and generates clear, actionable reports asking users to remove values to match required array dimension

Report Format

Clear messages distinguish between array types and levels:

  - Found (3) vertical layer array dimension mismatch error(s):
  -- veg_frac: has 3 element(s), expected 4. Added nulls.
     Suggested fix: Replace 1 null value(s) to match nlayer=4
  -- roofs at level vertical_layers: has 3 element(s), expected 2
     Suggested fix: Remove 1 alb substructure to match nlayer=2
  -- walls at level initial_states: has 1 element(s), expected 2. Added nulls.
     Suggested fix: Replace null values.

dayantur and others added 2 commits October 14, 2025 11:13
This script generates SUEWS sample configuration files for different
nlayer values (1-7) by:
- Reading a base sample config file
- Updating the nlayer value
- Adjusting vertical layer arrays to match the new nlayer
- Updating roofs/walls arrays in properties and initial_states

The script will be used to maintain consistency across sample configs
and enable automated validation of nlayer-specific structures.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link

🤖 I've automatically formatted the code in this PR using:

  • Python: ruff v0.8.6
  • Fortran: fprettify v0.3.7

Please pull the latest changes before making further edits.

@dayantur dayantur changed the title Feature: standard sample config structure checked based on automatic nlayer value detection Feature: generalised standard sample config with nlayer Oct 14, 2025
@dayantur dayantur temporarily deployed to github-pages-preview October 15, 2025 10:33 — with GitHub Actions Inactive
Copy link

github-actions bot commented Oct 15, 2025

🔍 Schema Preview Deployed

Preview URLs:

Production URLs (unchanged):


⚠️ Important: Preview schemas are in a subdirectory and do not affect production. The preview pages include warning banners to prevent accidental use in production configs.

Copy link

🤖 I've automatically formatted the code in this PR using:

  • Python: ruff v0.8.6
  • Fortran: fprettify v0.3.7

Please pull the latest changes before making further edits.

@dayantur dayantur temporarily deployed to github-pages-preview October 15, 2025 10:42 — with GitHub Actions Inactive
Copy link

🤖 I've automatically formatted the code in this PR using:

  • Python: ruff v0.8.6
  • Fortran: fprettify v0.3.7

Please pull the latest changes before making further edits.

@dayantur dayantur temporarily deployed to github-pages-preview October 15, 2025 10:51 — with GitHub Actions Inactive
Copy link

🤖 I've automatically formatted the code in this PR using:

  • Python: ruff v0.8.6
  • Fortran: fprettify v0.3.7

Please pull the latest changes before making further edits.

@dayantur dayantur temporarily deployed to github-pages-preview October 15, 2025 11:19 — with GitHub Actions Inactive
@dayantur dayantur changed the title Feature: generalised standard sample config with nlayer Feature: validator checks parameters dimensions according to nlayer Oct 15, 2025
@dayantur dayantur self-assigned this Oct 15, 2025
@dayantur dayantur changed the title Feature: validator checks parameters dimensions according to nlayer Feature: validator checks and updates parameters according to nlayer Oct 15, 2025
@dayantur dayantur temporarily deployed to github-pages-preview October 15, 2025 12:27 — with GitHub Actions Inactive
Copy link

🤖 I've automatically formatted the code in this PR using:

  • Python: ruff v0.8.6
  • Fortran: fprettify v0.3.7

Please pull the latest changes before making further edits.

…mple-config' of https://github.com/UMEP-dev/SUEWS into dayantur/feature/validator/automatic-nlayer-standard-sample-config
@dayantur dayantur temporarily deployed to github-pages-preview October 15, 2025 12:28 — with GitHub Actions Inactive
@dayantur dayantur marked this pull request as ready for review October 15, 2025 12:29
@dayantur dayantur requested a review from sunt05 October 15, 2025 12:30
@dayantur
Copy link
Author

dayantur commented Oct 15, 2025

Hi @sunt05 - here a proposed solution for what we discussed in #712 .
Please have a look also at Details in the first comment/summary of this PR (see above).
This should (more elegantly) fix the issue - but I am obviously happy to discuss further/change whatever you think can be improved :D

Copy link

@sunt05 sunt05 left a comment

Choose a reason for hiding this comment

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

Question about :

This script appears to be unused in the codebase:

  • Not imported or referenced anywhere in the code
  • The generated files ( - ) don't exist in the repo
  • Only exists in

Was this a development/testing utility that was accidentally committed? If so, I'd suggest removing it from the PR to keep the repository clean.

If the script is intended for future use or documentation purposes, consider:

  1. Moving it to or directory
  2. Adding a README explaining its purpose
  3. Or converting it to a pytest fixture in

What was the intended use case for this script?

sunt05

This comment was marked as duplicate.

@dayantur
Copy link
Author

Question about generate_nlayer_configs.py:

This script appears to be unused in the codebase:

  • Not imported or referenced anywhere in the code
  • The generated files (sample_config_4.yml - sample_config_7.yml) do not exist in the repo
  • Only sample_config.yml exists in src/supy/sample_data/

Was this a development/testing utility that was accidentally committed? If so, I would suggest removing it from the PR to keep the repository clean.

If the script is intended for future use or documentation purposes, consider:

  1. Moving it to scripts/ or tools/ directory
  2. Adding a README explaining its purpose
  3. Or converting it to a pytest fixture in test/data_model/conftest.py

What was the intended use case for this script?

Sorry @sunt05 - that should be removed!

@sunt05
Copy link

sunt05 commented Oct 15, 2025

Thanks @dayantur ! Please see my comment above about the script at the root level.

@sunt05 sunt05 temporarily deployed to github-pages-preview October 15, 2025 13:22 — with GitHub Actions Inactive
Resolved CHANGELOG.md conflict by merging both:
- PR731's nlayer validation feature
- Master's recent UMEP/QGIS build improvements and other changes

Updated annual statistics: 36 features, 119 total entries for 2025

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@sunt05 sunt05 temporarily deployed to github-pages-preview October 15, 2025 20:28 — with GitHub Actions Inactive
Copy link

🤖 I've automatically formatted the code in this PR using:

  • Python: ruff v0.8.6
  • Fortran: fprettify v0.3.7

Please pull the latest changes before making further edits.

@sunt05 sunt05 self-requested a review October 16, 2025 12:56
Copy link

@sunt05 sunt05 left a comment

Choose a reason for hiding this comment

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

Review Summary

Excellent work on implementing automatic nlayer dimension validation! This PR addresses issue #712 comprehensively with a well-designed solution. All 5 new tests pass successfully.

Strengths

  1. Comprehensive validation logic: Correctly handles all array types (simple arrays, nlayer+1 arrays, and complex nested structures)
  2. Smart template generation: The create_null_roof_wall_template() function intelligently replicates complex nested structures for roofs/walls
  3. Clear error reporting: The report format clearly distinguishes between array types and provides actionable fix suggestions
  4. Excellent test coverage: 5 comprehensive tests covering all scenarios (simple arrays, multiple errors, complex structures, and no-error cases)
  5. Safe defaults: detect_nlayer_from_user_yaml() gracefully handles errors and defaults to 3

Minor Observations

  1. Code formatting change: get_ver_git.py has a formatting change (black/ruff auto-format) that's unrelated to the feature - this is fine but worth noting
  2. Silent error handling: detect_nlayer_from_user_yaml() silently defaults to 3 on all errors. This is probably fine, but consider if logging might help debugging in some cases
  3. RefValue handling: The code correctly handles both RefValue format ({"value": ...}) and direct values - well done on this complexity

Suggestions for Future Enhancement (not blocking)

  1. Consider adding a test that validates the actual error report format/content (checking the report string generation)
  2. The null template creation for roofs/walls is impressive - might be worth documenting this approach in code comments for future maintainers

Verdict

Approve - This PR is ready to merge. The implementation is solid, well-tested, and addresses the problem described in #712 effectively.

@dayantur dayantur temporarily deployed to github-pages-preview October 17, 2025 10:43 — with GitHub Actions Inactive
@dayantur dayantur temporarily deployed to github-pages-preview October 17, 2025 11:27 — with GitHub Actions Inactive
Copy link

🤖 I've automatically formatted the code in this PR using:

  • Python: ruff v0.8.6
  • Fortran: fprettify v0.3.7

Please pull the latest changes before making further edits.

@dayantur
Copy link
Author

hi @sunt05 :) This is just to let you know that after your (positive!) review, I found a tiny bug this morning - I already fixed that and now everything seems to work correctly.

@sunt05 sunt05 self-requested a review October 17, 2025 11:56
@sunt05
Copy link

sunt05 commented Oct 17, 2025

Thanks @dayantur - looks there is some conflict with master please fix then we can merge! Good job!

@dayantur dayantur merged commit 33aac67 into master Oct 17, 2025
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