def get_xr_resolution(ds):
    """
    Read dataset and get pixel resolution from attributes. If 
    attributes don't exist, fall back to rough approach of minus 
    one pixel to another.

    Parameters
    ----------
    ds: xarray dataset, dataarray
        A single xarray dataset with variables and x and y dims.

    Returns
    ----------
    res : float
        A float containing the cell resolution of xarray dataset.
    """

    # check if x and y dims exist
    if 'x' not in list(ds.dims) and 'y' not in list(ds.dims):
        raise ValueError('No x, y dimensions in dataset.')

    # try getting max res option 1
    try:
        res = abs(max(ds.res))
    except:
        res = None

    # try getting max res option 2
    try:
        if not res:
            res = max(ds.geobox.resolution)
    except:
        res = None

    # try getting max res the dirty way
    try:
        if not res:
            x_res = abs(float(ds['x'].isel(x=0))) - abs(float(ds['x'].isel(x=1)))
            y_res = abs(float(ds['y'].isel(y=0))) - abs(float(ds['y'].isel(y=1)))
            res = abs(float(max(x_res, y_res)))
    except:
        res = None

    # check if something exists
    if not res:
        raise ValueError('Could not extract cell resolution from dataset.')

    # return
    return res