grid type testing 1 - Voronoi grids
See original GitHub issueSince (I think) the switch onto the graph structures, we have some unexpected behaviour related to the grid types. Formerly, Hex and Radial were subclasses of VoronoiDelaunayGrid, and on this basis in several places we had type testing that looked like this:
>>> if isinstance(grid, RasterModelGrid): # shorthand for "patches are square"
... # stuff
>>> elif isinstance(grid, VoronoiDelaunayGrid): # shorthand for "patches are triangles"
... # other stuff
>>> else:
... raise Error # if you're lucky this is there!
or sometimes simply:
>>> if isinstance(mg, RasterModelGrid):
>>> # stuff
>>> else:
>>> # other stuff
But, now we have this - to me very counterintuitive - typing:
>>> isinstance(rmg, VoronoiDelaunayGrid) # phew!
False
>>> isinstance(hmg, VoronoiDelaunayGrid) # formerly True I think
False
>>> isinstance(radmg, VoronoiDelaunayGrid) # formerly True I think
False
Have I missed a grid method (@mcflugen ?) that can now actually perform this “patches are triangles” check as this method isn’t working any more? We need this as a method as letting type checks propagate in lots of different methods seems like a recipe for disaster if this kind of change happens again, or we add more classes.
These if
statements also all need finding and tweaking. Tagging @kbarnhart as the place that triggered me noticing this was in the FlowAccumulator
(lns 698-9), but there are a couple of others as well where this is actually broken. Fortunately most of the tests are if Raster... else:
which holds up under these changes.
A related issue (will be submitted following this) is that now we have a NetworkModelGrid the lazy logic that many components use:
>>> if isinstance(mg, RasterModelGrid):
>>> # stuff
>>> else:
>>> # other stuff
Is no longer adequate - we will get weird fails if Networks are supplied to these. There should be explicit tests on our components if they can’t handle network grids.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
@SiccarPoint I’ve now read this, good catch. @mcflugen is definitely the person who would know what grid attribute should get used for this. Once he weighs in on what it should be, I’m can help make some of the relevant component changes.
@SiccarPoint - Just got back from some fieldwork, so may be middle/end of next week before I am able to actually read this issue (and #1294) carefully. Will respond then. Thx.