def get_nvss_map(nside=None): map_filepath = os.path.join(DATA_PATH, 'NVSS', 'nvss_map_n512.fits') mask_filepath = os.path.join(DATA_PATH, 'NVSS', 'nvss_mask_n0512.fits') map, mask = hp.read_map(map_filepath), hp.read_map(mask_filepath) rotator = Rotator(coord=['G', 'C']) map = rotator.rotate_map_pixel(map) mask = rotator.rotate_map_pixel(mask) map, mask = tansform_map_and_mask_to_nside(map, mask, nside=nside) map = get_masked_map(map, mask) return map, mask
def get_cmb_temperature_map(nside=None): filename = 'COM_CMB_IQU-smica_2048_R3.00_full.fits' # Read map = hp.read_map(os.path.join(DATA_PATH, 'Planck2018', filename), field=cmb_columns_idx.I_STOKES) mask = hp.read_map(os.path.join(DATA_PATH, 'Planck2018', filename), field=cmb_columns_idx.TMASK) # Rotate rotator = Rotator(coord=['G', 'C']) map = rotator.rotate_map_pixel(map) mask = rotator.rotate_map_pixel(mask) # Adjust map, mask = tansform_map_and_mask_to_nside(map, mask, nside=nside) map = get_masked_map(map, mask) mask = get_masked_map(mask, mask) return map, mask
def test_rotate_dipole_and_back(): """Rotate a smooth signal (dipole) from Galactic to Ecliptic and back""" nside = 64 npix = hp.nside2npix(nside) pix = np.arange(npix) vec = np.array(hp.pix2vec(nside, pix)) # dipole max is at North Pole dip_dir = np.array([0, 0, 1]) m_gal = np.dot(vec.T, dip_dir) gal2ecl = Rotator(coord=["C", "E"]) ecl2gal = Rotator(coord=["E", "C"]) m_ecl = gal2ecl.rotate_map_pixel(m_gal) # Remove 10 deg along equator because dipole signal is so low that relative error is # too large cut_equator_deg = 5 no_equator = hp.query_strip(nside, np.radians(90 + cut_equator_deg), np.radians(90 - cut_equator_deg)) np.testing.assert_allclose(m_gal[no_equator], ecl2gal.rotate_map_pixel(m_ecl)[no_equator], rtol=1e-3)
def test_rotate_dipole_and_back(): """Rotate a smooth signal (dipole) from Galactic to Ecliptic and back""" nside = 64 npix = hp.nside2npix(nside) pix = np.arange(npix) vec = np.array(hp.pix2vec(nside, pix)) # dipole max is at North Pole dip_dir = np.array([0, 0, 1]) m_gal = np.dot(vec.T, dip_dir) gal2ecl = Rotator(coord=["C", "E"]) ecl2gal = Rotator(coord=["E", "C"]) m_ecl = gal2ecl.rotate_map_pixel(m_gal) # Remove 10 deg along equator because dipole signal is so low that relative error is # too large cut_equator_deg = 5 no_equator = hp.query_strip( nside, np.radians(90 + cut_equator_deg), np.radians(90 - cut_equator_deg) ) np.testing.assert_allclose( m_gal[no_equator], ecl2gal.rotate_map_pixel(m_ecl)[no_equator], rtol=1e-3 )
def get_cmb_lensing_map(nside=None): folder_path = os.path.join(DATA_PATH, 'Planck2018/COM_Lensing_2048_R2.00') map_path = os.path.join(folder_path, 'dat_klm.fits') mask_path = os.path.join(folder_path, 'mask.fits') # Read klm = hp.read_alm(map_path) map = hp.alm2map(klm, nside) mask = hp.read_map(mask_path) # Rotate rotator = Rotator(coord=['G', 'C']) map = rotator.rotate_map_pixel(map) mask = rotator.rotate_map_pixel(mask) # Adjust mask = nmt.mask_apodization(mask, 0.2, apotype='C1') mask = hp.ud_grade(mask, nside_out=nside) mask[mask < 0.1] = 0 # Visualization purpose map = get_masked_map(map, mask) mask = get_masked_map(mask, mask) return map, mask
def test_rotate_map_polarization_with_spectrum(): """Rotation of reference frame should not change the angular power spectrum. In this test we create a map from a spectrum with a pure EE signal and check that the spectrum of this map and the spectrum of the same map rotated from Galactic to Ecliptic agrees. This test checks if the QU rotation is correct""" nside = 32 cl = np.zeros((6, 96), dtype=np.double) # Set ell=1 for EE to 1 cl[1][2] = 1 gal2ecl = Rotator(coord=["G", "E"]) m_original = hp.synfast(cl, nside=nside, new=True) cl_from_m_original = hp.anafast(m_original) m_rotated = gal2ecl.rotate_map_pixel(m_original) cl_from_m_rotated = hp.anafast(m_rotated) assert np.abs(cl_from_m_rotated - cl_from_m_original).sum() < 1e-2
def test_rotate_map_polarization(): """Compare to a rotation from Galactic to Ecliptic of a map of pure Q polarization, the expected value was computed with HEALPix IDL: https://gist.github.com/zonca/401069e1c520e02eaff8cd86149d5900 """ nside = 32 npix = hp.nside2npix(nside) QU_gal = np.zeros((2, npix), dtype=np.double) QU_gal[0, :npix // 2] = 1 gal2ecl = Rotator(coord=["G", "E"]) QU_ecl = gal2ecl.rotate_map_pixel(QU_gal) expected = hp.ma( hp.read_map(os.path.join(path, "data", "justq_gal2ecl.fits.gz"), [0, 1])) expected.mask = expected == 0 for i_pol, pol in enumerate("QU"): assert ((np.abs(expected[i_pol] - QU_ecl[i_pol]) < .05).sum() / np.logical_not(expected[i_pol].mask).sum()) > .9, ( pol + " comparison failed in rotate_map")
def test_rotate_map_polarization(): """Compare to a rotation from Galactic to Ecliptic of a map of pure Q polarization, the expected value was computed with HEALPix IDL: https://gist.github.com/zonca/401069e1c520e02eaff8cd86149d5900 """ nside = 32 npix = hp.nside2npix(nside) QU_gal = np.zeros((2, npix), dtype=np.double) QU_gal[0, : npix // 2] = 1 gal2ecl = Rotator(coord=["G", "E"]) QU_ecl = gal2ecl.rotate_map_pixel(QU_gal) expected = hp.ma( hp.read_map(os.path.join(path, "data", "justq_gal2ecl.fits.gz"), [0, 1]) ) expected.mask = expected == 0 for i_pol, pol in enumerate("QU"): assert ( (np.abs(expected[i_pol] - QU_ecl[i_pol]) < .05).sum() / np.logical_not(expected[i_pol].mask).sum() ) > .9, (pol + " comparison failed in rotate_map")