graph_weather icon indicating copy to clipboard operation
graph_weather copied to clipboard

feat: Add explicit input validation with clear error messages for model inputs

Open Raakshass opened this issue 10 months ago • 1 comments

Description

Adds explicit input validation with clear error messages for model inputs to address issue #190.

Previously, incorrect input tensor shapes caused cryptic runtime errors. This PR adds fail-fast validation at the API boundary for forward() methods using a new centralized validation utility.

Changes:

  • Add graph_weather/models/validation.py with centralized validation utilities
  • Update GraphWeatherForecaster.forward() to validate input shape
  • Update GraphWeatherAssimilator.forward() to validate input shape
  • Add comprehensive unit tests in tests/test_input_validation.py

Fixes #190

How Has This Been Tested?

Added comprehensive unit tests in tests/test_input_validation.py that verify:

  • Valid 3D tensors pass validation

  • Invalid 2D/1D/4D tensors raise ValueError with clear messages

  • Model imports work correctly

  • [x] Yes

  • [x] Yes (validation logic is pure shape checking, no data processing changes)

Checklist:

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

Raakshass avatar Feb 02 '26 20:02 Raakshass

The CI failure is due to pre-existing Ruff linting issues in files I didn't modify (aurora/, cafa/, anemoi_dataloader.py).

My changes to validation.py, forecast.py, analysis.py, and tests/test_input_validation.py are clean and follow the project's coding standards.

Happy to help fix these existing docstring issues in a separate PR if that would be helpful!

Raakshass avatar Feb 02 '26 20:02 Raakshass