-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix wrong number of mesh levels when grid is multiple of refinement factor #26
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Easy fix for numerical issues. Alternatively this also solves the isssue: coord_extent = np.array((xy.shape[2], xy.shape[1]), dtype="float32")
But, I am fine with the epsilon approach and from my side this PR can be merged.
* Update changelog and version number for version 0.2.0 * Move #26 to fixed in changelog
* Start looking into where xy has to be changed * Change shapes in docstrings * Make flat mesh graphs work with new coordinate layout * Merge PR #26 into branch * Fix coordinate handling in multirange graph creation * Rename grid_refinement_factor to mesh_node_distance * Fix existing tests to work with new coordinate format * Add test for irregularlygridded coordinates * Remove unneeded eps in mesh level calculation * Change documentation to use new format and arguments for coordinates * Fix bug in coordinate order for flat graphs * Start working on allowing latlon coordinates * Introduce coords and projection * Fix linting * Fix tests with coords keyword argument * Implement lat-lon transformation through projection * Add documentation page about graphs constructed using lat-lons * Adjust coords keyword arg in docs * Add test for lat-lon coordinates * Fix linting of docs * Merge main into branch * Fix typos and clarifications as suggested from code review Co-authored-by: sadamov <[email protected]> * Change euclidean coordinates to Cartesian coordinates * Update src/weather_model_graphs/create/mesh/kinds/hierarchical.py Co-authored-by: Leif Denby <[email protected]> * Clarify comments and variable names around mesh level computation * Add check for number of nodes in test with irregular coords * Update docs line on square meshes * Reference lat-lon notebook in coordinate section * Change projection spec to use pyproj crs:s * Adjust test to crs arguments * Fix linting * Update docs to crs change * Add cartopy dependency to visualization group * Update src/weather_model_graphs/create/base.py Co-authored-by: Leif Denby <[email protected]> * Fix documentation * Add changelog entry * Update CHANGELOG.md Co-authored-by: Leif Denby <[email protected]> * Trim whitespace --------- Co-authored-by: sadamov <[email protected]> Co-authored-by: Leif Denby <[email protected]>
Describe your changes
There is currently a bug where you can not make hierarchical graphs if the grid dimensions are an exact multiple of the refinement factor. This is best illustrated with an example:
Then you should be able to have a first mesh level of 9x9 and a second of 3x3 mesh nodes. This does currently not work, as the code return that the maximum number of possible mesh levels is 1, rather than 2.
We tracked down this issue to the casting to int in
weather-model-graphs/src/weather_model_graphs/create/mesh/mesh.py
Lines 116 to 121 in 1d1407b
Due to the numerical precision of this calculation it sometimes ends up with something like 1.999999999999996 rather than exactly 2. This then gets floored to 1.
This PR fixes this by adding a tiny epsilon before doing this rounding. It also adds a test for this.
Type of change
Checklist before requesting a review
pull
with--rebase
option if possible).I have updated the documentation to cover introduced code changesChecklist for reviewers
Each PR comes with its own improvements and flaws. The reviewer should check the following:
Author checklist after completed review
reflecting type of change (add section where missing):
Checklist for assignee