import yaml


def read_yaml(filename):
    """
    Read a yaml file into a dictionary.

    Parameters
    ----------
    filename: `str`
       File to read

    Returns
    -------
    outdict: `dict`
       Dictionary from yaml file

    """

    # The output dictionary
    outdict = {}

    # Open the yaml file and find key/value pairs
    with open(filename) as f: yaml_data = yaml.load(f, Loader=yaml.SafeLoader)
    for tag in outdict:
        if outdict[tag] is None:
            raise ValueError('A value for the required tag \"'
                                + tag + '\" must be specified.')

    # Add the pairs to the dictionary
    for tag in yaml_data: outdict[tag] = yaml_data[tag]

    return outdict