def transform_basis(nside, jones, z0_cza, R_z0): npix = hp.nside2npix(nside) hpxidx = np.arange(npix) cza, ra = hp.pix2ang(nside, hpxidx) fR = R_z0 tb, pb = irf.rotate_sphr_coords(fR, cza, ra) cza_v = irf.t_hat_cart(cza, ra) ra_v = irf.p_hat_cart(cza, ra) tb_v = irf.t_hat_cart(tb, pb) fRcza_v = np.einsum('ab...,b...->a...', fR, cza_v) fRra_v = np.einsum('ab...,b...->a...', fR, ra_v) cosX = np.einsum('a...,a...', fRcza_v, tb_v) sinX = np.einsum('a...,a...', fRra_v, tb_v) basis_rot = np.array([[cosX, -sinX],[sinX, cosX]]) basis_rot = np.transpose(basis_rot,(2,0,1)) # return np.einsum('...ab,...bc->...ac', jones, basis_rot) return irnf.M(jones, basis_rot)
def transform_basis(nside, jones, z0_cza, R_z0): npix = hp.nside2npix(nside) hpxidx = np.arange(npix) cza, ra = hp.pix2ang(nside, hpxidx) fR = R_z0 tb, pb = irf.rotate_sphr_coords(fR, cza, ra) cza_v = irf.t_hat_cart(cza, ra) ra_v = irf.p_hat_cart(cza, ra) tb_v = irf.t_hat_cart(tb, pb) fRcza_v = np.einsum('ab...,b...->a...', fR, cza_v) fRra_v = np.einsum('ab...,b...->a...', fR, ra_v) cosX = np.einsum('a...,a...', fRcza_v, tb_v) sinX = np.einsum('a...,a...', fRra_v, tb_v) basis_rot = np.array([[cosX, -sinX], [sinX, cosX]]) basis_rot = np.transpose(basis_rot, (2, 0, 1)) # return np.einsum('...ab,...bc->...ac', jones, basis_rot) return irnf.M(jones, basis_rot)
def transform_basis(nside, jones, z0_cza, R_z0): """ At zenith in the local frame the 'x' feed is aligned with 'theta' and the 'y' feed is aligned with 'phi' """ npix = hp.nside2npix(nside) hpxidx = np.arange(npix) cza, ra = hp.pix2ang(nside, hpxidx) # Rb is the rotation relating the E-field basis coordinate frame to the local horizontal zenith. # (specific to this instrument response simulation data) Rb = np.array([[0, 0, -1], [0, -1, 0], [-1, 0, 0]]) fR = np.einsum('ab,bc->ac', Rb, R_z0) # matrix product of two rotations tb, pb = irf.rotate_sphr_coords(fR, cza, ra) cza_v = irf.t_hat_cart(cza, ra) ra_v = irf.p_hat_cart(cza, ra) tb_v = irf.t_hat_cart(tb, pb) fRcza_v = np.einsum('ab...,b...->a...', fR, cza_v) fRra_v = np.einsum('ab...,b...->a...', fR, ra_v) cosX = np.einsum('a...,a...', fRcza_v, tb_v) sinX = np.einsum('a...,a...', fRra_v, tb_v) basis_rot = np.array([[cosX, sinX], [-sinX, cosX]]) basis_rot = np.transpose(basis_rot, (2, 0, 1)) return irnf.M(jones, basis_rot)
def transform_basis(nside, jones, z0_cza, R_z0): """ At zenith in the local frame the 'x' feed is aligned with 'theta' and the 'y' feed is aligned with 'phi' """ npix = hp.nside2npix(nside) hpxidx = np.arange(npix) cza, ra = hp.pix2ang(nside, hpxidx) # Rb is the rotation relating the E-field basis coordinate frame to the local horizontal zenith. # (specific to this instrument response simulation data) Rb = np.array([ [0,0,-1], [0,-1,0], [-1,0,0] ]) fR = np.einsum('ab,bc->ac', Rb, R_z0) # matrix product of two rotations tb, pb = irf.rotate_sphr_coords(fR, cza, ra) cza_v = irf.t_hat_cart(cza, ra) ra_v = irf.p_hat_cart(cza, ra) tb_v = irf.t_hat_cart(tb, pb) fRcza_v = np.einsum('ab...,b...->a...', fR, cza_v) fRra_v = np.einsum('ab...,b...->a...', fR, ra_v) cosX = np.einsum('a...,a...', fRcza_v, tb_v) sinX = np.einsum('a...,a...', fRra_v, tb_v) basis_rot = np.array([[cosX, sinX],[-sinX, cosX]]) basis_rot = np.transpose(basis_rot,(2,0,1)) return irnf.M(jones, basis_rot)
def make_jones(freq): if freq in range(90, 221): pass else: raise ValueError('Frequency is not available.') nside = 512 # make this as large as possible to minimize singularity effects at zenith ## nside 512 seems to work well enough using the "neighbours of neighbours" patch ## of the zenith singularity in the ra/cza basis. npix = hp.nside2npix(nside) hpxidx = np.arange(npix) t, p = hp.pix2ang(nside, hpxidx) g1 = ecomp(csvname(freq, 'G', 'X'), csvname(freq, 'P', 'X')) g2 = ecomp(csvname(freq, 'G', 'Y'), csvname(freq, 'P', 'Y')) I = (abs(g1)**2. + abs(g2)**2.) norm = np.sqrt(np.amax(I, axis=0)) # g1 /= norm # g2 /= norm rhm = irf.rotate_healpix_map Rb = np.array([[0, 0, -1], [0, -1, 0], [-1, 0, 0]]) Et_b = udgrade(g1.real, nside) + 1j * udgrade(g1.imag, nside) Ep_b = udgrade(g2.real, nside) + 1j * udgrade(g2.imag, nside) tb, pb = irf.rotate_sphr_coords(Rb, t, p) tb_v = irf.t_hat_cart(tb, pb) pb_v = irf.p_hat_cart(tb, pb) t_v = irf.t_hat_cart(t, p) p_v = irf.p_hat_cart(t, p) Rb_tb_v = np.einsum('ab...,b...->a...', Rb, tb_v) Rb_pb_v = np.einsum('ab...,b...->a...', Rb, pb_v) cosX = np.einsum('a...,a...', Rb_tb_v, t_v) sinX = np.einsum('a...,a...', Rb_pb_v, t_v) Et = Et_b * cosX + Ep_b * sinX Ep = -Et_b * sinX + Ep_b * cosX Ext = Et Exp = Ep ## This assumes that Et and Ep are the components of a dipole oriented ## along the X axis, and we want to obtain the components of the same ## dipole if it was oriented along Y. ## In the current basis, this is done by a scalar rotation of the theta and phi ## components by 90 degrees about the Z axis. Eyt = arm(Et.real) + 1j * arm(Et.imag) Eyp = arm(Ep.real) + 1j * arm(Ep.imag) jones_c = np.array([[Ext, Exp], [Eyt, Eyp]]).transpose(2, 0, 1) # jones_a = np.array([[rhm(Ext,Rb), rhm(Exp,Rb)],[rhm(Eyt,Rb),rhm(Eyp,Rb)]]).transpose(2,0,1) # # basis_rot = np.array([[cosX,-sinX],[sinX,cosX]]).transpose(2,0,1) # # jones_b = np.einsum('...ab,...bc->...ac', jones_a, basis_rot) # # Ext_b, Exp_b, Eyt_b, Eyp_b = [rhm(jones_b[:,i,j],Rb) for i in range(2) for j in range(2)] # # jones_c = np.array([[Ext_b,Exp_b],[Eyt_b,Eyp_b]]).transpose(2,0,1) return jones_c
def make_jones(freq): if freq in range(90,221): pass else: raise ValueError('Frequency is not available.') nside = 512 # make this as large as possible to minimize singularity effects at zenith ## nside 512 seems to work well enough using the "neighbours of neighbours" patch ## of the zenith singularity in the ra/cza basis. npix = hp.nside2npix(nside) hpxidx = np.arange(npix) t,p = hp.pix2ang(nside,hpxidx) g1 = ecomp(csvname(freq,'G','X'),csvname(freq,'P','X')) g2 = ecomp(csvname(freq,'G','Y'),csvname(freq,'P','Y')) I = (abs(g1)**2. + abs(g2)**2.) norm = np.sqrt(np.amax(I, axis=0)) g1 /= norm g2 /= norm rhm = irf.rotate_healpix_map Rb = np.array([ [0,0,-1], [0,-1,0], [-1,0,0] ]) Et_b = udgrade(g1.real, nside) + 1j * udgrade(g1.imag, nside) Ep_b = udgrade(g2.real, nside) + 1j * udgrade(g2.imag, nside) tb,pb = irf.rotate_sphr_coords(Rb, t, p) tb_v = irf.t_hat_cart(tb,pb) pb_v = irf.p_hat_cart(tb,pb) t_v = irf.t_hat_cart(t,p) p_v = irf.p_hat_cart(t,p) Rb_tb_v = np.einsum('ab...,b...->a...', Rb, tb_v) Rb_pb_v = np.einsum('ab...,b...->a...', Rb, pb_v) cosX = np.einsum('a...,a...', Rb_tb_v,t_v) sinX = np.einsum('a...,a...', Rb_pb_v,t_v) Et = Et_b * cosX + Ep_b * sinX Ep = -Et_b * sinX + Ep_b * cosX Ext = Et Exp = Ep ## This assumes that Et and Ep are the components of a dipole oriented ## along the X axis, and we want to obtain the components of the same ## dipole if it was oriented along Y. ## In the current basis, this is done by a scalar rotation of the theta and phi ## components by 90 degrees about the Z axis. Eyt = arm(Et.real) + 1j*arm(Et.imag) Eyp = arm(Ep.real) + 1j*arm(Ep.imag) jones_c = np.array([[Ext,Exp],[Eyt,Eyp]]).transpose(2,0,1) # jones_a = np.array([[rhm(Ext,Rb), rhm(Exp,Rb)],[rhm(Eyt,Rb),rhm(Eyp,Rb)]]).transpose(2,0,1) # # basis_rot = np.array([[cosX,-sinX],[sinX,cosX]]).transpose(2,0,1) # # jones_b = np.einsum('...ab,...bc->...ac', jones_a, basis_rot) # # Ext_b, Exp_b, Eyt_b, Eyp_b = [rhm(jones_b[:,i,j],Rb) for i in range(2) for j in range(2)] # # jones_c = np.array([[Ext_b,Exp_b],[Eyt_b,Eyp_b]]).transpose(2,0,1) return jones_c