def average_index(n1, n2, v1=None, v2=None, vr=None):
    """Compute volume weighted average refractive index
    Args:
        n1, n2 (float/ndarray): refractive index of material 1 and 2
        v1, v2 (float): volume of materials 1 and 2
        vr (float): volume ratio of v1/(v1+v2) used instead of v1 and v2
    """ 
    if vr is None:
        if v1 or v2 is None:
            raise ValueError("Please supply volumes v1, v2 "
                             "or volume ratio vr")
        n = (v1*n1 + v2*n2)/(v1+v2)
    else:
        # n = (vr*n1 + n2)/(vr+1) when vr = v1/v2
        n = vr*n1 + (1-vr)*n2
    return n