Пример #1
0
    def get_sacc_windows(self, wsp):
        """
        Get window functions for each bandpower so they can be stored into the final SACC files.
        """
        #Compute window functions
        nbands = wsp.wsp.bin.n_bands
        l_arr = np.arange(self.lmax + 1)
        if not os.path.isfile(self.get_output_fname('windows_l', ext='npz')):
            print("Computing window functions")
            windows = np.zeros([nbands, self.lmax + 1])
            t_hat = np.zeros(self.lmax + 1)
            for il, l in enumerate(l_arr):
                t_hat[il] = 1.
                windows[:, il] = wsp.decouple_cell(
                    wsp.couple_cell(l_arr, [t_hat]))
                t_hat[il] = 0.
            np.savez(self.get_output_fname('windows_l'), windows=windows)
        else:
            print("Reading window functions")
            windows = np.load(self.get_output_fname('windows_l',
                                                    ext='npz'))['windows']

        windows_sacc = []
        #i_x=0
        for i in range(self.nbins):
            for j in range(i, self.nbins):
                for b in range(nbands):
                    windows_sacc.append(sacc.Window(l_arr, windows[b]))

        return windows_sacc
Пример #2
0
    def get_sacc_binning(self, with_windows=False):
        typ, ell, t1, q1, t2, q2 = [], [], [], [], [], []
        l_eff = self.bins.get_effective_ells()

        windows = None
        if with_windows:
            windows_wsp = {}
            for b1 in range(self.n_bpss):
                for b2 in range(b1, self.n_bpss):
                    name = self.get_workspace_label(b1, b2)
                    windows_wsp[name] = {}
                    wsp = self.workspaces[name]
                    bpw_win = wsp.get_bandpower_windows()
                    windows_wsp[name]['EE'] = bpw_win[0, :, 0, :]
                    windows_wsp[name]['EB'] = bpw_win[1, :, 1, :]
                    windows_wsp[name]['BE'] = bpw_win[2, :, 2, :]
                    windows_wsp[name]['BB'] = bpw_win[3, :, 3, :]
            windows = []

        for b1, b2, s1, s2, l1, l2 in self.get_cell_iterator():
            if (b1 == b2) and (s1 == s2):
                types = ['EE', 'EB', 'BB']  # Do not double-count EB
            else:
                types = ['EE', 'EB', 'BE', 'BB']
            name_wsp = self.get_workspace_label(b1, b2)

            for ty in types:
                for il, l in enumerate(l_eff):
                    ell.append(l)
                    typ.append(ty)
                    t1.append(b1 * self.nsplits + s1)
                    t2.append(b2 * self.nsplits + s2)
                    q1.append('C')
                    q2.append('C')
                    if with_windows:
                        windows.append(
                            sacc.Window(self.larr_all,
                                        windows_wsp[name_wsp][ty][il]))

        return sacc.Binning(typ, ell, t1, q1, t2, q2, windows=windows)
Пример #3
0
            axis=0) / area
ec = {
    pn: np.sum(np.array([
        np.array([t.extra_cols[pn]
                  for t in sc[f].tracers]) * sc[f].meta['Area_rad']
        for f in fields
    ]),
               axis=0) / area
    for pn in pz_codes
}
# Windows
wins = [
    sacc.Window(
        sc['GAMA09H'].binning.windows[i_w].ls,
        np.sum(np.array([
            sc[f].binning.windows[i_w].w * sc[f].meta['Area_rad']
            for f in fields
        ]),
               axis=0) / area)
    for i_w, ww in enumerate(sc['GAMA09H'].binning.windows)
]

# Bins
s_bn = sc['GAMA09H'].binning
s_bn.windows = wins

