def genGRF(iMock):
    print("- generating mock " + str(iMock))
    # set the random seed
    np.random.seed(iMock)
    # Generate GRF healpix map
    hpGrfMap = hp.synfast(Cl,
                          nSide,
                          lmax=None,
                          mmax=None,
                          alm=False,
                          pol=False,
                          pixwin=False,
                          fwhm=0.0,
                          sigma=None,
                          new=False,
                          verbose=False)
    # save healpix map
    hp.write_map(pathOut + "hp_mock_" + str(iMock) + "_grf_f150_daynight.fits",
                 hpGrfMap,
                 overwrite=True)
    # Convert to pixell CAR map
    grfMap = reproject.enmap_from_healpix(hpGrfMap, hitShape, hitWcs, rot=None)
    # save CAR map
    enmap.write_map(pathOut + "mock_" + str(iMock) + "_grf_f150_daynight.fits",
                    grfMap)
Ejemplo n.º 2
0
    def observe(self,freq_GHz,noise_ukarcmin=3.,beam_fwhm_arcmin=8.):

        import pysm3
        import pysm3.units as u
        #np.random.seed(213114124+int(freq_GHz))

        beam = gauss_beam(np.arange(self.lmax_sim+10),beam_fwhm_arcmin)#hp.gauss_beam(beam_fwhm_arcmin*(np.pi/60./180),lmax=3*self.nside)
        beam[beam==0] = np.inf
        beam = 1/beam

        shape,wcs = enmap.fullsky_geometry(self.pixRes_arcmin)

        Q_noise = np.sqrt(2)*noise_ukarcmin*(np.pi/180/60)*curvedsky.rand_map(shape, wcs, beam**2)
        U_noise = np.sqrt(2)*noise_ukarcmin*(np.pi/180/60)*curvedsky.rand_map(shape, wcs, beam**2)

        sky = pysm3.Sky(nside=self.nside_pysm,preset_strings=["d1","s1"],output_unit="K_CMB")
        # Get the map at the desired frequency:
        I,Q_foreground,U_foreground = sky.get_emission(freq_GHz*u.GHz)*1e6

        I,Q_foreground,U_foreground = reproject.enmap_from_healpix([I,Q_foreground,U_foreground], shape, wcs,
                                  ncomp=3, unit=1, lmax=self.lmax_sim,rot=None)

        Q_map =  self.Q_cmb.copy()
        Q_map += Q_noise
        Q_map += Q_foreground


        U_map =  self.U_cmb.copy()
        U_map += U_noise
        U_map += U_foreground

        return Q_map,U_map
Ejemplo n.º 3
0
def mask_353(en_shape,
             en_wcs,
             intensity_cutoff=None,
             area_cutoff=None,
             fname_353="HFI_353_IQU_smooth.fits",
             return_healpix=False):
    """
    Returns binary mask based on total polarized intensity at 353 GHz.
    
    :param en_shape: shape of the output enmap
    :param en_wcs: wcs parameters of the output enmap
    :param intensity_cutoff: if not None, the mask will remove all pixels where the polarized intensity is larger than the maximum polarized intensity across the sky multiplied by this number.
    :param area_cutoff: if not None, this number sets the sky fraction to be removed (e.g. if set to 0.5, the mask will remove the most contaminated 50% of the sky).
    :param fname_353: path to FITS file containing the 353 map.
    :param return_healpix: if set to True, will return both enmap mask and original HEALPix mask.
    """
    #Read 353 and compute polarized intensity
    hp_tqu = np.array(hp.read_map(fname_353, field=[0, 1, 2], verbose=False))
    hp_p = np.sqrt(hp_tqu[1]**2 + hp_tqu[2]**2)

    #Set intensity cutoff (as a fraction of maximum intensity)
    if intensity_cutoff is not None:
        #This may be set directly as input
        p_cut = intensity_cutoff
    elif area_cutoff is not None:
        #It can be set indirectly by requesting a given total sky fraction
        if area_cutoff >= 1.:
            #Just pick everything
            p_cut = 1.001
        else:
            #Find cutoff value that selects the right sky fraction
            hist, b = np.histogram(np.log10(hp_p), bins=200)
            b = 0.5 * (b[1:] + b[:-1])
            hist = np.cumsum(hist) / np.sum(hist + 0.)
            p_cut = 10.**(b[np.where(
                hist > area_cutoff)[0][0]]) / np.amax(hp_p)
    else:
        #If none are selected, we just return 1 everywhere
        p_cut = 1.0001

    #Create healpix mask
    hp_mask = np.ones_like(hp_p)
    hp_mask[hp_p >= p_cut * np.amax(hp_p)] = 0.

    #Transform to enmap
    en_mask = reproject.enmap_from_healpix(hp_mask,
                                           en_shape,
                                           en_wcs,
                                           ncomp=1,
                                           rot='gal,equ')
    #Transformation will yield floating point numbers other than 1 and 0. Binarize.
    en_mask[en_mask > 0.9] = 1
    en_mask[en_mask <= 0.9] = 0

    if return_healpix:
        return en_mask, hp_mask
    else:
        return en_mask
# In[ ]:


# fig=plt.figure(0)
# hp.mollview(planckMask, fig=0, title="Planck Galactic mask", coord=None, cbar=True, unit='')
# # fig.savefig(pathFig+"planck_mask_C_thresh.pdf")
# # fig.clf()
# plt.show()


# In[ ]:


# convert to enmap
planckMask = reproject.enmap_from_healpix(planckMask, footMask.shape, footMask.wcs, rot=None)


# In[ ]:


# plot=enplot.plot(planckMask, downgrade=16)
# enplot.show(plot)


# # Read PS mask

# In[ ]:


