Пример #1
0
parser.add_argument("--beam-version", type=str,  default=None,help='Mask version')
parser.add_argument("-e", "--effective-freq", action='store_true',help='Ignore bandpass files and use effective frequency.')
parser.add_argument("--unsanitized-beam", action='store_true',help='Do not sanitize beam.')
parser.add_argument("--no-act-color-correction", action='store_true',help='Do not color correct ACT arrays in a scale dependent way.')
parser.add_argument("--ccor-exp",     type=float,  default=-1,help="ccor exp.")
args = parser.parse_args()

print("Command line arguments are %s." % args)
tutils.validate_args(args.solutions,args.beams)
tutils.validate_args(args.solutions,args.beams_planck)

# Prepare act-only and planck-only jobs
qids = args.arrays.split(',')
act_arrays = [] ; planck_arrays = []
for qid in qids:
    if tutils.is_planck(qid): 
        planck_arrays.append(qid)
    else: 
        act_arrays.append(qid)
do_act_only = (len(act_arrays)>0) and not(args.skip_only)
do_planck_only = (len(planck_arrays)>0) and not(args.skip_only)
act_arrays = ','.join(act_arrays)
planck_arrays = ','.join(planck_arrays)
print("Starting simulation for arrays %s of which %s are ACT and %s are Planck." % (args.arrays,act_arrays,planck_arrays))


# Generate each ACT and Planck sim and store kdiffs,kcoadd in memory

set_id = args.set_id
bandpasses = not(args.effective_freq)
gconfig = io.config_from_yaml("input/data.yml")
Пример #2
0
    lmin,lmax,hybrid,radial,friend,f1,fgroup,wrfit = aspecs(qid1)
    lmin,lmax,hybrid,radial,friend,f2,fgroup,wrfit = aspecs(qid2)

    ctheory = ilc.CTheory(ncents)
    stheory = ilc.CTheory(ccents)
    cltt = ctheory.get_theory_cls(f1,f2,a_cmb=1,a_gal=0.8)
    pl = io.Plotter(xyscale='linlog',scalefn=lambda x: x**2./2./np.pi,xlabel='l',ylabel='D')
    pl.add(ncents,cltt,color='k',lw=3)
    pl.add(ncents,n1d/fbeam1(ncents)/fbeam2(ncents))
    # pl._ax.set_xlim(2,8000)
    pl._ax.set_ylim(1,1e8)
    pl.done("%sn1d_%s_%s.png" % (opath,qid1,qid2),verbose=False)


    pl = io.Plotter(xyscale='linlog',scalefn=lambda x: x**2./2./np.pi,xlabel='l',ylabel='D')
    if tutils.is_planck(qid1) and tutils.is_planck(qid2): pl.add(ncents,cltt,color='k',lw=3) # unblind only if both planck
    #pl.add(ccents,s1d/fbeam1(ccents)/fbeam2(ccents))
    pl.add(ccents,s1d)
    pl.add(ncents,n1d/fbeam1(ncents)/fbeam2(ncents))
    pl._ax.set_ylim(1,1e8)
    pl.done("%ss1d_%s_%s.png" % (opath,qid1,qid2),verbose=False)


    #res = s1d/fbeam1(ccents)/fbeam2(ccents) - stheory.get_theory_cls(f1,f2,a_cmb=1,a_gal=0,a_cibp=0,a_cibc=0,a_radps=0,a_ksz=0,a_tsz=1)
    res = s1d - stheory.get_theory_cls(f1,f2,a_cmb=1,a_gal=0,a_cibp=0,a_cibc=0,a_radps=0,a_ksz=0,a_tsz=1)

    if tutils.is_planck(qid1) and tutils.is_planck(qid2): 
        flmin = 20
    else:
        flmin = 1000
        
