def check_pes(epi_fmaps, pe_dir):
    """Check whether there are images with matched PE."""
    opposed_pe = False
    matched_pe = False
    for _, fmap_pe in epi_fmaps:
        if fmap_pe == pe_dir:
            matched_pe = True
        elif fmap_pe[0] == pe_dir[0]:
            opposed_pe = True
    if not opposed_pe:
        raise ValueError(
            'None of the discovered fieldmaps has the right phase encoding direction. This is possibly a problem with metadata. If not, rerun with ``--ignore fieldmaps`` to skip the distortion correction step.'
            )
    return matched_pe
