def expanded_shape(data, packed=False):
    """
    Determine the expanded shape of a 3D array.
    """
    nx, ny, nz = data.shape
    if nx % 2 or ny % 2:
        raise ValueError('First two dimensions of array must be even.')
    if packed:
        if nz % 2 == 0:
            raise ValueError('Last dimension of packed array must be odd.')
        nz = 2 * (nz - 1)
    elif nz % 2:
        raise ValueError('Last dimension of unpacked array must be even.')
    return nx, ny, nz
