def grid_attrs_to_aospy_names(data, grid_attrs=None):
    """Rename grid attributes to be consistent with aospy conventions.

    Search all of the dataset's coords and dims looking for matches to known
    grid attribute names; any that are found subsequently get renamed to the
    aospy name as specified in ``aospy.internal_names.GRID_ATTRS``.

    Also forces any renamed grid attribute that is saved as a dim without a
    coord to have a coord, which facilitates subsequent slicing/subsetting.

    This function does not compare to Model coordinates or add missing
    coordinates from Model objects.

    Parameters
    ----------
    data : xr.Dataset
    grid_attrs : dict (default None)
        Overriding dictionary of grid attributes mapping aospy internal
        names to names of grid attributes used in a particular model.

    Returns
    -------
    xr.Dataset
        Data returned with coordinates consistent with aospy
        conventions
    """
    if grid_attrs is None:
        grid_attrs = {}

    # Override GRID_ATTRS with entries in grid_attrs
    attrs = GRID_ATTRS.copy()
    for k, v in grid_attrs.items():
        if k not in attrs:
            raise ValueError(
                'Unrecognized internal name, {!r}, specified for a custom '
                'grid attribute name.  See the full list of valid internal '
                'names below:\n\n{}'.format(k, list(GRID_ATTRS.keys())))
        attrs[k] = (v, )

    dims_and_vars = set(data.variables).union(set(data.dims))
    for name_int, names_ext in attrs.items():
        data_coord_name = set(names_ext).intersection(dims_and_vars)
        if data_coord_name:
            data = data.rename({data_coord_name.pop(): name_int})
    return set_grid_attrs_as_coords(data)
Rename grid attributes to be consistent with aospy conventions.

    Search all of the dataset's coords and dims looking for matches to known
    grid attribute names; any that are found subsequently get renamed to the
    aospy name as specified in ``aospy.internal_names.GRID_ATTRS``.

    Also forces any renamed grid attribute that is saved as a dim without a
    coord to have a coord, which facilitates subsequent slicing/subsetting.

    This function does not compare to Model coordinates or add missing
    coordinates from Model objects.

    Parameters
    ----------
    data : xr.Dataset
    grid_attrs : dict (default None)
        Overriding dictionary of grid attributes mapping aospy internal
        names to names of grid attributes used in a particular model.

    Returns
    -------
    xr.Dataset
        Data returned with coordinates consistent with aospy
        conventions