# Tracers
s_tr = []
for i_t in range(4):
    T = sacc.Tracer('bin_%d' % i_t,
                    'point',
Пример #4
0
        if pb == "T":
            tb_name = "%s_%s_s0" % (eb, fb)
        else:
            tb_name = "%s_%s_s2" % (eb, fb)

        cl_type = "cl_" + map_types[pa] + map_types[pb]
        lbin = data["%s_%s" % (ea, fa), "%s_%s" % (eb, fb)]["lbin"]
        cb = data["%s_%s" % (ea, fa), "%s_%s" % (eb, fb)][pa + pb]

        spec_sacc.add_ell_cl(cl_type, ta_name, tb_name, lbin, cb)

        if isim == 0:
            bbl = get_bbl(ea, fa, pa, eb, fb, pb)
            ls_w = np.arange(2, bbl.shape[-1] + 2)
            wins = sacc.Window(ls_w, bbl.T)
            cov_sacc.add_ell_cl(cl_type,
                                ta_name,
                                tb_name,
                                lbin,
                                cb,
                                window=wins,
                                window_id=range(len(lbin)))

    if isim == 0:
        cov_sacc.add_covariance(cov_full)
        cov_sacc.save_fits("%s/data_sacc_w_covar_and_Bbl.fits" % sacc_dir,
                           overwrite=True)

    spec_sacc.save_fits("%s/data_sacc_%s.fits" % (sacc_dir, sim_suffix),
                        overwrite=True)
Пример #5
0
q1_arr = []
q2_arr = []
w_arr = []
for ic, c in enumerate(corr_ordering):
    s1, s2 = c
    tn1 = s1[:-2]
    q1 = s1[-1]
    t1 = np.where(tracer_names == tn1)[0][0]
    tn2 = s2[:-2]
    q2 = s2[-1]
    t2 = np.where(tracer_names == tn2)[0][0]
    typ = q1 + q2
    for b in range(nells):
        w = windows[b, ic]
        lmean = np.sum(ls * w) / np.sum(w)
        win = sacc.Window(ls, w)
        ls_arr.append(lmean)
        w_arr.append(win)
    q1_arr += nells * [q1]
    q2_arr += nells * [q2]
    t1_arr += nells * [t1]
    t2_arr += nells * [t2]
    typ_arr += nells * [typ]
bins = sacc.Binning(typ_arr,
                    ls_arr,
                    t1_arr,
                    q1_arr,
                    t2_arr,
                    q2_arr,
                    windows=w_arr)
Пример #6
0
# at 100 ell bins for density correlations
lvals = np.arange(100, 1000, 100)
Ntracer = len(tracers)
type, ell, t1, q1, t2, q2, val, err, wins = [], [], [], [], [], [], [], [], []
for t1i in range(Ntracer):
    for t2i in range(t1i, Ntracer):
        for l in lvals:
            ## we have Fourier space measurement
            type.append('FF')
            ## at this nominal ell
            ell.append(l)
            ## but in detail  the measurement
            ## is a Gaussian window around central ell +/- 50
            wins.append(
                sacc.Window(
                    np.arange(l - 50, l + 50),
                    np.exp(-(1.0 * np.arange(-50, 50))**2 / (2 * 20.**2))))
            ## We refer to tracers by their index
            t1.append(t1i)
            t2.append(t2i)
            ## Here we have density cross-correlations so "P" as point
            ## except for CMB where
            q1.append('S')
            q2.append('S')
            ## values and errors
            val.append(np.random.uniform(0, 10))
            err.append(np.random.uniform(1, 2))

binning = sacc.Binning(type, ell, t1, q1, t2, q2, windows=wins)
mean = sacc.MeanVec(val)
Пример #7
0
cl = np.exp(lcl_i(np.log(l_all)))
nl = nl_yy_f(l_all)

# Beam
beam_fwhm_amin = 1.4
beam = np.exp(-0.5 * l_all * (l_all + 1) *
              (beam_fwhm_amin * np.pi / 180 / 60)**2)
cl *= beam**2

# Bandpower window
d_ell = 100
n_bands = 10000 // d_ell
windows = np.zeros([n_bands, lmax - 1])
for i in range(n_bands):
    windows[i, i * d_ell + 2:(i + 1) * d_ell + 2] = 1. / d_ell
win = sacc.Window(l_all, windows.T)

# Convolve and Gaussian covariance
bpws = np.dot(windows, cl)
bpws_n = np.dot(windows, nl)
leff = np.dot(windows, l_all)
fsky = 0.1
cov = np.diag((bpws + bpws_n)**2 / ((leff + 0.5) * fsky * d_ell))

# Add statistical noise
#bpws = np.random.multivariate_normal(bpws, cov)

s = sacc.Sacc()
s.add_tracer('Map', 'SO_y', quantity='cmb_tSZ', spin=0, ell=l_all, beam=beam)
s.add_ell_cl('cl_00',
             'SO_y',
Пример #8
0
from packaging import version

# Dummy arrays
vecsize = 100
x = np.linspace(0, 100, vecsize)
y = 1. / (x + 50)**2

# Create file
s = sacc.Sacc()

# Add tracers
s.add_tracer('NZ', 'nz', x, y)
s.add_tracer('NZ', 'nz_b', x, y)

wth = sacc.TopHatWindow(0., 1.)
ww = sacc.Window(x, y)
s.add_ell_cl('galaxy_density_cl', 'nz', 'nz', x, y, window=[wth] * vecsize)
s.add_theta_xi('galaxy_density_xi', 'nz', 'nz', x, y, window=[ww] * vecsize)
nvec = 2

if version.parse(sacc.__version__) > version.parse('0.2.0'):
    wlth = sacc.LogTopHatWindow(-2., 0.)
    s.add_ell_cl('galaxy_density_cl',
                 'nz_b',
                 'nz_b',
                 x,
                 y,
                 window=[wlth] * vecsize)
    nvec += 1

if version.parse(sacc.__version__) > version.parse('0.4.0'):
Пример #9
0
t2_arr = []
q1_arr = []
q2_arr = []
w_arr = []
for ic, c in enumerate(corr_ordering):
    s1, s2 = c
    tn1 = s1[:-2]
    q1 = s1[-1]
    t1 = np.where(tracer_names == tn1)[0][0]
    tn2 = s2[:-2]
    q2 = s2[-1]
    t2 = np.where(tracer_names == tn2)[0][0]
    typ = q1 + q2
    for ib, w in enumerate(windows):
        lmean = leff[ib]
        win = sacc.Window(larr_all, w)
        ls_arr.append(lmean)
        w_arr.append(win)
    q1_arr += nbands * [q1]
    q2_arr += nbands * [q2]
    t1_arr += nbands * [t1]
    t2_arr += nbands * [t2]
    typ_arr += nbands * [typ]
bins = sacc.Binning(typ_arr,
                    ls_arr,
                    t1_arr,
                    q1_arr,
                    t2_arr,
                    q2_arr,
                    windows=w_arr)
Пример #10
0
  print("Reading window functions")
  windows=np.load(o.fname_mcm+".windows.npz")['windows']
    

#Compute all cross-correlations
print("Computing all cross-power specra")
cls_all=[]
windows_sacc=[]
ordering=np.zeros([nbins,nbins],dtype=int)
i_x=0
for i in range(nbins) :
  for j in range(i,nbins) :
    cl_coupled=nmt.compute_coupled_cell_flat(tracers[i].field,tracers[j].field,bpws)
    cls_all.append(wsp.decouple_cell(cl_coupled)[0])
    for b in range(nbands) :
      windows_sacc.append(sacc.Window(l_arr,windows[b]))
    ordering[i,j]=i_x
    if j!=i :
      ordering[j,i]=i_x
    i_x+=1
cls_all=np.array(cls_all)
n_cross=len(cls_all)
n_ell=len(ell_eff)

#Get guess power spectra
if o.guess_cell=='data' :
  #Interpolate measured power spectra
  lth=np.arange(2,lmax+1)+0.
  clth=np.zeros([n_cross,len(lth)])
  for i in range(n_cross) :
    clf=interp1d(ell_eff,cls_all[i],bounds_error=False,fill_value=0,kind='linear')
Пример #11
0
    def get_binnings(self, with_windows=True):
        # Get windows if needed
        win_coadd = None
        win_nulls = None
        if with_windows:
            win_coadd = []
            win_nulls = []
            ls_win = self.s_splits.binning.windows[0].ls.copy()
            nls = len(ls_win)
            windows = np.zeros(
                [self.nbands, 2, self.nbands, 2, self.n_bpws, nls])
            for t1, t2, typ, ells, ndx in self.sorting:
                b1, s1 = self.tracer_number_to_band_split(t1)
                b2, s2 = self.tracer_number_to_band_split(t2)
                typ = typ.decode()
                p1 = self.index_pol[typ[0]]
                p2 = self.index_pol[typ[1]]
                if (s1 == 0) and (s2 == 0):
                    for b, i in enumerate(ndx):
                        w = self.s_splits.binning.windows[i].w
                        windows[b1, p1, b2, p2, b, :] = w
                        if not ((b1 == b2) and (p1 == p2)):
                            windows[b2, p2, b1, p1, b, :] = w

        # Binnings for coadds
        typ, ell, t1, q1, t2, q2 = [], [], [], [], [], []
        for i1 in range(2 * self.nbands):
            b1 = i1 // 2
            p1 = i1 % 2
            for i2 in range(i1, 2 * self.nbands):
                b2 = i2 // 2
                p2 = i2 % 2
                ty = self.pol_names[p1] + self.pol_names[p2]
                for il, ll in enumerate(self.ells):
                    ell.append(ll)
                    typ.append(ty)
                    t1.append(b1)
                    t2.append(b2)
                    q1.append('C')
                    q2.append('C')
                    if with_windows:
                        win_coadd.append(
                            sacc.Window(ls_win, windows[b1, p1, b2, p2, il]))
        self.bins_coadd = sacc.Binning(typ,
                                       ell,
                                       t1,
                                       q1,
                                       t2,
                                       q2,
                                       windows=win_coadd)

        # Binnings for nulls
        typ, ell, t1, q1, t2, q2 = [], [], [], [], [], []
        for i_null, (i, j, k, l) in enumerate(self.pairings):
            for b1 in range(self.nbands):
                tr1 = self.ind_nulls['band%d_null%dm%d' %
                                     (b1 + 1, i + 1, j + 1)]
                for p1 in range(2):
                    for b2 in range(self.nbands):
                        tr2 = self.ind_nulls['band%d_null%dm%d' %
                                             (b2 + 1, k + 1, l + 1)]
                        for p2 in range(2):
                            ty = self.pol_names[p1] + self.pol_names[p2]
                            for il, ll in enumerate(self.ells):
                                ell.append(ll)
                                typ.append(ty)
                                t1.append(tr1)
                                t2.append(tr2)
                                q1.append('C')
                                q2.append('C')
                                if with_windows:
                                    win_nulls.append(
                                        sacc.Window(
                                            ls_win, windows[b1, p1, b2, p2,
                                                            il]))
        self.bins_nulls = sacc.Binning(typ,
                                       ell,
                                       t1,
                                       q1,
                                       t2,
                                       q2,
                                       windows=win_nulls)