Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying vertical levels rather than height levels #2063

Merged
merged 15 commits into from
Feb 12, 2025

Conversation

lambert-p
Copy link
Contributor

@lambert-p lambert-p commented Dec 9, 2024

Description:

I have changed all variables named height_levels to vertical_level. This is to make the setting of vertical levels more transparent with the previous height_level referring to height, or pressure levels if needed (using a boolean pressure option). The vertical_level argument is therefore clearer to use.

Testing:

  • Ran tests and they passed OK
  • Edited tests for the new feature(s)

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.41%. Comparing base (84a8944) to head (c2f5ee0).
Report is 70 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2063      +/-   ##
==========================================
+ Coverage   98.39%   98.41%   +0.01%     
==========================================
  Files         124      135      +11     
  Lines       12212    13304    +1092     
==========================================
+ Hits        12016    13093    +1077     
- Misses        196      211      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lambert-p lambert-p force-pushed the mobt_693_vertical_levels branch from 0ff1f90 to d7d8142 Compare December 17, 2024 14:52
Copy link
Contributor

@maxwhitemet maxwhitemet left a comment

Choose a reason for hiding this comment

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

I have reviewed your code and highlight only very minor typo corrections. I will put the ticket into second review.

@lambert-p
Copy link
Contributor Author

The ticket mentions adding pressure/height flags to the synthetic data but I think this has already been done. #1993

@Kat-90
Copy link
Contributor

Kat-90 commented Dec 31, 2024

The ticket mentions adding pressure/height flags to the synthetic data but I think this has already been done. #1993

After reviewing the work, I think that this hasn't quite been done yet. Ben has mentioned that there is already a pressure flag to change from height to pressure which is what you've noticed too, and this was fine back when all the levels were called height.
What I think he is suggesting is that now we have a more generalised variable name or "vertical levels", we should have 2 flags, one for pressure AND one for heights. So rather than assuming if pressure = false then it sets heights, we set heights explicitly as we now have no mention of heights anywhere at all.
This would make things even more transparent.

Copy link
Contributor

@Kat-90 Kat-90 left a comment

Choose a reason for hiding this comment

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

I'm a little confused how the acceptance tests are passing at the moment. This PR updates the kgo names so they shouldn't be able to find them - these fail for me locally, plus some extra ones relating to cell methods from this PR: #2062

I think you need to update the names of any KGO files that you have changed in the acceptance tests. These need another PR in the imrpover_test_data repository

@@ -428,54 +433,54 @@ def test_error_unmatched_realizations(self):
self.data_3d, realizations=np.arange(realizations_len)
)

def test_error_unmatched_height_levels(self):
def test_error_unmatched_vertical_levels(self):
"""Test error is raised if the heights provided do not match the
Copy link
Contributor

@Kat-90 Kat-90 Dec 19, 2024

Choose a reason for hiding this comment

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

I think this should docstring be changed to "levels" rather than heights

Copy link
Contributor

Choose a reason for hiding this comment

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

This still needs changing

Copy link
Contributor

@bayliffe bayliffe Jan 14, 2025

Choose a reason for hiding this comment

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

This test actually needs to be duplicated. One named height levels, one named pressure levels. They are testing explicitly as the coordinate name is set in the set up function. So this test should be test_error_unmatched_height_levels as it was originally, with the height=True keyword argument provided. The copy should be called test_error_unmatched_pressure_levels, with pressure=True, and the msg tested will be modified to say `"Cannot generate {} pressures with data of length {}".

pressure:
Flag to indicate whether the height levels are specified as pressure, in Pa.
Flag to indicate whether the vertical levels are specified as pressure, in Pa.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add another flag here for "height" and subsequent places that need it.

@lambert-p
Copy link
Contributor Author

The kgo names have been changed and I have added a height flag as requested

Copy link
Contributor

@Kat-90 Kat-90 left a comment

Choose a reason for hiding this comment

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

Just a few more changes needed here and some minor docstring additions.
We discussed defaulting the new height flag to True but looking further into the code, this is already happening so I suggest we change it to False.

@@ -420,6 +421,7 @@ def set_up_spot_variable_cube(
realizations: Optional[Union[List[float], ndarray]] = None,
vertical_levels: Optional[Union[List[float], ndarray]] = None,
pressure: bool = False,
height: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to add the height flag to this docstring below (line 468)

@@ -420,6 +421,7 @@ def set_up_spot_variable_cube(
realizations: Optional[Union[List[float], ndarray]] = None,
vertical_levels: Optional[Union[List[float], ndarray]] = None,
pressure: bool = False,
height: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we considered what happens if pressure is set to True and the height flag is left unset? It's default is True so we would have 2 True coords which will likely fail. For this to work you'd probably have to write a bit of code to handle it.

On line 370 which is the function that uses the pressure and height flags, there is a bit of code that says if pressure is set (i.e. if pressure=True) then set pressure, else use height. For this reason it might be worth just setting the default flag for height to False as it's already defaulting to height within the code.

@@ -539,6 +542,7 @@ def set_up_variable_cube(
realizations: Optional[Union[List[float], ndarray]] = None,
vertical_levels: Optional[Union[List[float], ndarray]] = None,
pressure: bool = False,
height: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, please add height to the docstring below the pressure flag. And consider changing height default to False.

@@ -428,54 +433,54 @@ def test_error_unmatched_realizations(self):
self.data_3d, realizations=np.arange(realizations_len)
)

def test_error_unmatched_height_levels(self):
def test_error_unmatched_vertical_levels(self):
"""Test error is raised if the heights provided do not match the
Copy link
Contributor