Пример #3
0
def calculate_yy(bin_edges,arrays,region,version,cov_versions,beam_version,
                 effective_freq,overwrite,maxval,unsanitized_beam=False,do_weights=False,
                 pa1_shift = None,
                 pa2_shift = None,
                 pa3_150_shift = None,
                 pa3_090_shift = None,
                 no_act_color_correction=False, ccor_exp = -1,
                 sim_splits=None,unblind=False,all_analytic=False,beta_samples=None):


    """
    
    We calculate the yy power spectrum as follows.
    We restrict the Fourier modes in our analysis to those within bin_edges.
    This way we don't carry irrelevant pixels and thus speed up the ability to MC.
    We accept two covariance versions in cov_versions, which correspond to 
    [act_covariance_from_split_0,act_covariance_from_split_1,other_covs].
    Thus the ACT auto covariances are pre-calculated

    """
    arrays = arrays.split(',')
    narrays = len(arrays)
    if sim_splits is not None: assert not(unblind)
    def warn(): print("WARNING: no bandpass file found. Assuming array ",dm.c['id']," has no response to CMB, tSZ and CIB.")
    aspecs = tutils.ASpecs().get_specs
    bandpasses = not(effective_freq)
    savedir = tutils.get_save_path(version,region)
    assert len(cov_versions)==3
    covdirs = [tutils.get_save_path(cov_versions[i],region) for i in range(3)]
    for covdir in covdirs: assert os.path.exists(covdir)
    if not(overwrite):
        assert not(os.path.exists(savedir)), \
       "This version already exists on disk. Please use a different version identifier."
    try: os.makedirs(savedir)
    except:
        if overwrite: pass
        else: raise


    mask = enmap.read_map(covdir+"tilec_mask.fits")


    from scipy.ndimage.filters import gaussian_filter as smooth
    pm = enmap.read_map("/scratch/r/rbond/msyriac/data/planck/data/pr2/COM_Mask_Lensing_2048_R2.00_car_deep56_interp_order0.fits")
    wcs = pm.wcs
    mask = enmap.enmap(smooth(pm,sigma=10),wcs) * mask


    shape,wcs = mask.shape,mask.wcs
    Ny,Nx = shape
    modlmap = enmap.modlmap(shape,wcs)
    omodlmap = modlmap.copy()
    ells = np.arange(0,modlmap.max())
    minell = maps.minimum_ell(shape,wcs)
    sel = np.where(np.logical_and(modlmap>=bin_edges[0]-minell,modlmap<=bin_edges[-1]+minell))
    modlmap = modlmap[sel]

    bps = []
    lbeams = []
    kbeams = []
    shifts = []
    cfreqs = []
    lmins = []
    lmaxs = []
    names = []
    for i,qid in enumerate(arrays):
        dm = sints.models[sints.arrays(qid,'data_model')](region=mask,calibrated=True)
        if dm.name=='act_mr3':
            season,array1,array2 = sints.arrays(qid,'season'),sints.arrays(qid,'array'),sints.arrays(qid,'freq')
            array = '_'.join([array1,array2])
        elif dm.name=='planck_hybrid':
            season,patch,array = None,None,sints.arrays(qid,'freq')
        else:
            raise ValueError
        lmin,lmax,hybrid,radial,friend,cfreq,fgroup,wrfit = aspecs(qid)
        lmins.append(lmin)
        lmaxs.append(lmax)
        names.append(qid)
        cfreqs.append(cfreq)
        if bandpasses:
            try: 
                fname = dm.get_bandpass_file_name(array) 
                bps.append("data/"+fname)
                if (pa1_shift is not None) and 'PA1' in fname:
                    shifts.append(pa1_shift)
                elif (pa2_shift is not None) and 'PA2' in fname:
                    shifts.append(pa2_shift)
                elif (pa3_150_shift is not None) and ('PA3' in fname) and ('150' in fname):
                    shifts.append(pa3_150_shift)
                elif (pa3_090_shift is not None) and ('PA3' in fname) and ('090' in fname):
                    shifts.append(pa3_90_shift)
                else:
                    shifts.append(0)

            except:
                warn()
                bps.append(None)
        else:
            try: bps.append(cfreq)
            except:
                warn()
                bps.append(None)

        kbeam = tutils.get_kbeam(qid,modlmap,sanitize=not(unsanitized_beam),version=beam_version,planck_pixwin=True)
        if dm.name=='act_mr3':
            lbeam = tutils.get_kbeam(qid,ells,sanitize=not(unsanitized_beam),version=beam_version,planck_pixwin=False) # note no pixwin but doesnt matter since no ccorr for planck
        elif dm.name=='planck_hybrid':
            lbeam = None
        else:
            raise ValueError
        lbeams.append(lbeam)
        kbeams.append(kbeam.copy())
    # Make responses
    responses = {}

    def _get_response(comp,param_override=None):
        if bandpasses:
            if no_act_color_correction:
                r = tfg.get_mix_bandpassed(bps, comp, bandpass_shifts=shifts,
                                           param_dict_override=param_override)
            else:
                r = tfg.get_mix_bandpassed(bps, comp, bandpass_shifts=shifts,
                                           ccor_cen_nus=cfreqs, ccor_beams=lbeams, 
                                           ccor_exps = [ccor_exp] * narrays,
                                           param_dict_override=param_override)
        else:
            r = tfg.get_mix(bps, comp,param_dict_override=param_override)
        return r

    for comp in ['tSZ','CMB','CIB']:
        responses[comp] = _get_response(comp,None)


    
    from tilec.utils import is_planck
    ilcgens = []
    okcoadds = []
    for splitnum in range(2):
        covdir = covdirs[splitnum]
        kcoadds = []
        for i,qid in enumerate(arrays):
            lmin = lmins[i]
            lmax = lmaxs[i]

            if is_planck(qid):
                dm = sints.models[sints.arrays(qid,'data_model')](region=mask,calibrated=True)

                _,kcoadd,_ = kspace.process(dm,region,qid,mask,
                                            skip_splits=True,
                                            splits_fname=sim_splits[i] if sim_splits is not None else None,
                                            inpaint=False,fn_beam = None,
                                            plot_inpaint_path = None,
                                            split_set=splitnum)
            else:
                kcoadd_name = covdir + "kcoadd_%s.npy" % qid
                kcoadd = enmap.enmap(np.load(kcoadd_name),wcs)

            kmask = maps.mask_kspace(shape,wcs,lmin=lmin,lmax=lmax)
            dtype = kcoadd.dtype
            kcoadds.append((kcoadd.copy()*kmask)[sel])

        kcoadds = enmap.enmap(np.stack(kcoadds),wcs)
        okcoadds.append(kcoadds.copy())


        # Read Covmat
        ctheory = ilc.CTheory(modlmap)
        nells = kcoadds[0].size
        cov = np.zeros((narrays,narrays,nells))
        for aindex1 in range(narrays):
            for aindex2 in range(aindex1,narrays):
                qid1 = names[aindex1]
                qid2 = names[aindex2]
                if is_planck(names[aindex1]) or is_planck(names[aindex2]) or all_analytic:
                    lmin,lmax,hybrid,radial,friend,f1,fgroup,wrfit = aspecs(qid1)
                    lmin,lmax,hybrid,radial,friend,f2,fgroup,wrfit = aspecs(qid2)
                    # If both are Planck and same array, get white noise from last bin
                    icov = ctheory.get_theory_cls(f1,f2,a_cmb=1,a_gal=0.8)*kbeams[aindex1]*kbeams[aindex2]
                    if aindex1==aindex2:
                        pcov = enmap.enmap(np.load(covdirs[2]+"tilec_hybrid_covariance_%s_%s.npy" % (names[aindex1],names[aindex2])),wcs)
                        pbin_edges = np.append(np.arange(500,3000,200) ,[3000,4000,5000,5800])
                        pbinner = stats.bin2D(omodlmap,pbin_edges)
                        w = pbinner.bin(pcov)[1][-1]
                        icov = icov + w
                else:
                    icov = np.load(covdir+"tilec_hybrid_covariance_%s_%s.npy" % (names[aindex1],names[aindex2]))[sel]
                if aindex1==aindex2: 
                    icov[modlmap<lmins[aindex1]] = maxval
                    icov[modlmap>lmaxs[aindex1]] = maxval
                cov[aindex1,aindex2] = icov
                cov[aindex2,aindex1] = icov

        assert np.all(np.isfinite(cov))

        ilcgen = ilc.HILC(modlmap,np.stack(kbeams),cov=cov,responses=responses,invert=True)
        ilcgens.append(ilcgen)
      

    solutions = ['tSZ','tSZ-CMB','tSZ-CIB']
    ypowers = {}
    w2 = np.mean(mask**2.)
    binner = stats.bin2D(modlmap,bin_edges)
    np.random.seed(100)
    blinding = np.random.uniform(0.8,1.2) if not(unblind) else 1


    def _get_ypow(sname,dname,dresponse=None,dcmb=False):

        if dresponse is not None:
            assert dname is not None
            for splitnum in range(2):
                ilcgens[splitnum].add_response(dname,dresponse)

        ykmaps = []
        for splitnum in range(2):
            if dcmb:
                assert dname is not None
                ykmap = ilcgens[splitnum].multi_constrained_map(okcoadds[splitnum],sname,[dname,"CMB"])
            else:
                if dname is None:
                    ykmap = ilcgens[splitnum].standard_map(okcoadds[splitnum],sname)
                else:
                    ykmap = ilcgens[splitnum].constrained_map(okcoadds[splitnum],sname,dname)
            ykmaps.append(ykmap.copy())

        ypower = (ykmaps[0]*ykmaps[1].conj()).real / w2
        return binner.bin(ypower)[1] * blinding


    # The usual solutions
    for solution in solutions:

        sols = solution.split('-')
        if len(sols)==2:
            sname = sols[0]
            dname = sols[1]
        elif len(sols)==1:
            sname = sols[0]
            dname = None
        else:
            raise ValueError

        ypowers[solution] = _get_ypow(sname,dname,dresponse=None)


    # The CIB SED samples
    if beta_samples is not None:
        y_bsamples = []
        y_bsamples_cmb = []
        for beta in beta_samples:
            pdict = tfg.default_dict.copy()
            pdict['beta_CIB'] = beta
            response = _get_response("CIB",param_override=pdict)
            y_bsamples.append(  _get_ypow("tSZ","iCIB",dresponse=response,dcmb=False) )
            y_bsamples_cmb.append(  _get_ypow("tSZ","iCIB",dresponse=response,dcmb=True) )
    else:
        y_bsamples = None
        y_bsamples_cmb = None


    return binner.centers,ypowers,y_bsamples,y_bsamples_cmb
