-
Notifications
You must be signed in to change notification settings - Fork 295
Bugfix shape masking #6129
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
base: main
Are you sure you want to change the base?
Bugfix shape masking #6129
Conversation
From @SciTools/peloton : discussed what we are seeing here and in #6126. |
Discussion with @acchamber notes:
|
What are @SciTools/peloton (@pp-mo) thoughts about adding This would facilitate better handling of shapes to rasters (which is essentially the problem we're solving) with the added bonus that we could also mask to other shape types, like lines, to extract a trajectory from a Cube, for example. |
I was planning on going to the AVD surgery this week to discuss some changes and/or make the case for rasterio |
Thanks for your patience everyone. It's sometimes a struggle to balance everything and we just haven't had an opportunity to discuss this. Coming to the Surgery (UK Met Office) is an ideal next step. |
@pp-mo, @trexfeathers and @stephenworsley have discussed this at the Surgery and agree in principle that we could consider adding rasterio as an optional dependency. |
for more information, see https://pre-commit.ci
From @SciTools/peloton: would @hsteptoe and @acchamber appreciate any more input from core devs at this point? |
I just need to find more time, which is in short supply as we get near the end of FY... |
This is now ready for some initial (alpha?) testing 🎉. @acchamber are you available to try out the new features? (Updates to docs etc. will follow if this is successful) Tests are incomplete are should not be review yet. This is a fairly substantial re-write. New/improved features include:
There are some breaking changes, principally moving away from having a My informal tests so far show working behaviour for iris test data from |
@trexfeathers @bjlittle I think this is ready for a first review... in particular I would appreciate reviews/help with
|
re. the PROJ variable, the last time I saw this come up was |
@mo-DanCubbon only two-thirds of Iris devs will be able to view this link since it's internal to the UK Met Office. If there is any more detail you'd like to be visible it'll need to be posted verbatim. |
Details in that link were not super important, only that the network had to be switched off. We've investigated this a bit more, and have turned our PROJ_NETWORK back to on... but now we're getting the right answer. I'm assuming Proj has cached the necessary grid files to perform the transformation correctly now. I haven't since been able to reproduce the issue unfortunately but you could try with this:
|
@@ -2189,27 +2192,56 @@ def _strip_metadata_from_dims(cube, dims): | |||
return reduced_cube | |||
|
|||
|
|||
def mask_cube_from_shapefile(cube, shape, minimum_weight=0.0, in_place=False): | |||
"""Take a shape object and masks all points not touching it in a cube. | |||
def mask_cube_from_shapefile( |
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.
Just a question about the terminology used in this area. One of the functions being modified is mask_cube_from_shapefile
is really masking from a geometry (which can contain multiple disconnected shapes) and not a shapefile (which could contain multiple geometries). I would guess it would be difficult to change the name of the function, but perhaps it is worth clarifying this in the documentation as it was something that initially confused me.
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.
Yes, that's a fair comment. The primary consideration here was not to introduce breaking changes by changing the function name.
I would be in favour of renaming for consistency with the shapely
library, which underpins the geometry handling, and either go for mask_cube_from_shape()
or mask_cube_from_geometry()
which would recognise that iris
is agnostic to how geometries are loaded in the first place (they could also come from geoJSON or .kml files for example), but @trexfeathers would need to approve the change... could we utilise iris.FUTURE
here?
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 has been raised before, but during design @acchamber assured me that it would be much more meaningful to our user base if we used the word shapefile
. Would you entertain the possibility that those of us discussing this on GitHub are more technical than the average user?
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.
Yes, this degree of technical pedantry may be unnecessary...but arguably it provides clarity. The simplest solution is just to add some clarification to the docs (although IMO the typing already makes it clear what the function expects). I suspect that the current convention is only meaningful to those folk coming from ASCEND (which limits it to internal MO), as ASCEND did also handle shapefile loading, which iris does not.
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.
I can't remember previous discussuions on this, so I may be contractdicting past self, but I don't see a big reason not to to use mask_cube_from_shape()
instead - @hsteptoe is right in that it is not the shapefile itself being used, but a shapely geometry object. I think mask_cube_from_shape()
makes it purpose clear to scanners of the docs while also being more correct - but that probably does require a depreciation warning for a switch in a few versions time, similar to how numpy handled this.
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.
OK well if everyone is cool with this, it's not as bad as you might think. You can introduce the new signature right now, and the outdated signature just calls the new one, with a deprecation warning as you say.
We are talking more about Iris v4.0 these days so the warnings won't be around forever!
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.
I think my preference would be mask_cube_from_shape()
... @mo-DanCubbon @acchamber thoughts?
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.
I think that would be the most understandable yes
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.
agreed
🚀 Pull Request
Description
Fixes #6126 by exposing the shape geometry to the user. Adds to docs and docstrings to make it clearer how to use this.
Consult Iris pull request check list
Add any of the below labels to trigger actions on this PR: