def quad_filter(fcinv, fdiag, lmax, lcl, **kwargs): # CMB filtering fl = prjlib.loadocl(fcinv['o'], **kwargs) ol = prjlib.loadocl(fdiag['o'], **kwargs) xl = prjlib.loadocl(fcinv['x'], **kwargs) alp = np.zeros((3, lmax + 1)) ocl = np.zeros((4, lmax + 1)) ifl = np.zeros((3, lmax + 1)) alp[1:3, 2:] = xl[1:3, 2:] / lcl[1:3, 2:] ocl[0, :] = ol[0, :] ocl[1:3, 2:] = fl[1:3, 2:] / alp[1:3, 2:]**2 ocl[3, :] = ol[3, :] ifl[0, :] = lcl[0, :] ifl[1:3, 2:] = fl[1:3, 2:] / alp[1:3, 2:] return ocl, ifl
np.concatenate((pquad.eL[None, :], np.mean(cl[1:, :, :], axis=0), np.std(cl[1:, :, :], axis=0))).T) p, f, r = prjlib.init() ps, fs, _ = prjlib.init(stype='lcmb', dodust='False') #//// Reconstruction ////# ow = False #ow = True snmax = p.snmax if p.stype not in ['lcmb', 'dust']: snmax = 100 if p.stype in ['absrot', 'relrot', 'dust']: rdn0 = False ocl = prjlib.loadocl(fs.scl) quad_func.quad.diagcinv(ps.quad, ocl) quad_func.quad.diagcinv(p.quad, ocl) quad_func.quad.qrec(ps.quad, p.snmin, snmax, f.alm, r.lcl, qout=p.quad, overwrite=ow) if p.stype == 'dust': rdn0 = True quad_func.quad.rdn0(ps.quad, p.snmin, p.snmax, f.alm,
import prjlib import quad_func import binning as bins p, f, r = prjlib.init(loadw=False) p0, f0 = prjlib.filename_init(PSA='s14&15_deep56', doreal='True', dearot='True') p1, f1 = prjlib.filename_init(PSA='s14&15_boss', doreal='True') px, fx = prjlib.filename_init(PSA='s14&15_cross', doreal='True') __, __, w1, __ = prjlib.window(f0) __, __, w2, __ = prjlib.window(f1) r.w4 = np.sqrt(w1 * w2) #//// bias terms ////# oc0 = prjlib.loadocl(f0.scl) oc1 = prjlib.loadocl(f1.scl) quad_func.quad.diagcinv(p0.quad, oc0) quad_func.quad.diagcinv(p1.quad, oc1) #quad_func.n0x(px.quad,p0.quad,p1.quad,f0.alm,f1.alm,r.w4,r.lcl) #quad_func.rdn0x(px.quad,p0.quad,p1.quad,0,1,f0.alm,f1.alm,r.w4,r.lcl) #//// Power spectrum ////# oLmax = p.quad.oLmax bn = p.quad.bn binspc = p.quad.binspc for q in p.quad.qlist: cl = np.zeros((p.snmax - p.snmin + 1, 1, oLmax + 1))
def interface(freqs,kwargs_ov={},kwargs_cmb={},run=['map2alm','combfreq','wiener_iso','wiener_diag']): telescope = kwargs_cmb['t'] snmin = kwargs_cmb['snmin'] snmax = kwargs_cmb['snmax'] ntype = kwargs_cmb['ntype'] if 'hitmap' in run: output_hitmap(**kwargs_ov) if 'simmap' in run: if telescope in ['la','sa']: for freq in freqs: # signal sim sobj = sim_map(telescope=telescope,freq=freq,snmin=snmin,snmax=snmax,ntype='',**kwargs_ov) sim_map.SOsim(sobj) # noise sim sobj = sim_map(telescope=telescope,freq=freq,snmin=snmin,snmax=snmax,ntype=ntype,**kwargs_ov) sim_map.SOsim(sobj) if 'calcalm' in run: # map -> alm for each freq (and com) and telescope if '_iso' in ntype: # compute alms for isotropic noise # need pre-computed frequency-coadded spectrum if kwargs_cmb['fltr'] != 'none': sys.exit('isotropic noise calculation is only valid for none-filtered case') if telescope in ['la','co']: # for isotropic noise spectrum and diagonal wiener filtering pc = prjlib.analysis_init(t=telescope,freq='com',snmin=snmin,snmax=snmax,ntype=ntype.replace('_iso','')) ncl = prjlib.loadocl(pc.fcmb.scl['n'],lTmin=pc.lTmin,lTmax=pc.lTmax) # setup filenames for input and output inp = prjlib.analysis_init(t='id',ntype='cv',snmin=snmin,snmax=snmax) # to use fullsky signal out = prjlib.analysis_init(t=telescope,freq='com',fltr='none',snmin=snmin,snmax=snmax,ntype=ntype) # alm and aps iso_noise(pc.rlz,pc.roll,pc.lmax,inp.fcmb.alms['o'],out.fcmb.alms['o'],ncl[0:3,:],**kwargs_ov) aps(pc.rlz,pc.lmax,out.fcmb,1.,stype=['o'],**kwargs_ov) else: if kwargs_cmb['fltr'] == 'none': if telescope == 'co': sys.exit('does not support none filter case for LA+SA') if telescope == 'id': # map -> alm for fullsky case stype = ['o'] ntype = 'cv' freqs = ['145'] else: stype = ['s','n','o'] # load survey window w, wn = prjlib.window(telescope,ascale=kwargs_cmb['ascale']) # map -> alm for each freq for freq in freqs: p = prjlib.analysis_init(t=telescope,freq=freq,snmin=snmin,snmax=snmax,ntype=ntype) # define parameters, filenames map2alm(p.telescope,p.rlz,freq,p.nside,p.lmax,p.fcmb,w,roll=p.roll,**kwargs_ov) # map -> alm aps(p.rlz,p.lmax,p.fcmb,wn[2],stype=stype,**kwargs_ov) # combine alm over freqs if telescope in ['la','sa']: p = prjlib.analysis_init(t=telescope,freq='com',snmin=snmin,snmax=snmax,ntype=ntype) fmap = prjlib.filename_freqs(freqs,t=telescope,ntype=ntype) alm_comb_freq(p.rlz,fmap,p.fcmb,roll=p.roll,**kwargs_ov) aps(p.rlz,p.lmax,p.fcmb,wn[2],**kwargs_ov) elif kwargs_cmb['fltr'] == 'cinv': # full wiener filtering if telescope == 'sa': sys.exit('does not support cinv filter case for SA') pw = prjlib.analysis_init(t=telescope,freq='com',fltr='cinv',snmin=snmin,snmax=snmax,ntype=ntype) pI = prjlib.analysis_init(t='id',ntype='cv',snmin=snmin,snmax=snmax) # for cross wn = prjlib.wfac(telescope,binary=True) if telescope == 'la': mtypes = ['T','E','B'] # filenames fmap = prjlib.filename_freqs(freqs,t=telescope,ntype=ntype) # Temperature cinv_params = {\ 'chn' : 7, \ 'eps' : [1e-4,.1,.1,.1,.1,.1,0.], \ 'lmaxs' : [4096,2048,2048,1024,512,256,20], \ 'nsides' : [2048,2048,1024,512,256,128,64], \ 'itns' : [100,5,5,5,5,5,0], \ 'ro' : 1, \ 'filter' : 'W' \ } cinv(1,pw.rlz,telescope,4096,ntype,fmap,pw.fcmb.alms['o'],pw.lcl,freqs=freqs,**cinv_params,**kwargs_ov) # Polarization cinv_params = {\ 'chn' : 6, \ 'eps' : [1e-5,.1,.1,.1,.1,0.], \ 'lmaxs' : [4096,2048,1024,512,256,20], \ 'nsides' : [2048,1024,512,256,128,64], \ 'itns' : [100,7,5,3,3,0], \ 'ro' : 1, \ 'filter' : 'W' \ } cinv(2,pw.rlz,telescope,4096,ntype,fmap,pw.fcmb.alms['o'],pw.lcl,freqs=freqs,**cinv_params,**kwargs_ov) if telescope == 'co': mtypes = ['E','B'] cinv_params = {\ 'chn' : 6, \ 'eps' : [1e-5,.1,.1,.1,.1,0.], \ 'lmaxs' : [2048,1000,400,200,100,20], \ 'nsides0' : [1024,512,256,128,128,64], \ 'nsides1' : [512,256,256,128,64,64], \ 'itns' : [200,9,3,3,7,0], \ 'ro' : 1, \ 'reducmn' : 2, \ 'filter' : 'W' \ } cinv_params = {\ 'chn' : 1, \ 'eps' : [1e-5], \ 'lmaxs' : [2048], \ 'nsides0' : [1024], \ 'nsides1' : [512], \ 'itns' : [1000], \ 'ro' : 1, \ 'reducmn' : 0, \ 'filter' : 'W' \ } fmapla = prjlib.filename_freqs(freqs,t='la',ntype=ntype) fmapsa = prjlib.filename_freqs(freqs,t='sa',ntype=ntype) cinv(2,pw.rlz,telescope,2048,ntype,fmapla,pw.fcmb.alms['o'],pw.lcl,freqs=freqs,fmapsa=fmapsa,**cinv_params,**kwargs_ov) # aps aps(pw.rlz,pw.lmax,pw.fcmb,wn[0],stype=['o'],mtype=mtypes,**kwargs_ov) apsx(pw.rlz,pw.lmax,pw.fcmb,pI.fcmb,wn[0],mtype=mtypes,**kwargs_ov)
def interface(run=[], kwargs_ov={}, kwargs_cmb={}, kwargs_qrec={}, ep=1e-30): if kwargs_cmb['t'] != 'la': sys.exit('only la is supported') # Define parameters, filenames for input CMB p = prjlib.analysis_init(**kwargs_cmb) # Load pre-computed w-factor which is used for correction normalization of spectrum wn = prjlib.wfac(p.telescope) # Compute filtering if p.fltr == 'none': # for none-filtered alm # Load "observed" aps containing signal, noise, and some residual. # This aps will be used for normalization calculation ocl = prjlib.loadocl(p.fcmb.scl['o'], lTmin=p.lTmin, lTmax=p.lTmax) # CMB alm will be multiplied by 1/ifl before reconstruction process ifl = ocl #p.lcl[0:3,:] elif p.fltr == 'cinv': # for C^-1 wiener-filtered alm pc = prjlib.analysis_init(t=p.telescope, freq='com', fltr='none', ntype=p.ntype) # Compute aps appropriate for C^-1 filtering case. ocl, ifl = quad_filter(p.fcmb.scl, pc.fcmb.scl, p.lmax, p.lcl, lTmin=p.lTmin, lTmax=p.lTmax) ocl[ocl <= 0.] = 1e30 ifl[ifl <= 0.] = 1e30 wn[:] = wn[0] else: sys.exit('unknown filtering') if 'iso' in p.ntype: #fullsky case wn[:] = 1. d = prjlib.data_directory() ids = prjlib.rlz_index(doreal=p.doreal) qobj = quad_func.reconstruction(d['root'], ids, rlz=p.rlz, stag=p.stag, run=run, wn=wn, lcl=p.lcl, ocl=ocl, ifl=ifl, falm=p.fcmb.alms['o'], **kwargs_ov, **kwargs_qrec) # Aps of reconstructed phi if 'aps' in run: aps(p.fltr, qobj, p.rlz, p.fpalm, wn) # Cinv kappa if 'kcinv' in run: compute_kcninv(qobj.f, p.rlz, p.fltr, p.kk[:qobj.olmax + 1], p.fpalm, Snmin=p.snmin, Snmax=p.snmax, qlist=qobj.qlist, **kwargs_ov)