def xarray_derivative_wrap(func):
    'Decorate the derivative functions to make them work nicely with DataArrays.\n\n    This will automatically determine if the coordinates can be pulled directly from the\n    DataArray, or if a call to lat_lon_grid_deltas is needed.\n    '

    @functools.wraps(func)
    def wrapper(f, **kwargs):
        if (('x' in kwargs) or ('delta' in kwargs)):
            return preprocess_xarray(func)(f, **kwargs)
        elif isinstance(f, xr.DataArray):
            axis = f.metpy.find_axis_name(kwargs.get('axis', 0))
            new_kwargs = {'axis': f.get_axis_num(axis)}
            if check_axis(f[axis], 'time'):
                new_kwargs['delta'] = f[axis].metpy.time_deltas
            elif check_axis(f[axis], 'longitude'):
                (new_kwargs['delta'], _) = grid_deltas_from_dataarray(f)
            elif check_axis(f[axis], 'latitude'):
                (_, new_kwargs['delta']) = grid_deltas_from_dataarray(f)
            else:
                new_kwargs['x'] = f[axis].metpy.unit_array
            result = func(f.metpy.unit_array, **new_kwargs)
            return xr.DataArray(result.magnitude, coords=f.coords, dims=f.dims, attrs={'units': str(result.units)})
        else:
            raise ValueError('Must specify either "x" or "delta" for value positions when "f" is not a DataArray.')
    return wrapper
Decorate the derivative functions to make them work nicely with DataArrays.

This will automatically determine if the coordinates can be pulled directly from the
DataArray, or if a call to lat_lon_grid_deltas is needed.
def xarray_derivative_wrap(func):
    'Decorate the derivative functions to make them work nicely with DataArrays.\n\n    This will automatically determine if the coordinates can be pulled directly from the\n    DataArray, or if a call to lat_lon_grid_deltas is needed.\n    '

    @functools.wraps(func)
    def wrapper(f, **kwargs):
        if (('x' in kwargs) or ('delta' in kwargs)):
            return preprocess_xarray(func)(f, **kwargs)
        elif isinstance(f, xr.DataArray):
            axis = f.metpy.find_axis_name(kwargs.get('axis', 0))
            new_kwargs = {'axis': f.get_axis_num(axis)}
            if check_axis(f[axis], 'time'):
                new_kwargs['delta'] = f[axis].metpy.time_deltas
            elif check_axis(f[axis], 'longitude'):
                (new_kwargs['delta'], _) = grid_deltas_from_dataarray(f)
            elif check_axis(f[axis], 'latitude'):
                (_, new_kwargs['delta']) = grid_deltas_from_dataarray(f)
            else:
                new_kwargs['x'] = f[axis].metpy.unit_array
            result = func(f.metpy.unit_array, **new_kwargs)
            return xr.DataArray(result.magnitude, coords=f.coords, dims=f.dims, attrs={'units': str(result.units)})
        else:
            raise ValueError('Must specify either "x" or "delta" for value positions when "f" is not a DataArray.')
    return wrapper