Beispiel #1
0
def inpaint_map_const_cov(imap,mask,union_sources_version=None,noise_pix = 20,hole_radius = 3.,plots=False):
    """

    Inpaints a map under the assumption of constant 2D Fourier covariance. This uses the average PS
    of the full map for the noise model at each source location and thus does not handle inhomogenity.
    Pros: no products needed other than map-maker outputs of map
    Cons: 

    imap -- (npol,Ny,Nx)
    ivar -- (Ny,Nx)
    """

    ras,decs = sints.get_act_mr3f_union_sources(version=union_sources_version)
    kmap = enmap.fft(mask*imap,normalize='phys')

    gtags = []
    gdicts = {}
    pcoords = []
    for i,(ra,dec) in enumerate(zip(ras,decs)):
        sel = reproject.cutout(ivar, ra=np.deg2rad(ra), dec=np.deg2rad(dec), pad=1, corner=False,npix=noise_pix,return_slice=True)
        if sel is None: continue
        civar = ivar[sel]
        if np.any(civar<=0): continue
        modrmap = civar.modrmap()
        modlmap = civar.modlmap()
        res = maps.resolution(civar.shape,civar.wcs)
        cimap = imap[sel]
        print(ra,dec)
        if plots: 
            for p in range(3): io.plot_img(cimap[p],os.environ['WORK']+"/cimap_%d_%s" % (p,str(i).zfill(2)))
            mimap = cimap.copy()
            mimap[...,modrmap<np.deg2rad(hole_radius/60.)] = np.nan
            for p in range(3): io.plot_img(mimap[p],os.environ['WORK']+"/masked_cimap_%d_%s" % (p,str(i).zfill(2)))
        
        scov = pixcov.scov_from_theory(modlmap,cmb_theory_fn,fn_beam,iau=False)
        ncov = pixcov.ncov_from_ivar(civar)
        pcov = scov + ncov
        gdicts[i] = pixcov.make_geometry(hole_radius=np.deg2rad(hole_radius/60.),n=noise_pix,deproject=True,iau=False,pcov=pcov,res=res)
        pcoords.append(np.array((dec,ra)))
        gtags.append(i)

    if len(gtags)>0: 
        pcoords = np.stack(pcoords).swapaxes(0,1)
        result = pixcov.inpaint(imap,pcoords,deproject=True,iau=False,geometry_tags=gtags,geometry_dicts=gdicts,verbose=True)

    if plots:
        for i,(ra,dec) in enumerate(zip(ras,decs)):
            sel = reproject.cutout(ivar, ra=np.deg2rad(ra), dec=np.deg2rad(dec), pad=1, corner=False,npix=noise_pix,return_slice=True)
            if sel is None: continue
            civar = ivar[sel]
            if np.any(civar<=0): continue
            modrmap = civar.modrmap()
            modlmap = civar.modlmap()
            res = maps.resolution(civar.shape,civar.wcs)
            cimap = result[sel]
            print("Inpainted ", ra,dec)
            if plots: 
                for p in range(3): io.plot_img(cimap[p],os.environ['WORK']+"/inpainted_cimap_%d_%s" % (p,str(i).zfill(2)))

    return result
def create_ptsr_mask(nside, ascale=0.5, threshold=.0, radius=10., ptsr='base'):

    # from catalogue
    #ras, decs, size = np.loadtxt('data_local/input/cat_crossmatched.txt',unpack=True,usecols=(0,1,5))
    #RAs  = ras[size>threshold]
    #DECs = decs[size>threshold]
    #arcm = size[size>threshold] * extend

    #RAs, DECs = interfaces.get_act_mr3f_union_sources(version='20200503_sncut_40')
    RAs, DECs = interfaces.get_act_mr3f_union_sources(
        version='20210209_sncut_10_aggressive')
    arcm = np.ones(len(RAs)) * radius

    # additional mask
    if ptsr == 'PT':
        RAs_add = np.array([187.3])
        DECs_add = np.array([2.])
        arcm_add = np.array([40.])
        # add
        RAs = np.concatenate((RAs, RAs_add))
        DECs = np.concatenate((DECs, DECs_add))
        arcm = np.concatenate((arcm, arcm_add))

    # compute 3D positions
    v = hp.pixelfunc.ang2vec(RAs, DECs, lonlat=True)

    # create mask
    maskpt = np.ones(12 * nside**2)

    for i in range(len(arcm)):
        pix = hp.query_disc(nside, v[i], arcm[i] * np.pi / 10800.)
        maskpt[pix] = 0.

    if ascale != 0.:
        maskpt = curvedsky.utils.apodize(nside, maskpt, ascale)

    return maskpt
Beispiel #3
0
print("Number of bright extended sources : ", len(eras))
bras, bdecs = sints.get_act_mr3f_cut_sources()
print("Number of bright cut sources : ", len(bras))

debug = False
rlim = 1.0
jras = np.append(eras, bras)
jdecs = np.append(edecs, bdecs)
ocat = merge_duplicates(jras * utils.degree,
                        jdecs * utils.degree,
                        rlim=rlim * utils.arcmin) / utils.degree
