def keep_dims(self, keep_dims, *, errors="raise"):
    """
    Keep only certain dimensions and associated variables from this dataset.

    Parameters
    ----------
    keep_dims : hashable or iterable of hashable
        Dimension or dimensions to keep.
    errors : {"raise", "ignore"}, optional
        If 'raise' (default), raises a ValueError error if any of the
        dimensions passed are not in the dataset. If 'ignore', any given
        dimensions that are in the dataset are dropped and no error is raised.

    Returns
    -------
    obj : Dataset
        The dataset without the given dimensions (or any variables
        containing those dimensions)
    """
    if isinstance(keep_dims, str):
        keep_dims = {keep_dims}
    else:
        keep_dims = set(keep_dims)
    all_dims = set(self.dims)
    if errors == "raise":
        missing_dims = keep_dims - all_dims
        if missing_dims:
            raise ValueError(
                f"{self.__class__} does not contain the dimensions: {missing_dims}"
            )
    return self.drop_dims([i for i in all_dims if i not in keep_dims])