Skip to content

Updating wind downscaling code to be more descriptive - #2315

Merged
mo-AliceLake merged 21 commits into
feature_update_wind_downscalingfrom
alice-update-winddownscaling
Apr 30, 2026
Merged

Updating wind downscaling code to be more descriptive#2315
mo-AliceLake merged 21 commits into
feature_update_wind_downscalingfrom
alice-update-winddownscaling

Conversation

@mo-AliceLake

@mo-AliceLake mo-AliceLake commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

This issue represents step 1 of a larger piece of work to enable skilful wind downscaling in IMPROVER. The current wind‑downscaling code mixes height correction (HC) and roughness correction (RC). My understanding is that earlier investigations suggest that HC alone adds skill, but the combined HC+RC approach does not (at least over the UK domain). The long‑term aim (step 2) is to separate these components cleanly, but to be able to do that, the existing code needs to be understood, tidied, and documented without altering the science. This issue covers that preparatory clean‑up work.

Testing:

  • Ran tests and they passed OK
  • Added new tests for the new feature(s) - N/A

CLA

  • If a new developer, signed up to CLA

@mo-AliceLake
mo-AliceLake marked this pull request as draft March 3, 2026 13:34
@mo-AliceLake
mo-AliceLake marked this pull request as ready for review March 5, 2026 15:47

@SamGriffithsMO SamGriffithsMO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure of the exact context of this work, but if we want the code to run outside of the Improver suite on the HPC, you may wish to also update cli/wind_dowscaling.py. Ideally it would just initialise plugins and call them, making calling via the API easier.

However if you do update the CLI to align with these changes (naming conventions) you will break the CLI and API. Are the full scope of your changes going break these anyway? And therefore, should you target this at a feature branch? (The Improver science team can hopefully set expectations here, as they have better sight on all the uses of these plugins).

If you don't need to break CLI or API with your changes, I would advise not breaking them (i.e. revert changes to init and process call signatures)

Comment thread improver/wind_calculations/wind_downscaling.py Outdated
Comment thread improver/wind_calculations/wind_downscaling.py
Comment on lines +969 to +970
except CoordinateNotFoundError:
ok_pairs.append(False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe not for this PR, but it would be helpful to give a hint as to what/why this returned false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I need someone to teach me how to do logging in IMPROVER - note to remind me to ask 🙂

Comment thread improver/wind_calculations/wind_downscaling.py
@mo-AliceLake

mo-AliceLake commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

I'm not sure of the exact context of this work, but if we want the code to run outside of the Improver suite on the HPC, you may wish to also update cli/wind_dowscaling.py. Ideally it would just initialise plugins and call them, making calling via the API easier.

However if you do update the CLI to align with these changes (naming conventions) you will break the CLI and API. Are the full scope of your changes going break these anyway? And therefore, should you target this at a feature branch? (The Improver science team can hopefully set expectations here, as they have better sight on all the uses of these plugins).

If you don't need to break CLI or API with your changes, I would advise not breaking them (i.e. revert changes to init and process call signatures)

I don't know about the IMPROVER cli and API - need to learn! - but unfortunately yes this work will definitely be a breaking change as we need to split out HC and RC (see e.g. work-in-progress next step #2324)

Will ask about feature branch 🙂

@mo-AliceLake
mo-AliceLake changed the base branch from master to feature_update_wind_downscaling March 10, 2026 14:11
@mo-AliceLake

mo-AliceLake commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks to @SamGriffithsMO's pointers:

  • I've learnt about the IMPROVER api (didn't need updating) and cli (have now updated accordingly).
  • I have made a feature branch feature_update_wind_downscaling which I am now pointing everything towards. Can do proper release notes etc when that feature branch is eventually merged into master.

And in the meantime, unit tests have started failing, but that's not to do with these changes - we think to do with something being updated in the environment.

@SamGriffithsMO SamGriffithsMO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm happy with this (less the failing tests). Since it's not pointing at main I'll approve anyway, and pass this on to Ben A(?) who might be better able to advise on a CI fix

