Skip to content

feat: add BoundaryNudgingLayer for regional-global blending#223

Open
AswaniSahoo wants to merge 2 commits into
openclimatefix:mainfrom
AswaniSahoo:feat/boundary-nudging
Open

feat: add BoundaryNudgingLayer for regional-global blending#223
AswaniSahoo wants to merge 2 commits into
openclimatefix:mainfrom
AswaniSahoo:feat/boundary-nudging

Conversation

@AswaniSahoo

Copy link
Copy Markdown
Contributor

Pull Request

Description

This PR adds BoundaryNudgingLayer, which blends regional predictions with global context at domain boundaries using a relaxation zone.

It builds on RegionalForecaster from #221 to support boundary conditioning for issue #3. The layer is opt-in and does not change behavior when disabled.

The layer includes:

  • Distance-based relaxation prior using haversine distance from region centroid
  • Learned MLP correction on top of the geometric prior
  • Smooth blending: alpha=0 at center (trust regional), alpha=1 at edges (trust global)
  • Integration into RegionalForecaster.forward() after the residual connection
  • Two new config fields: enable_nudging (default False), nudging_hidden_dim

Related to #3

How Has This Been Tested?

The following tests were added and run using pytest:

  • tests/test_regional_forecast.py
    • Nudging disabled does not change output (backward compat)
    • Nudging enabled with no global context produces valid output
    • Global context changes output when nudging is enabled
    • Relaxation weights are in [0, 1] with max at farthest point
    • Gradients flow through the nudging layer

Commands run:

  • .\.venv\Scripts\python.exe -m pytest tests/test_regional_forecast.py -v

    • 13 passed, 1 warning
  • .\.venv\Scripts\python.exe -m ruff check graph_weather/models/regional_forecast.py tests/test_regional_forecast.py

    • Passed

If your changes affect data processing, have you plotted any changes? i.e. have you done a quick sanity check?

  • Not applicable - no data processing changes

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

@AswaniSahoo

Copy link
Copy Markdown
Contributor Author

@jacobbieker This implements the boundary nudging approach we discussed on Issue #3 .

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.

1 participant