def get_grid_mapping(xarr, grid_mapping='crs'):
    """ Return grid mapping variable

    Parameters
    ----------
    xarr : xarray.Dataset or xarray.DataArray
        XArray data

    Returns
    -------
    xarray.Variable
        XArray grid mapping variable

    Raises
    ------
    KeyError
        Raised if grid mapping variable does not exist
    """
    var_gm = xarr.coords.get(grid_mapping, None)
    if var_gm is None:
        raise KeyError('No grid mapping variable found')
    else:
        return var_gm