Пример #4
0
for i in range(narrays):
    for j in range(i,narrays):
        qid1 = qids[i]
        qid2 = qids[j]

        kbeam1 = 1
        kbeam2 = 1

        fname = root + 'tilec_hybrid_covariance_%s_%s.npy' % (qid1,qid2)
        p2d = enmap.enmap(np.load(fname))

        cents,p1d = binner.bin(p2d/kbeam1/kbeam2)

        pl = io.Plotter(xyscale='linlog',xlabel='l',ylabel='C')
        if tutils.is_planck(qid1) or tutils.is_planck(qid2):
            pl.add(cents[cents<5800],p1d[cents<5800])
        else:
            pl.add(cents,p1d)


        if tutils.is_planck(qid1) and tutils.is_planck(qid2):
            sel = np.where(np.logical_and(cents>500,cents<4000))
            pf1 = p1d[sel][-1] if i==j else 0

            lmin,lmax,hybrid,radial,friend,f1,fgroup,wrfit = aspecs(qid1)
            lmin,lmax,hybrid,radial,friend,f2,fgroup,wrfit = aspecs(qid2)

            lbeam1 = tutils.get_kbeam(qid1,cents,sanitize=True,planck_pixwin=True)
            lbeam2 = tutils.get_kbeam(qid2,cents,sanitize=True,planck_pixwin=True)
            