Choose a reason for hiding this comment

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

This still needs changing

Copy link
Contributor

@Kat-90 Kat-90 left a comment

Choose a reason for hiding this comment

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

One last thing.

Kat-90
Kat-90 previously approved these changes Jan 13, 2025
Copy link
Contributor

@Kat-90 Kat-90 left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me now, passing to @bayliffe for a quick glance.

Copy link
Contributor

@bayliffe bayliffe left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this Phoebe. I've put an upsetting number of comments on this, but that's largely to try and help make it clear what I want, rather than leaving you one comment and saying "repeat everywhere".

We should have a chat about this to ensure you understand the reasoning for what I've requested. Give me a call once you've read the review.

Copy link
Contributor

@bayliffe bayliffe left a comment

Choose a reason for hiding this comment

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

Many fewer comments this time. Thanks for all the changes, nearly there with just a few to go.

@lambert-p
Copy link
Contributor Author

Thanks for the comments Ben, I have made the changes and added the tests required.

Copy link
Contributor

@bayliffe bayliffe left a comment

Choose a reason for hiding this comment

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

The tiniest comment which I've largely included to demonstrate how you can reset a file from an older commit. If you make that change I will approve and merge all of this.

Thanks for all the work.

@@ -791,7 +791,7 @@ def height_of_maximum(
A cube of the maximum value over the height coordinate.
find_lowest:
If true then the lowest maximum height will be found (for cases where
there are two heights with the maximum vertical velocity.) Otherwise the highest
there are two heights with the maximum height velocity.) Otherwise the highest
Copy link
Contributor

Choose a reason for hiding this comment

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

We've nearly left this file unchanged. Last thing is that whilst we are talking about height levels, the velocity discussed is the velocity in the z-dimension, i.e. the vertical velocity. If you can put this back as shown here then this file will be exactly as it was before.

Suggested change
there are two heights with the maximum height velocity.) Otherwise the highest
there are two heights with the maximum vertical velocity.) Otherwise the highest

If in future you want to completely undo the changes to a file, the easiest way is to go and get the file back from a commit before you made any changes. You can do this as follows.

  1. Use git log to have a look at the commit history of your branch.
  2. Copy the hash (the long number/letter string) that identifies the commit you want.
  3. Checkout the file that you want to reset from that commit. In this case, assuming your in the head directory (~/improver) it would be this:
git checkout 347a8a437c1284e04d01253828cac48ce11487e4 -- improver/utilities/cube_manipulation.py

This works fine if you've got a nice linear commit history, or even if you've merged in master, as long as no one else is editing the file you're interested in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Ben, that is useful to know for future! I have made the final change.

Copy link
Contributor

@bayliffe bayliffe left a comment

Choose a reason for hiding this comment

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

🎉 Thanks for all the work on this, I think we have made the setting of vertical levels in our test data much more explicit now.

@bayliffe bayliffe merged commit c4b7a5f into metoppv:master Feb 12, 2025
10 checks passed
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