id_high_planck = 0

for spec in ["TT", "EE", "TE"]:
    for id_f, fpair in enumerate(freq_pairs):
        
        f0, f1 = fpair
        
        if (spec == "TT") & (f0 == "100") & (f1 == "143"): continue
        if (spec == "TT") & (f0 == "100") & (f1 == "217"): continue
        
        l_planck, _, _ = np.loadtxt("data/planck_data/spectrum_%s_%sx%s.dat"%(spec, f0, f1), unpack=True)
        id_high_planck += len(l_planck)
        std_planck = np.sqrt(variance_planck)[id_low_planck:id_high_planck]

        lth, cl_th_and_fg = np.loadtxt("%s/best_fit_%sx%s_%s.dat" % (bestfit_dir, f0, f1, spec), unpack=True)
        lb, cb = planck_utils.binning(lth, cl_th_and_fg, lmax, binning_file=binning_file)
        ps_name = "%s_%sx%s" % (spec, f0, f1)
        lmin_c, lmax_c = lrange[ps_name]
        id=np.where((lb >= lmin_c) & (lb <= lmax_c))
        lb, cb = lb[id], cb[id]
        fac = lb * (lb + 1) / (2 * np.pi)

        bin_start, bin_stop = bin_range[ps_name]
        std_sim = np.sqrt(cov.diagonal())[bin_start:bin_stop]
        mean_sim = mean_vec[bin_start:bin_stop]
        
        plt.figure(figsize=(12, 8))
        plt.errorbar(lb, cb * fac, color="grey", label = "input theory")
        plt.errorbar(lb, mean_sim * fac, std_sim * fac, color="red", fmt = "." , label = "mean %s %s GHzx %s GHz"%(spec, f0, f1), alpha=0.4)
        plt.xlabel(r"$\ell$", fontsize=20)
        plt.ylabel(r"$D_\ell$", fontsize=20)
Exemple #2
0
        for spec in spectra:
            
            if (spec=='TT' or spec=='EE' or spec=='BB') & (freq1==freq2):
                
                if spec=='TT':
                    sigma_th=d['sigma_th_%s'%freq1]
                if spec=='EE' or spec=='BB':
                    sigma_th=d['sigma_pol_th_%s'%freq1]
                sigma_th = np.deg2rad(sigma_th)/60
                
                nlth[spec]=lth*0+2*sigma_th**2
                
                bl_hm1=bl[freq1,'hm1',spec]
                bl_hm2=bl[freq1,'hm2',spec]

                lb,nb_hm1= planck_utils.binning(l,ps_dict[freq1,freq2,spec,'hm1','hm1']*bl_hm1**2-ps_dict[freq1,freq2,spec,'hm1','hm2']*bl_hm1*bl_hm2,lmax,size=size)
                lb,nb_hm2= planck_utils.binning(l,ps_dict[freq1,freq2,spec,'hm2','hm2']*bl_hm2**2-ps_dict[freq1,freq2,spec,'hm1','hm2']*bl_hm1*bl_hm2,lmax,size=size)

                f=lb**2/(2*np.pi)

                nl_interpol_1 = scipy.interpolate.interp1d(lb,nb_hm1, fill_value='extrapolate')
                nl_interpol_2 = scipy.interpolate.interp1d(lb,nb_hm2, fill_value='extrapolate')
                nl_interpol_mean= scipy.interpolate.interp1d(lb,(nb_hm1+nb_hm2)/2, fill_value='extrapolate')
                
                nl_hm1[spec]=np.array([nl_interpol_1(i) for i in lth])
                nl_hm2[spec]=np.array([nl_interpol_2(i) for i in lth])
                nl_mean[spec]=np.array([nl_interpol_mean(i) for i in lth])

                if spec=='TT':
                    plt.ylim(-0.002,0.002)
                plt.plot(lth,nlth[spec],label='white noise %sx%s %s'%(freq1,freq2,spec))
    for spec in ['TT', 'EE', 'TE', 'r']:

        if spec != 'r':
            if (fname != '100x143') & (fname != '100x217'):
                cl_th_and_fg[spec,
                             fname] = (clth[spec] + fg[spec, fname][:lthmax]
                                       ) * 2 * np.pi / (lth * (lth + 1))
            else:
                cl_th_and_fg[spec,
                             fname] = clth[spec] * 2 * np.pi / (lth *
                                                                (lth + 1))

            lb, cb_th_and_fg[spec, fname] = planck_utils.binning(
                lth,
                cl_th_and_fg[spec, fname],
                lthmax,
                binning_file=binning_file)
            id = np.where((lb > lmin) & (lb < lmax))

            cb_th_and_fg[spec, fname] = cb_th_and_fg[spec, fname][id]
        else:
            cl_th_and_fg[spec, fname] = cl_th_and_fg['TE', fname] / np.sqrt(
                cl_th_and_fg['TT', fname] * cl_th_and_fg['EE', fname])
            cb_th_and_fg[spec, fname] = cb_th_and_fg['TE', fname] / np.sqrt(
                cb_th_and_fg['TT', fname] * cb_th_and_fg['EE', fname])

        l, mean[spec, fname], std[spec, fname] = np.loadtxt(
            '%s/spectra_%s_%s_hm1xhm2.dat' % (mc_dir, spec, fname),
            unpack=True)
