@exporter.export
def grid_deltas_from_dataarray(f):
    'Calculate the horizontal deltas between grid points of a DataArray.\n\n    Calculate the signed delta distance between grid points of a DataArray in the horizontal\n    directions, whether the grid is lat/lon or x/y.\n\n    Parameters\n    ----------\n    f : `xarray.DataArray`\n        Parsed DataArray on a latitude/longitude grid, in (..., lat, lon) or (..., y, x)\n        dimension order\n\n    Returns\n    -------\n    dx, dy:\n        arrays of signed deltas between grid points in the x and y directions with dimensions\n        matching those of `f`.\n\n    See Also\n    --------\n    lat_lon_grid_deltas\n\n    '
    if (f.metpy.crs['grid_mapping_name'] == 'latitude_longitude'):
        (dx, dy) = lat_lon_grid_deltas(f.metpy.x, f.metpy.y, initstring=f.metpy.cartopy_crs.proj4_init)
        slc_x = slc_y = tuple((([np.newaxis] * (f.ndim - 2)) + ([slice(None)] * 2)))
    else:
        dx = (np.diff(f.metpy.x.metpy.unit_array.to('m').magnitude) * units('m'))
        dy = (np.diff(f.metpy.y.metpy.unit_array.to('m').magnitude) * units('m'))
        slc = ([np.newaxis] * (f.ndim - 2))
        slc_x = tuple((slc + [np.newaxis, slice(None)]))
        slc_y = tuple((slc + [slice(None), np.newaxis]))
    return (dx[slc_x], dy[slc_y])
Calculate the horizontal deltas between grid points of a DataArray.

Calculate the signed delta distance between grid points of a DataArray in the horizontal
directions, whether the grid is lat/lon or x/y.

Parameters
----------
f : `xarray.DataArray`
    Parsed DataArray on a latitude/longitude grid, in (..., lat, lon) or (..., y, x)
    dimension order

Returns
-------
dx, dy:
    arrays of signed deltas between grid points in the x and y directions with dimensions
    matching those of `f`.

See Also
--------
lat_lon_grid_deltas
@exporter.export
def grid_deltas_from_dataarray(f):
    'Calculate the horizontal deltas between grid points of a DataArray.\n\n    Calculate the signed delta distance between grid points of a DataArray in the horizontal\n    directions, whether the grid is lat/lon or x/y.\n\n    Parameters\n    ----------\n    f : `xarray.DataArray`\n        Parsed DataArray on a latitude/longitude grid, in (..., lat, lon) or (..., y, x)\n        dimension order\n\n    Returns\n    -------\n    dx, dy:\n        arrays of signed deltas between grid points in the x and y directions with dimensions\n        matching those of `f`.\n\n    See Also\n    --------\n    lat_lon_grid_deltas\n\n    '
    if (f.metpy.crs['grid_mapping_name'] == 'latitude_longitude'):
        (dx, dy) = lat_lon_grid_deltas(f.metpy.x, f.metpy.y, initstring=f.metpy.cartopy_crs.proj4_init)
        slc_x = slc_y = tuple((([np.newaxis] * (f.ndim - 2)) + ([slice(None)] * 2)))
    else:
        dx = (np.diff(f.metpy.x.metpy.unit_array.to('m').magnitude) * units('m'))
        dy = (np.diff(f.metpy.y.metpy.unit_array.to('m').magnitude) * units('m'))
        slc = ([np.newaxis] * (f.ndim - 2))
        slc_x = tuple((slc + [np.newaxis, slice(None)]))
        slc_y = tuple((slc + [slice(None), np.newaxis]))
    return (dx[slc_x], dy[slc_y])