Skip to content

cf_xarray.bounds_to_vertices produces incorrect results with descending 2D array (e.g., bounds) #576

Open
@tomvothecoder

Description

@tomvothecoder

This GitHub issue comment in the xESMF repo reveals that cf_xarray.bounds_to_vertices has an issue where it produces incorrect results when bounds are descending, which cascades to incorrect results when regridding with xESMF.

Minimum Example

import xarray as xr
import cf_xarray as cfxr

bounds = xr.DataArray([[50.5, 50. ], [51.,  50.5], [51.5, 51. ], [52.,  51.5], [52.5, 52.]], dims=('lat', 'bounds'))
cfxr.bounds_to_vertices(bounds, "bounds")

yields

<xarray.DataArray (lat_vertices: 6)> Size: 48B
array([50.5, 51. , 51.5, 52. , 52.5, 52. ])
Dimensions without coordinates: lat_vertices

instead of starting at 50 and ending at 52.5.

Expected Result (I think)

<xarray.DataArray (lat_vertices: 5)> Size: ?
array([50., 50.5. , 51, 51.5. , 52])
Dimensions without coordinates: lat_vertices

@aulemahal mentioned here that he contributed to this portion of cf-xarray and he expects the fix to be a simple transpose.

Unless somebody gets to it before me, I will try to take a look at the code whenever I have time since this is a somewhat high priority for a few projects I work on that use xESMF for regridding.

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