pathPSMask = "/global/cscratch1/sd/eschaan/project_ksz_act_planck/data/act_ps_mask/source_mask_s16_simonecat_sn5_cross_20171105.fits"
Ejemplo n.º 5
0
            szlab = "SMICA-nosz (PR3)"


        if redo:

            bin_edges = np.arange(20,3000,20)
            binner = stats.bin2D(modlmap,bin_edges)

            if methodp=='sz':
                ppath = "/scratch/r/rbond/msyriac/data/planck/data/pr2/"
                alm = hp.read_alm(ppath + 'COM_CMB_IQU-smica-field-Int_2048_R2.01_full_alm.fits',hdu=1) * 1e6
            elif methodp=='nosz':
                ppath = "/scratch/r/rbond/msyriac/data/planck/data/pr3/"
                alm = hp.read_alm(ppath + 'COM_CMB_IQU-smica-nosz_2048_R3.00_full_alm.fits',hdu=1) * 1e6
                
            imap = reproject.enmap_from_healpix(alm, shape, wcs, ncomp=1, unit=1, lmax=6000,
                                                rot="gal,equ", first=0, is_alm=True, return_alm=False) * mask
            #io.hplot(enmap.downgrade(imap,4),"ymap_%s_%s" % (region,method),grid=True,color='gray')

            nside = 2048
            pixwin = hp.pixwin(nside=nside,pol=False)
            pls = np.arange(len(pixwin))
            pwin = maps.interp(pls,pixwin)(modlmap)


            kmap = enmap.fft(imap,normalize='phys')/maps.gauss_beam(modlmap,fwhm)*maps.gauss_beam(modlmap,dfwhm) /pwin
            kmap[~np.isfinite(kmap)] = 0 
            p2d = (kmap*kmap.conj()).real / w2

            cents,p1d = binner.bin(p2d)
            io.save_cols(os.environ['WORK']+"/cpower_planck_%s_%s.txt" % (region,method), (cents,p1d))
        else:
Ejemplo n.º 6
0
pl.add(ls,nls,ls="--",label='theory noise per mode')
pl._ax.set_xlim(20,4000)
pl.done(config['data_path']+"xcls_%s.png" % polcomb)


# Filtered input
fikalm = hp.almxfl(ikalm,wfilt)
fimap = hp.alm2map(fikalm,nside=256)



# Resampled mask
dmask = hp.ud_grade(mask,nside_out=256)
dmask[dmask<0] = 0


# Mollview plots
io.mollview(frmap*dmask,config['data_path']+"wrmap1.png",xsize=1600,lim=8e-6)
io.mollview(fimap*dmask,config['data_path']+"wimap1.png",xsize=1600,lim=8e-6)

# CAR plots
shape,wcs = enmap.band_geometry(np.deg2rad((-70,30)),res=np.deg2rad(0.5*8192/512/60.))
omask = reproject.enmap_from_healpix(dmask, shape, wcs,rot=None)
omap = cs.alm2map(fkalm, enmap.empty(shape,wcs))
io.hplot(omap*omask,config['data_path']+"cwrmap1",grid=True,ticks=20,color='gray')
omap = cs.alm2map(fikalm, enmap.empty(shape,wcs))
io.hplot(omap*omask,config['data_path']+"cwimap1",grid=True,ticks=20,color='gray')



Ejemplo n.º 7
0
decs = np.array(decs0)
ms = np.array(ms0)
print("Number of halos above the given mass = ", len(ras))

# stamp size and resolution
px = 0.5
width = 120. / 60.
maxr = width * utils.degree / 2.0

# read maps
fshape, fwcs = enmap.fullsky_geometry(res=px * utils.arcmin, proj='car')
imap = f'{my_sim_path}/kap_lt4.5.fits'
kmap = reproject.enmap_from_healpix(imap,
                                    fshape,
                                    fwcs,
                                    ncomp=1,
                                    unit=1,
                                    lmax=6000,
                                    rot=None)
print(kmap.shape)

filename = f'{my_sim_path}/lensed_alm.fits'
alm = np.complex128(hp.read_alm(filename, hdu=(1, 2, 3)))
#print(alm.shape) (3, 34043626)
ncomp = 1
omap = enmap.empty((ncomp, ) + fshape[-2:], fwcs, dtype=np.float64)
lmap = curvedsky.alm2map(alm, omap, spin=[0, 2], oversample=2.0, method="auto")
print(lmap.shape)

tap_per = 12.0
pad_per = 3.0
Ejemplo n.º 8
0
                            color='gray')
        enplot.write("madcows/stamps/act_en_mc_stamp" + str(i), plots)

#########################################################################################################################################################################################

print("Starting Planck Maps")

planck_file_name = '/maps/HFI_SkyMap_143_2048_R2.02_full.fits'

#shape,wcs = enmap.geometry(shape=(1024,1024),res=np.deg2rad(0.5/60.),pos=(0,0))
shape, wcs = enmap.fullsky_geometry(res=5.0 * utils.arcmin, proj='car')

pmap = reproject.enmap_from_healpix(planck_file_name,
                                    shape,
                                    wcs,
                                    ncomp=1,
                                    unit=1,
                                    lmax=6000,
                                    rot="gal,equ")

plots = enplot.plot(pmap, range=300, mask=0)

enplot.write("planck_map", plots)

t = QTable.read('madcows/AdvACT_S18Clusters_v1.0-beta.fits')
ra_temp = t['RADeg']
dec_temp = t['decDeg']
ra, dec = np.array(ra_temp), np.array(dec_temp)
s18stack = stack(ra, dec, pmap)
plots = enplot.plot(enmap.upgrade(s18stack, 5),
                    grid=False,