def read_flat_parameters(fname):
    """Read flat channel rejection parameters from .cov or .ave config file"""

    try:
        with open(fname, 'r') as f:
            lines = f.readlines()
    except:
        raise ValueError("Error while reading %s" % fname)

    reject_names = ['gradFlat', 'magFlat', 'eegFlat', 'eogFlat', 'ecgFlat']
    reject_pynames = ['grad', 'mag', 'eeg', 'eog', 'ecg']
    flat = dict()
    for line in lines:
        words = line.split()
        if words[0] in reject_names:
            flat[reject_pynames[reject_names.index(words[0])]] = \
                float(words[1])

    return flat