Пример #5
0
    if args.onlyd:
        if i not in dtiles: continue

    for qid in qids:
        # Check if this array is useful
        ashape, awcs = geoms[qid]
        Ny, Nx = ashape[-2:]
        center = enmap.center(eshape, ewcs)
        acpixy, acpixx = enmap.sky2pix(ashape, awcs, center)
        # Following can be made more restrictive by being aware of tile shape
        if acpixy <= 0 or acpixx <= 0 or acpixy >= Ny or acpixx >= Nx: continue
        # Ok so the center of the tile is inside this array, but are there any missing pixels?
        eivars = get_splits_ivar(qid, extracter)
        # Only check for missing pixels if array is not a Planck array
        if eivars is None: continue
        if not (is_planck(qid)) and ("s16" not in qid) and np.any(
                ta.crop_main(eivars) <= 0):
            print(
                "Skipping %s as it seems to have some zeros in the tile center..."
                % qid)
            continue
        aids.append(qid)
        apod = ta.apod * apodize_zero(np.sum(eivars, axis=0), ivar_apod_pix)
        esplits = get_splits(qid, extracter)

        if args.ivars:
            if i in dtiles:
                #io.hplot(esplits * apod,os.environ['WORK']+"/tiling/esplits_%s_%d" % (qid,i))
                #io.hplot(eivars * apod,os.environ['WORK']+"/tiling/eivars_%s_%d" % (qid,i))
                io.plot_img(
                    esplits * apod,