def _rename_variables(ds, variableMap):  # {{{
    """
    Given an `xarray.DataSet` object `ds` and a dictionary mapping
    variable names `variableMap`, returns a new data set in which variables
    from `ds` with names equal to values in `variableMap` are renamed
    to the corresponding key in `variableMap`.

    Parameters
    ----------
    ds : `xarray.DataSet` object
        A data set in which the mapped variable names should be renamed

    variableMap : dict
        A dictionary with keys that are variable names used by
        MPAS-Analysis and values that are lists of possible names for the same
        variable in the MPAS dycore that produced the data set (which may
        differ between versions).

    Returns
    -------
    outDataSEt : A new `xarray.DataSet` object with the variable renamed.
    """
    # Authors
    # -------
    # Xylar Asay-Davis

    renameDict = {}
    for datasetVariable in ds.data_vars:
        for mapVariable in variableMap:
            renameList = variableMap[mapVariable]
            if datasetVariable in renameList:
                renameDict[datasetVariable] = mapVariable
                break

    return ds.rename(renameDict)