io.save_cols("union_catalog_06192019.csv", (ocat[:, 0], ocat[:, 1]),
             delimiter=',',
             header='ra(deg),dec(deg) | Made using actsims/bin/union_srcs.py.',
             fmt='%.5f')
ras, decs = sints.get_act_mr3f_union_sources()
assert np.all(np.isclose(ras, ocat[:, 0]))
assert np.all(np.isclose(decs, ocat[:, 1]))

if debug:
    xmin = -190
    xmax = 190
    ymin = -70
    ymax = 35
    s = 0.1
    dpi = 100

    plt.scatter(jras, jdecs, s=s, marker=',')
    plt.xlim(xmin, xmax)
    plt.ylim(ymin, ymax)
    plt.savefig("scatter.png", dpi=dpi)
Beispiel #4
0
def inpaint_map_white(imap,ivar,fn_beam,union_sources_version=None,noise_pix = 40,hole_radius = 6.,plots=False,cache_name=None,verbose=True):
    """

    Inpaints a map under the assumption of inhomogenous but white uncorrelated instrument noise.
    Pros: no products needed other than map-maker outputs of map and ivar, good inpainting despite crappy
    noise model.
    Cons: noise model has to be built for each source, so this is actually quite slow.

    imap -- (npol,Ny,Nx)
    ivar -- (Ny,Nx)
    fn_beam -- lambda ells: beam(ells)
    cache_name -- a unique string identifying the catalog+map/array/frequency/split combination to/from which the geometries are cached
    """
   
    if cache_name is not None:
        cache_name = cache_name + "_catversion_%s" % union_sources_version
        try:
            ras,decs,gtags,pcoords,gdicts = load_cached_inpaint_geometries(cache_name)
            do_geoms = False
            if verbose: print("actsims.inpaint: loaded cached geometries for ", cache_name)
        except:
            if verbose: print("actsims.inpaint: no cached geometries found for ", cache_name, ". Generating and saving...")
            do_geoms = True
    else:
        do_geoms = True

    if do_geoms:
        ras,decs = sints.get_act_mr3f_union_sources(version=union_sources_version)
        cmb_theory_fn = lambda s,l: cosmology.default_theory().lCl(s,l)
        gtags = []
        gdicts = {}
        pcoords = []
        for i,(ra,dec) in enumerate(zip(ras,decs)):
            sel = reproject.cutout(ivar, ra=np.deg2rad(ra), dec=np.deg2rad(dec), pad=1, corner=False,npix=noise_pix,return_slice=True)
            if sel is None: continue
            civar = ivar[sel]
            if np.any(civar<=0): continue
            modrmap = civar.modrmap()
            modlmap = civar.modlmap()
            res = maps.resolution(civar.shape,civar.wcs)
            cimap = imap[sel]
            if verbose: print("actsims.inpaint: built noise model for source ",i," / ",len(ras))
            scov = pixcov.scov_from_theory(modlmap,cmb_theory_fn,fn_beam,iau=False)
            ncov = pixcov.ncov_from_ivar(civar)
            pcov = scov + ncov
            gdicts[i] = pixcov.make_geometry(hole_radius=np.deg2rad(hole_radius/60.),n=noise_pix,deproject=True,iau=False,pcov=pcov,res=res)
            pcoords.append(np.array((dec,ra)))
            gtags.append(i)
        if len(gtags)>0: 
            pcoords = np.stack(pcoords).swapaxes(0,1)
        if cache_name is not None:
            save_cached_inpaint_geometries(cache_name,ras,decs,gtags,pcoords,gdicts)
            if verbose: print("actsims.inpaint: cached geometries for ",cache_name)

    if len(gtags)>0: result = pixcov.inpaint(imap,pcoords,deproject=True,iau=False,geometry_tags=gtags,geometry_dicts=gdicts,verbose=verbose)

    if plots:
        for i,(ra,dec) in enumerate(zip(ras,decs)):
            sel = reproject.cutout(ivar, ra=np.deg2rad(ra), dec=np.deg2rad(dec), pad=1, corner=False,npix=noise_pix,return_slice=True)
            if sel is None: continue
            civar = ivar[sel]
            if np.any(civar<=0): continue
            modrmap = civar.modrmap()
            modlmap = civar.modlmap()
            res = maps.resolution(civar.shape,civar.wcs)
            cimap = imap[sel]
            for p in range(3): io.plot_img(cimap[p],os.environ['WORK']+"/cimap_%d_%s" % (p,str(i).zfill(2)))
            mimap = cimap.copy()
            mimap[...,modrmap<np.deg2rad(hole_radius/60.)] = np.nan
            for p in range(3): io.plot_img(mimap[p],os.environ['WORK']+"/masked_cimap_%d_%s" % (p,str(i).zfill(2)))
            cimap = result[sel]
            for p in range(3): io.plot_img(cimap[p],os.environ['WORK']+"/inpainted_cimap_%d_%s" % (p,str(i).zfill(2)))
            
    return result