Exemple #4
0
d = so_dict.so_dict()
d.read_from_file(sys.argv[1])

binning_file = d["binning_file"]
freqs = d["freqs"]
lmax = d["lmax"]
clfile = d["theoryfile"]

lth, Clth = pspy_utils.ps_lensed_theory_to_dict(clfile,
                                                output_type="Cl",
                                                lmax=lmax,
                                                start_at_zero=False)

Cb_th = {}
lb, Cb_th["EE"] = planck_utils.binning(lth, Clth["EE"], lmax, binning_file)
lb, Cb_th["BB"] = planck_utils.binning(lth, Clth["BB"], lmax, binning_file)

if d["use_ffp10"]:
    mc_dir = "montecarlo_ffp10_larger_bin"
else:
    mc_dir = "montecarlo"

chain_dir = "chains"
pspy_utils.create_directory(chain_dir)

lmin, lmax = 100, 1500
id = np.where((lb >= lmin) & (lb <= lmax))
lb, Cb_th["EE"], Cb_th["BB"] = lb[id], Cb_th["EE"][id], Cb_th["BB"][id]

nbins = len(lb)
Exemple #5
0
                if spec == "EE" or spec == "BB":
                    sigma_th = d["sigma_pol_th_%s" % freq1]

                sigma_th = np.deg2rad(sigma_th) / 60

                nlth[spec] = lth * 0 + 2 * sigma_th**2

                bl_hm1 = bl[freq1, "hm1", spec]
                bl_hm2 = bl[freq1, "hm2", spec]

                nth_hm1 = ps_dict["hm1", "hm1", spec] * bl_hm1**2 - ps_dict[
                    "hm1", "hm2", spec] * bl_hm1 * bl_hm2
                nth_hm2 = ps_dict["hm2", "hm2", spec] * bl_hm2**2 - ps_dict[
                    "hm1", "hm2", spec] * bl_hm1 * bl_hm2

                lb, nb_hm1 = planck_utils.binning(l, nth_hm1, lmax, size=size)
                lb, nb_hm2 = planck_utils.binning(l, nth_hm2, lmax, size=size)

                nl_interpol_1 = scipy.interpolate.interp1d(
                    lb, nb_hm1, fill_value="extrapolate")
                nl_interpol_2 = scipy.interpolate.interp1d(
                    lb, nb_hm2, fill_value="extrapolate")

                # Factor 4 since the noise on the 'mean' if 1/2 of the mean noise
                nl_interpol_mean = scipy.interpolate.interp1d(
                    lb, (nb_hm1 + nb_hm2) / 4, fill_value="extrapolate")

                nl_hm1[spec] = np.array([nl_interpol_1(i) for i in lth])
                nl_hm2[spec] = np.array([nl_interpol_2(i) for i in lth])
                nl_mean[spec] = np.array([nl_interpol_mean(i) for i in lth])
Exemple #6
0
for fpair, color in zip(freq_pairs, color_array):

    f0, f1 = fpair
    fname = '%sx%s' % (f0, f1)
    cl = {}
    error = {}
    mc_error = {}
    model = {}
    lmin, lmax = d['lrange_%sx%s' % (f0, f1)]

    for spec in ['TT', 'EE', 'TE']:
        model[spec, fname] = psth[spec]
        lb, model[spec,
                  fname] = planck_utils.binning(lth,
                                                model[spec, fname],
                                                lthmax,
                                                binning_file=binning_file)
        id = np.where((lb > lmin) & (lb < lmax))
        model[spec, fname] = model[spec, fname][id]

    model['r', fname] = model['TE', fname] / np.sqrt(
        model['TT', fname] * model['EE', fname])

    l, r, std_r = np.loadtxt('%s/spectra_r_%s_hm1xhm2.dat' % (mc_dir, fname),
                             unpack=True)

    cov_TTTT = np.loadtxt('%s/diagonal_select_cov_mat_TT_%s_%s_TT_%s_%s.dat' %
                          (mc_dir, fname, 'hm1xhm2', fname, 'hm1xhm2'))
    cov_EEEE = np.loadtxt('%s/diagonal_select_cov_mat_EE_%s_%s_EE_%s_%s.dat' %
                          (mc_dir, fname, 'hm1xhm2', fname, 'hm1xhm2'))
    cov_TETE = np.loadtxt('%s/diagonal_select_cov_mat_TE_%s_%s_TE_%s_%s.dat' %