Skip to content

Passing xarray.DataArray grids through data processing functions should preserve dimension names #1819

Open

Description

@weiji14

Description of the desired feature

Currently, the dimension names of the xarray.DataArray grid outputs appear to be hardcoded to 'x', 'y' and 'z', instead of using the original dimension names of the input xarray.DataArray. To illustrate

grid = xr.DataArray(
    data=[
        [0, 1, 2],
        [3, 4, 5],
        [6, 7, 8],
    ],
    coords=dict(height=[1.5, 2.5, 3.5], width=[4.5, 5.5, 6.5]),
    dims=["height", "width"],
)
print(grid)
# <xarray.DataArray (height: 3, width: 3)>
# array([[0, 1, 2],
#        [3, 4, 5],
#        [6, 7, 8]])
# Coordinates:
#   * height   (height) float64 1.5 2.5 3.5
#   * width    (width) float64 4.5 5.5 6.5

Run it through a data processing function like grdhisteq.equalize_grid

newgrid = pygmt.grdhisteq.equalize_grid(grid=grid)
print(newgrid)
# <xarray.DataArray 'z' (y: 3, x: 3)>
# array([[ 0.,  4.,  6.],
#        [ 8.,  8., 11.],
#        [13., 15., 15.]], dtype=float32)
# Coordinates:
#   * x        (x) float64 4.5 5.5 6.5
#   * y        (y) float64 1.5 2.5 3.5
# Attributes:
#     long_name:     z
#     actual_range:  [ 0. 15.]

Ideally, the newgrid.dims should be ('height', 'width') instead of ('y', 'x').

Are you willing to help implement and maintain this feature? Yes, but happy to let someone take this up too!

Activity

  1. added
    help wanted
    feature request
    on Mar 15, 2022
  2. added this to the 0.7.0 milestone on Mar 15, 2022
  3. modified the milestones: 0.7.0, 0.8.0 on Jun 23, 2022
  4. modified the milestones: 0.8.0, 0.9.0 on Dec 11, 2022
  5. modified the milestones: 0.9.0, 1.0.0 on Mar 6, 2023
  6. added
    longterm
    on Mar 6, 2023
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

    feature requesthelp wantedlongterm

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions