Exemplo n.º 1
0
def fit_beam(
    imap,
    coords,
    fwhm,
    ps,
    noise,
    r=5 * u.arcmin,
    verbose=False,
):
    """Given an enmap [...,ny,nx] and a set of coords [n,{dec,ra}], extract a set
	of cutouts [n,...,thumby,thumbx] centered on each set of
	coordinates. Fit a beam to each cutout, and return the fluxes."""

    print("Getting thumbnails...")
    thumbs = reproject.thumbnails(imap, coords, r=r, proj='tan', pixwin=False)

    shape, wcs = thumbs.shape[-2:], thumbs.wcs
    ivar = maps.ivar(shape, wcs, noise)

    print("Initializing fitter...")
    pfitter = ptfit.Pfit(shape,
                         wcs,
                         rbeam=None,
                         div=ivar,
                         ps=ps,
                         beam=fwhm,
                         n2d=None,
                         invert=False)

    nthumbs = coords.shape[0]
    rbeam = maps.sigma_from_fwhm(np.deg2rad(fwhm / 60.))
    fluxes = []
    print("Fitting thumbnails...")
    for i in range(nthumbs):
        pflux, cov, fit, _ = pfitter.fit(thumbs[i], dec=0, ra=0, rbeam=rbeam)
        fluxes.append(pflux[0])
        print(f"Source {i+1} / {nthumbs} done.")
    fluxes = np.asarray(fluxes)

    out = np.zeros((nthumbs, 3))
    out[:, 0] = coords[:, 0]
    out[:, 1] = coords[:, 1]
    out[:, 2] = fluxes
    print("Making source map")
    smap = pointsrcs.sim_srcs(imap.shape[-2:], imap.wcs, out, rbeam)

    return smap
Exemplo n.º 2
0
pl.add(nus,tdust,label='Dust',color='C2')
pl.done("fg_SED.png")

sys.exit()

qids = "d56_01,d56_02,d56_03,d56_04,d56_05,d56_06,p01,p02,p03,p04,p05,p06,p07,p08".split(',')
beams = [1.4,1.4,1.4,1.4,2.2,1.4,32.408,27.100,13.315,9.69,7.30,5.02,4.94,4.83]
region = 'deep56'

mask = sints.get_act_mr3_crosslinked_mask(region)
shape,wcs = mask.shape,mask.wcs

aspecs = tutils.ASpecs().get_specs
for i,qid in enumerate(qids):

    lmin,lmax,hybrid,radial,friend,cfreq,fgroup,wrfit = aspecs(qid)
    nu = cfreq
    dec = 0
    ra = 10
    srcs = np.array([[np.deg2rad(dec),np.deg2rad(ra),ffunc(nu,fg)]])
    beam = maps.sigma_from_fwhm(np.deg2rad(beams[i]/60)) 

    imap = pointsrcs.sim_srcs(shape, wcs, srcs, beam, omap=None, dtype=None, nsigma=5, rmax=None, smul=1,
                              return_padded=False, pixwin=False, op=np.add, wrap="auto", verbose=False, cache=None)

    #cut = reproject.cutout(imap,ra=np.deg2rad(ra),dec=np.deg2rad(dec),npix=60)
    kmap = enmap.fft(imap,normalize='phys')
    np.save("/scratch/r/rbond/msyriac/data/depot/tilec/%s_src_test_v1.0.0_rc_deep56/kcoadd_%s.npy" % (fg.lower(),qid), kmap)
    print(qid)
    #io.plot_img(cut)
Exemplo n.º 3
0
    for k, (ra, dec) in enumerate(zip(ras, decs)):
        if np.abs(np.rad2deg(dec)) > decmax: continue
        #if iamps[k]>-500: continue # !!!
        # if sns[k]<20: continue
        # if k<300 or k>400: continue
        if evals[k] < 3: continue

        stamp = reproject.cutout(imap, ra=ra, dec=dec, pad=1, npix=npix)

        if stamp is None: continue
        divstamp = reproject.cutout(div, ra=ra, dec=dec, pad=1, npix=npix)
        famp, cov, pfit = ptfit.ptsrc_fit(stamp,
                                          dec,
                                          ra,
                                          maps.sigma_from_fwhm(
                                              np.deg2rad(pfwhm / 60.)),
                                          div=divstamp,
                                          ps=ps,
                                          beam=pfwhm,
                                          n2d=None)
        # model = pointsrcs.sim_srcs(stamp.shape, stamp.wcs,
        #                            np.array((dec,ra,famp.reshape(-1)[0]))[None],
        #                            maps.sigma_from_fwhm(np.deg2rad(pfwhm/60.)))
        # io.plot_img(np.log10(stamp),"stamp_%d.png" % k)
        # io.plot_img(divstamp,"divstamp_%d.png"  % k)
        # io.plot_img(model,"model_%d.png"  % k)
        # io.plot_img(stamp-model,"residual_%d.png"  % k)

        # if k==1: sys.exit()
        sdecs.append(dec)
        sras.append(ra)
Exemplo n.º 4
0
beam_fn = lambda x: maps.gauss_beam(x, fwhm)

# Random sources

np.random.seed(10)

cosdecs = np.random.uniform(-1, 1, N)
srcs = np.zeros((N, 3))
srcs[:, 0] = np.arccos(cosdecs) - np.pi / 2.
srcs[:, 1] = np.random.uniform(0, 2. * np.pi, N)
srcs[:, 2] = 1000  # uK peak signal
coords = srcs[:, :2]

# Simulate sources
smap = pointsrcs.sim_srcs(shape[-2:], wcs, srcs,
                          maps.sigma_from_fwhm(fwhm * u.arcmin))

# Q/U sources with 1% flux
smap = np.repeat(smap[None, ...], 3, 0)
smap[1:] = smap[1:] / 100

# 2 arcmin full sky geometry
shape, wcs = enmap.fullsky_geometry(res=2.0 * u.arcmin)
shape = (3, ) + shape

# Noise maps
nmap = maps.white_noise(shape, wcs, noise)
nmap[1:, ...] = nmap[1:, ...] * np.sqrt(2.)

# Observed map
imap = cs.filter(maps.rand_cmb_sim(shape, wcs, lmax), beam_fn,