Skip to content

Vertical slices of a Grid3D are mislabelled, so isel(x=..).isel(y=..) fails #1047

Description

@ecomodeller

Selecting a single column out of a dfs3 requires selecting along x and then along y. Both of the obvious ways to write that fail, and the way that works reads wrongly.

da = mikeio.read("tests/testdata/dissolved_oxygen.dfs3")[0]
da.dims                            # ("time", "z", "y", "x")

da.isel(x=56, y=110)               # NotImplementedError: Selecting on multiple
                                   # dimensions in the same call, not yet implemented
da.isel(x=56).isel(y=110)          # IndexError: index 110 is out of bounds
                                   # for axis 0 with size 17
da.isel(x=56).isel(x=110)          # works, and the values are correct

The cause is that a vertical slice is represented as a Grid2D, whose axes are named x and y by definition. After isel(x=56) the original z axis is reported as y and the original y axis as x:

s = da.isel(x=55)
s.dims                             # ("time", "y", "x")
s.geometry.nx, s.geometry.ny       # 112, 17  -- i.e. original ny, nz

So the extents are right and the data is right — isel(x=..).isel(x=..) returns exactly the expected column — but the labels describe a horizontal grid that this object is not. A caller who trusts dims gets an IndexError, and one who works around it has to know that x means two different axes on consecutive lines.

Worth deciding whether a vertical slice should be a Grid2D at all. #1010 covers the related loss of origin/orientation/projection in the same branches; both come from reusing a horizontal grid type for a vertical slice.


Code sites:

  • src/mikeio/spatial/_grid_geometry.py (Grid3D.isel, the axis == 1andaxis == 2 branches)
  • src/mikeio/dataset/_dataarray.py (DataArray.isel, the multiple-dimension guard)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions