def jones2celestial_basis(jones, z0_cza=None):
    if z0_cza is None:
        z0_cza = np.radians(120.7215)

    npix = jones.shape[0]
    nside = hp.npix2nside(npix)

    hpxidx = np.arange(npix)
    cza, ra = hp.pix2ang(nside, hpxidx)

    z0 = irf.r_hat_cart(z0_cza, 0.)

    RotAxis = np.cross(z0, np.array([0, 0, 1.]))
    RotAxis /= np.sqrt(np.dot(RotAxis, RotAxis))
    RotAngle = np.arccos(np.dot(z0, [0, 0, 1.]))

    R_z0 = irf.rotation_matrix(RotAxis, RotAngle)

    ### New
    jones_b = transform_basis(nside, jones, z0_cza, R_z0.T)

    rot = [0., -z0_cza, 0.]
    jones_out = irf.unitary_rotate_jones(jones_b, rot, multiway=True)

    return jones_out
def jones2celestial_basis(jones, z0_cza=None):
    if z0_cza is None:
        z0_cza = np.radians(120.7215)

    npix = jones.shape[0]
    nside = hp.npix2nside(npix)

    hpxidx = np.arange(npix)
    cza, ra = hp.pix2ang(nside, hpxidx)

    z0 = irf.r_hat_cart(z0_cza, 0.)

    RotAxis = np.cross(z0, np.array([0,0,1.]))
    RotAxis /= np.sqrt(np.dot(RotAxis,RotAxis))
    RotAngle = np.arccos(np.dot(z0, [0,0,1.]))

    R_z0 = irf.rotation_matrix(RotAxis, RotAngle)

    jones_b = transform_basis(nside, jones, z0_cza, R_z0.T)

    rot = [0., -z0_cza, 0.]
    jones_out = irf.unitary_rotate_jones(jones_b, rot, multiway=True)

    return jones_out