@exporter.export
@preprocess_xarray
def lat_lon_grid_deltas(longitude, latitude, **kwargs):
    'Calculate the delta between grid points that are in a latitude/longitude format.\n\n    Calculate the signed delta distance between grid points when the grid spacing is defined by\n    delta lat/lon rather than delta x/y\n\n    Parameters\n    ----------\n    longitude : array_like\n        array of longitudes defining the grid\n    latitude : array_like\n        array of latitudes defining the grid\n    kwargs\n        Other keyword arguments to pass to :class:`~pyproj.Geod`\n\n    Returns\n    -------\n    dx, dy:\n        at least two dimensional arrays of signed deltas between grid points in the x and y\n        direction\n\n    Notes\n    -----\n    Accepts 1D, 2D, or higher arrays for latitude and longitude\n    Assumes [..., Y, X] for >=2 dimensional arrays\n\n    '
    from pyproj import Geod
    if (latitude.ndim != longitude.ndim):
        raise ValueError('Latitude and longitude must have the same number of dimensions.')
    if (latitude.ndim < 2):
        (longitude, latitude) = np.meshgrid(longitude, latitude)
    geod_args = {'ellps': 'sphere'}
    if kwargs:
        geod_args = kwargs
    g = Geod(**geod_args)
    (forward_az, _, dy) = g.inv(longitude[..., :(- 1), :], latitude[..., :(- 1), :], longitude[..., 1:, :], latitude[..., 1:, :])
    dy[((forward_az < (- 90.0)) | (forward_az > 90.0))] *= (- 1)
    (forward_az, _, dx) = g.inv(longitude[..., :, :(- 1)], latitude[..., :, :(- 1)], longitude[..., :, 1:], latitude[..., :, 1:])
    dx[((forward_az < 0.0) | (forward_az > 180.0))] *= (- 1)
    return ((dx * units.meter), (dy * units.meter))
Calculate the delta between grid points that are in a latitude/longitude format.

Calculate the signed delta distance between grid points when the grid spacing is defined by
delta lat/lon rather than delta x/y

Parameters
----------
longitude : array_like
    array of longitudes defining the grid
latitude : array_like
    array of latitudes defining the grid
kwargs
    Other keyword arguments to pass to :class:`~pyproj.Geod`

Returns
-------
dx, dy:
    at least two dimensional arrays of signed deltas between grid points in the x and y
    direction

Notes
-----
Accepts 1D, 2D, or higher arrays for latitude and longitude
Assumes [..., Y, X] for >=2 dimensional arrays
@exporter.export
@preprocess_xarray
def lat_lon_grid_deltas(longitude, latitude, **kwargs):
    'Calculate the delta between grid points that are in a latitude/longitude format.\n\n    Calculate the signed delta distance between grid points when the grid spacing is defined by\n    delta lat/lon rather than delta x/y\n\n    Parameters\n    ----------\n    longitude : array_like\n        array of longitudes defining the grid\n    latitude : array_like\n        array of latitudes defining the grid\n    kwargs\n        Other keyword arguments to pass to :class:`~pyproj.Geod`\n\n    Returns\n    -------\n    dx, dy:\n        at least two dimensional arrays of signed deltas between grid points in the x and y\n        direction\n\n    Notes\n    -----\n    Accepts 1D, 2D, or higher arrays for latitude and longitude\n    Assumes [..., Y, X] for >=2 dimensional arrays\n\n    '
    from pyproj import Geod
    if (latitude.ndim != longitude.ndim):
        raise ValueError('Latitude and longitude must have the same number of dimensions.')
    if (latitude.ndim < 2):
        (longitude, latitude) = np.meshgrid(longitude, latitude)
    geod_args = {'ellps': 'sphere'}
    if kwargs:
        geod_args = kwargs
    g = Geod(**geod_args)
    (forward_az, _, dy) = g.inv(longitude[..., :(- 1), :], latitude[..., :(- 1), :], longitude[..., 1:, :], latitude[..., 1:, :])
    dy[((forward_az < (- 90.0)) | (forward_az > 90.0))] *= (- 1)
    (forward_az, _, dx) = g.inv(longitude[..., :, :(- 1)], latitude[..., :, :(- 1)], longitude[..., :, 1:], latitude[..., :, 1:])
    dx[((forward_az < 0.0) | (forward_az > 180.0))] *= (- 1)
    return ((dx * units.meter), (dy * units.meter))