def _process_gradient_args(f, kwargs):
    'Handle common processing of arguments for gradient and gradient-like functions.'
    axes = kwargs.get('axes', range(f.ndim))

    def _check_length(positions):
        if (('axes' in kwargs) and (len(positions) < len(axes))):
            raise ValueError('Length of "coordinates" or "deltas" cannot be less than that of "axes".')
        elif (('axes' not in kwargs) and (len(positions) != len(axes))):
            raise ValueError('Length of "coordinates" or "deltas" must match the number of dimensions of "f" when "axes" is not given.')
    if ('deltas' in kwargs):
        if (('coordinates' in kwargs) or ('x' in kwargs)):
            raise ValueError('Cannot specify both "coordinates" and "deltas".')
        _check_length(kwargs['deltas'])
        return ('delta', kwargs['deltas'], axes)
    elif ('coordinates' in kwargs):
        _check_length(kwargs['coordinates'])
        return ('x', kwargs['coordinates'], axes)
    elif isinstance(f, xr.DataArray):
        return ('pass', axes, axes)
    else:
        raise ValueError('Must specify either "coordinates" or "deltas" for value positions when "f" is not a DataArray.')
Handle common processing of arguments for gradient and gradient-like functions.
def _process_gradient_args(f, kwargs):
    
    axes = kwargs.get('axes', range(f.ndim))

    def _check_length(positions):
        if (('axes' in kwargs) and (len(positions) < len(axes))):
            raise ValueError('Length of "coordinates" or "deltas" cannot be less than that of "axes".')
        elif (('axes' not in kwargs) and (len(positions) != len(axes))):
            raise ValueError('Length of "coordinates" or "deltas" must match the number of dimensions of "f" when "axes" is not given.')
    if ('deltas' in kwargs):
        if (('coordinates' in kwargs) or ('x' in kwargs)):
            raise ValueError('Cannot specify both "coordinates" and "deltas".')
        _check_length(kwargs['deltas'])
        return ('delta', kwargs['deltas'], axes)
    elif ('coordinates' in kwargs):
        _check_length(kwargs['coordinates'])
        return ('x', kwargs['coordinates'], axes)
    elif isinstance(f, xr.DataArray):
        return ('pass', axes, axes)
    else:
        raise ValueError('Must specify either "coordinates" or "deltas" for value positions when "f" is not a DataArray.')