def _norm_from_ccorr_data(data, norm=None):
    """Determines normalization type from ccorr data"""
    try:
        d, c, sq, s1, s2 = data
    except ValueError:
        raise ValueError('Not a valid correlation data')
    if s1 is None:
        if sq is None:
            default_norm = 0
            available_norm = 0
        else:
            default_norm = 4
            available_norm = 5
    elif sq is None:
        default_norm = 2
        available_norm = 2
    else:
        default_norm = 6
        available_norm = 7
    if norm is None:
        return default_norm
    else:
        if norm not in range(8):
            raise ValueError('Normalization mode must be in range(8)')
        if norm & available_norm == norm:
            return norm
        else:
            raise ValueError('Normalization mode incompatible with input data.'
                )
