def combine_quality( dqarr1, dqarr2 ):
    """

    Combines two data quality arrays to make a third.
    
    The bitwise nature of the data quality flags means that two
    arrays can be combined without needing to know the meaning
    of the underlying flags.
    
    :Parameters:
            
    dqarr1: numpy array or None
        numpy array which represents a dq plane (or part of it).
        Can be None if there is no data quality information.
    dqarr2: numpy array or None
        numpy array which represents another dq plane (or part of it).
        Can be None if there is no data quality information.
    
    :Returns:
    
    newdq: numpy array
        numpy array containing a combination of both DQ arrays.
        Can be None if both of the input arrays are None.
    
    """
    # Check which of the arrays are defined.
    if dqarr1 is not None and dqarr2 is not None:
        # There are two quality arrays - merge them.
        # The bitwise OR operation combines the effect of the flags
        # without the need to know what they mean.
        newdq = dqarr1 | dqarr2
    elif dqarr1 is not None:
        # Only array 1 is defined - return it.
        newdq = dqarr1
    elif dqarr2 is not None:
        # Only array 2 is defined - return it.
        newdq = dqarr2
    else:
        # Neither array is defined - return None.
        newdq = None
    return newdq