-
Notifications
You must be signed in to change notification settings - Fork 289
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
Bugfix shape masking #6129
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 |
I'll see if I can find the time to play around with this alpha in the next two weeks, to give some feedback, however I am concerned by the breaking changes here. Being unable to mask the anti-meridian or the poles feels like a major flaw - As you've pointed out fixing it requires some guess of intention by the program of the user's desires, but a user being unable to mask shapes such as - Russia , The Pacific Ocean, The Arctic circle or Antarctica is a deteriment to many science workflows, especially when some of these do work in the current function. I am also concerned about losing |
Re. meridian crossing, I'll add some more shapefile test cases for the Arctic, Antarctic and Pacific Ocean. I think that so long as these are Re. |
I know that Russia currently works in the current impletmentation with the "standard" Natural Earth shapefile. I have not actually checked for the Arctic/Antarctic, but I know there's active science that would need them to work, although I accept your point it's as much as about the shapefile construction as our impletmentation.
I know I certainly am - it matters mostly when your grid resolution and your shapefile are similar magnitiudes - a good example being country-level masking on 1 degree or courser grids. You often get situations where a country is centred between grid boxes - being present in 20% of one, 30% of about, and 2% of a third as an example. Counting all the boxes equally is bad, but the shape doesn't nessacerily reach the centre of the boxes it is significantly in. Manual experimentation is required to find a suitable weight, doesn't mean it's not useful. You can also think of land-sea maskes and river watersheds for long-but-thin shapes. There's lots of different shapes you may use and data to apply them to, and assuming that all cases are covered by "all-touched" and centred-touching is reductive. |
It's not reductive if a users' choice of % isn't justifiable in the first place. Manual experimentation to find what 'looks right' isn't a robust or justifiable process when, by definition, going from vector -> raster involves a loss of fidelity. This requires a clear rule-based approach to this transform. A %-based approach can lead to voids in a raster. For a complex set of vectors that roughly sub-divide a grid cell equally (say, 30%-35%-35%), if a %-based threshold is poorly specified (say >= 40%) then the grid cell will fail to be selected and assigned to any of those rasterised vectors. A clear rule system (eg. centre-overlapping) will avoid this. This precedent exists across many rasterization implementations including things like OpenGL or ArcGIS. A %-based approach does not. I can see an argument for a rule based on Also consider the Arakawa grid system used by numerical models... there is an understanding that a continuous physical property discretised onto a grid has to be assigned to a fixed point (on the centre or edge), even though we interpret this quantity as an integral over the grid box, ie. an area average. But again, this is based on a clear rule system: centres or edges. Your concern with rasterising vectors onto coarse grid is simply an aliasing issue. A simple approach to anti-aliasing could be to weight the underlying raster by the proportion of the vector that overlaps it, but the weight needs to be carried through and applied to the raster at the point of masking, which doesn't happen in the current implementation, which is reductive in as much as it is limited to a |
@hsteptoe was kind enough to bring this to a 'surgery' day at UK Met Office. Summary of my position, as the developer responsible for Iris:
|
…g' into bugfix-shape-masking
for more information, see https://pre-commit.ci
🚀 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: