Updating wind downscaling code to be more descriptive - #2315
Conversation
SamGriffithsMO
left a comment
There was a problem hiding this comment.
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)
| except CoordinateNotFoundError: | ||
| ok_pairs.append(False) |
There was a problem hiding this comment.
Maybe not for this PR, but it would be helpful to give a hint as to what/why this returned false
There was a problem hiding this comment.
I need someone to teach me how to do logging in IMPROVER - note to remind me to ask 🙂
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 🙂 |
|
Thanks to @SamGriffithsMO's pointers:
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
left a comment
There was a problem hiding this comment.
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
* Pinning proj to 9.7.1 * Adding myself to contributors list * Fix numpy-update test failures * Reverting float() change
bayliffe
left a comment
There was a problem hiding this comment.
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.
| # 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) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
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: 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. 🙂 |
5709753
into
feature_update_wind_downscaling
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:
CLA