mo-AliceLake and others added 2 commits March 11, 2026 11:27
* Pinning proj to 9.7.1

* Adding myself to contributors list

* Fix numpy-update test failures

* Reverting float() change

@bayliffe bayliffe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for tackling this Alice, we've all been far too scared. A couple more comments here to go with those below.

  • We have generally removed the type definitions from the doc-string text, instead relying upon the type-hinting in the function interfaces to specify this; have a look across a few other plugins. I don't think this needs to be a hard rule, so if you find it clearer to include the types in the text as well, that's fine.
  • Do you think you will tackle rewriting / improving the unit tests as part of the broader work? I'll flag now that if they are to undergo a serious rewrite it would be good to move to using pytest, which we've not done wholesale but are tackling piecemeal as we happen to be working on older tests.

Comment thread .mailmap Outdated
Comment thread improver/cli/wind_downscaling.py
Comment thread improver/wind_calculations/wind_downscaling.py
Comment thread improver/wind_calculations/wind_downscaling.py Outdated
Comment thread improver/wind_calculations/wind_downscaling.py Outdated
Comment thread improver/wind_calculations/wind_downscaling.py Outdated
Comment thread improver/wind_calculations/wind_downscaling.py Outdated
Comment on lines +971 to +979
# Pairwise x/y grid compatibility check across all ancils
ok_pairs: list[bool] = []
for a, b in itertools.permutations(required, 2):
try:
same_y = a.coord(axis="y") == b.coord(axis="y")
same_x = a.coord(axis="x") == b.coord(axis="x")
ok_pairs.append(bool(same_x & same_y))
except CoordinateNotFoundError:
ok_pairs.append(False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could make use of the spatial_coords_match functionality in utilities/cube_checker.py rather than this being repeated here. It would remove all of the stripping of extra coordinates etc above which should shorten this quite a bit. You may wish to retain this for the units comparison and to invoke the suggested function.


Check if wind and ancillary files are on the same grid and if
they have the same ordering.
def check_wind_ancil(self, xwp: int, ywp: int) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be replaced with a call to enforce_coordinate_ordering in utilities/cube_manipulation.py. Instead of simply checking the order matches and failing otherwise the code can simply enforce that the orders match and so allow it to continue. Deletes some more code from this file as well.

@mo-AliceLake

Copy link
Copy Markdown
Contributor Author

Thanks for tackling this Alice, we've all been far too scared. A couple more comments here to go with those below.

  • We have generally removed the type definitions from the doc-string text, instead relying upon the type-hinting in the function interfaces to specify this; have a look across a few other plugins. I don't think this needs to be a hard rule, so if you find it clearer to include the types in the text as well, that's fine.
  • Do you think you will tackle rewriting / improving the unit tests as part of the broader work? I'll flag now that if they are to undergo a serious rewrite it would be good to move to using pytest, which we've not done wholesale but are tackling piecemeal as we happen to be working on older tests.

Thanks so much for such a detailed+helpful review! 🙂 Really useful for getting more familiar with the IMPROVER codebase.

I've made pretty much all the suggested changes (including tidying up the type hints to align with the rest of the repo) and have also reworked the docstrings and variable names, so hopefully these are now much clearer.

There are a couple of things I've deliberately left for follow-up work to avoid this one becoming too tangled:
Refactoring the CLI to remove the processing (ticket here: https://github.com/metoppv/mo-blue-team/issues/1141)
Updating to newer IMPROVER utilities, because I'd like to tackle this once I have stronger unit test coverage to make sure I don't accidentally change any behaviour...

Tests: yes, I'm planning to rewrite these (have started having a go on a separate branch) but hadn't yet switched to pytest, so thanks for flagging - I'll have a go. 🙂

@mo-AliceLake
mo-AliceLake merged commit 5709753 into feature_update_wind_downscaling Apr 30, 2026
7 checks passed
@mo-AliceLake
mo-AliceLake deleted the alice-update-winddownscaling branch April 30, 2026 09:33
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.

4 participants