Skip to content

Fix spatial loss map step labeling - #752

Open
vikramsingh920 wants to merge 9 commits into
mllam:mainfrom
vikramsingh920:fix-747-spatial-loss-labels
Open

vikramsingh920 wants to merge 9 commits into
mllam:mainfrom
vikramsingh920:fix-747-spatial-loss-labels

Conversation

@vikramsingh920

Copy link
Copy Markdown

Describe your changes

Fixes an issue where out-of-range values in val_steps_to_log could cause
spatial loss maps to be associated with the wrong forecast steps.

< Summary of the changes.>

Updated test_step to keep track of the filtered evaluation steps and use them
when generating spatial loss map titles and PDF filenames. Added a regression
test to verify that out-of-range steps are skipped and valid steps are labeled
correctly.

< Please also include relevant motivation and context. >

When val_steps_to_log contains steps outside the test rollout length, those
steps are filtered out when calculating the spatial loss. However, the original
val_steps_to_log was still used when labeling and saving the loss maps. This
could cause the loss maps to be associated with the wrong forecast steps and
PDF filenames.

< List any dependencies that are required for this change. >
No new dependencies are required.

Issue Link

fixes #747
< Link to the relevant issue or task, if applicable > (e.g. closes #00 or solves #00)

Type of change

  • [✅] 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 Documentation (Addition or improvements to documentation)

Checklist before requesting a review

  • My branch is up-to-date with the target branch - if not update your fork with the changes from the target branch (use pull with --rebase option if possible).
  • [✅] I have performed a self-review of my code
  • [✅] For any new/modified functions/classes I have added docstrings that clearly describe its purpose, expected inputs and returned values
  • I have placed in-line comments to clarify the intent of any hard-to-understand passages of my code
  • I have updated the README to cover introduced code changes
  • [✅] I have added tests that prove my fix is effective or that my feature works
  • [✅] I have given the PR a name that clearly describes the change, written in imperative form (context).
  • I have requested a reviewer and an assignee (assignee is responsible for merging). This applies only if you have write access to the repo, otherwise feel free to tag a maintainer to add a reviewer and assignee.

Checklist for reviewers

Each PR comes with its own improvements and flaws. The reviewer should check the following:

  • the code is readable
  • the code is well tested
  • the code is documented (including return types and parameters)
  • the code is easy to maintain

Author checklist after completed review

  • [✅] I have added a line to the CHANGELOG describing this change, in a section
    reflecting type of change (add section where missing):
    • added: when you have added new functionality
    • changed: when default behaviour of the code has been changed
    • fixes: when your contribution fixes a bug
    • maintenance: when your contribution is relates to repo maintenance, e.g. CI/CD or documentation

Checklist for assignee

  • PR is up to date with the base branch
  • the tests pass
  • (if the PR is not just maintenance/bugfix) the PR is assigned to the next milestone. If it is not, propose it for a future milestone.
  • author has added an entry to the changelog (and designated the change as added, changed, fixed or maintenance)
  • Once the PR is ready to be merged, squash commits and merge the PR.

@GiGiKoneti

GiGiKoneti commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Thanks @vikramsingh920. The core synchronization via _test_spatial_steps and the regression test look good, but a few items need fixing:

  1. Revert unrelated files: Please revert neural_lam/config.py and neural_lam/train_model.py (add_safe_globals is out of scope for [Bug] Spatial loss map titles and saved PDFs mislabeled in on_test_epoch_end when val_steps_to_log contains out-of-range steps #747).
  2. Fix ty type checking error in neural_lam/models/module.py (lines 890–893): Line 891 self.logger.save_dir fails ty because the ignore comment was placed on line 892 (exist_ok=True,). If directory creation was only needed for the test fixture, create the directory in the test instead of modifying create_metric_log_dict.
  3. Guard lower bound in test_step: Use 1 <= step <= spatial_loss.shape[1] instead of step <= spatial_loss.shape[1] to prevent non-positive steps (0, -1) from silently slicing from the end via negative indexing in programmatic setups.
  4. Rebase after Reject step < 1 in --*_steps_to_log and --var_leads_metrics_watch #746: Per @sadamov's note in [Bug] Spatial loss map titles and saved PDFs mislabeled in on_test_epoch_end when val_steps_to_log contains out-of-range steps #747, please rebase on main once Reject step < 1 in --*_steps_to_log and --var_leads_metrics_watch #746 lands.
  5. Clean up diff: Please revert the tuple unpacking change in tests/test_plotting.py:558.

cc : @sadamov

@vikramsingh920

Copy link
Copy Markdown
Author

Thanks for the review @GiGiKoneti. I have addressed the points in the latest push:

  1. Reverted neural_lam/config.py and neural_lam/train_model.py.
  2. Fixed the ty error by creating the directory inside the test fixture rather than create_metric_log_dict.
  3. Added the 1 <= step <= spatial_loss.shape[1] lower-bound guard in test_step and expanded regression test coverage to include non-positive steps (-1, 0).
  4. Reverted the tuple unpacking syntax in tests/test_plotting.py:558.
  5. Will rebase on main once Reject step < 1 in --*_steps_to_log and --var_leads_metrics_watch #746 lands.

@GiGiKoneti

Copy link
Copy Markdown
Contributor

two small issues remain:

  1. black and flake8 failures: pre-commit run flake8 fails on lines exceeding 80 chars in neural_lam/models/module.py:659 and tests/test_plotting.py:928, 955, and black reformats module.py.
  2. Tuple unpacking at tests/test_plotting.py:558: Line 558 still drops the parentheses around (init_states, ...); please revert to keep the diff clean.

@vikramsingh920

Copy link
Copy Markdown
Author

Thanks @GiGiKoneti, I addressed both comments in the latest push:

  1. Wrapped long lines in neural_lam/models/module.py and tests/test_plotting.py so flake8 and black pass cleanly.
  2. Restored the tuple unpacking parentheses at tests/test_plotting.py:558 to keep the diff clean.

@vikramsingh920

Copy link
Copy Markdown
Author

Hi @GiGiKoneti and @sadamov , when you get a chance, could you please take a look at my PR #752 and let me know if there’s anything I should change or improve? I’d really appreciate your feedback. Thanks!

@GiGiKoneti

Copy link
Copy Markdown
Contributor

Since #746 is still open, this PR will need a rebase on main once #746 lands before it can be merged. Leaving final review and sequencing to Simon.

@vikramsingh920

vikramsingh920 commented Sep 22, 2026

Copy link
Copy Markdown
Author

hii @GiGiKoneti and @sadamov , #746 has now been merged, so I’ve rebased #752 onto the latest main and addressed the previous review comments.
Could you please take a look at #752 when you get a chance? Thanks!

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.

[Bug] Spatial loss map titles and saved PDFs mislabeled in on_test_epoch_end when val_steps_to_log contains out-of-range steps

2 participants