Esempio n. 1
0
    def _init_foreground_model(self):

        from fgspectra import cross as fgc
        from fgspectra import frequency as fgf
        from fgspectra import power as fgp

        template_path = os.path.join(
            os.path.dirname(os.path.abspath(fgp.__file__)), "data")
        cibc_file = os.path.join(template_path, "cl_cib_Choi2020.dat")

        # set pivot freq and multipole
        self.fg_nu_0 = self.foregrounds["normalisation"]["nu_0"]
        self.fg_ell_0 = self.foregrounds["normalisation"]["ell_0"]

        # We don't seem to be using this
        # cirrus = fgc.FactorizedCrossSpectrum(fgf.PowerLaw(), fgp.PowerLaw())
        self.ksz = fgc.FactorizedCrossSpectrum(fgf.ConstantSED(),
                                               fgp.kSZ_bat())
        self.cibp = fgc.FactorizedCrossSpectrum(fgf.ModifiedBlackBody(),
                                                fgp.PowerLaw())
        self.radio = fgc.FactorizedCrossSpectrum(fgf.PowerLaw(),
                                                 fgp.PowerLaw())
        self.tsz = fgc.FactorizedCrossSpectrum(fgf.ThermalSZ(),
                                               fgp.tSZ_150_bat())
        self.cibc = fgc.FactorizedCrossSpectrum(
            fgf.CIB(), fgp.PowerSpectrumFromFile(cibc_file))
        self.dust = fgc.FactorizedCrossSpectrum(fgf.ModifiedBlackBody(),
                                                fgp.PowerLaw())
        self.tSZ_and_CIB = fgc.SZxCIB_Choi2020()

        components = self.foregrounds["components"]
        self.fg_component_list = {s: components[s] for s in self.requested_cls}
Esempio n. 2
0
def get_foreground_model(fg_params, fg_model,
                         frequencies, ell,
                         requested_cls=["tt", "te", "ee"]):
    normalisation = fg_model["normalisation"]
    nu_0 = normalisation["nu_0"]
    ell_0 = normalisation["ell_0"]

    from fgspectra import cross as fgc
    from fgspectra import power as fgp
    from fgspectra import frequency as fgf
    # We don't seem to be using this
    # cirrus = fgc.FactorizedCrossSpectrum(fgf.PowerLaw(), fgp.PowerLaw())
    ksz = fgc.FactorizedCrossSpectrum(fgf.ConstantSED(), fgp.kSZ_bat())
    cibp = fgc.FactorizedCrossSpectrum(fgf.ModifiedBlackBody(), fgp.PowerLaw())
    radio = fgc.FactorizedCrossSpectrum(fgf.PowerLaw(), fgp.PowerLaw())
    tsz = fgc.FactorizedCrossSpectrum(fgf.ThermalSZ(), fgp.tSZ_150_bat())
    cibc = fgc.FactorizedCrossSpectrum(fgf.CIB(), fgp.PowerLaw())

    # Make sure to pass a numpy array to fgspectra
    if not isinstance(frequencies, np.ndarray):
        frequencies = np.array(frequencies)

    model = {}
    model["tt", "kSZ"] = fg_params["a_kSZ"] * ksz(
        {"nu": frequencies},
        {"ell": ell, "ell_0": ell_0})
    model["tt", "cibp"] = fg_params["a_p"] * cibp(
        {"nu": frequencies, "nu_0": nu_0,
         "temp": fg_params["T_d"], "beta": fg_params["beta_p"]},
        {"ell": ell, "ell_0": ell_0, "alpha": 2})
    model["tt", "radio"] = fg_params["a_s"] * radio(
        {"nu": frequencies, "nu_0": nu_0, "beta": -0.5 - 2},
        {"ell": ell, "ell_0": ell_0, "alpha": 2})
    model["tt", "tSZ"] = fg_params["a_tSZ"] * tsz(
        {"nu": frequencies, "nu_0": nu_0},
        {"ell": ell, "ell_0": ell_0})
    model["tt", "cibc"] = fg_params["a_c"] * cibc(
        {"nu": frequencies, "nu_0": nu_0,
         "temp": fg_params["T_d"], "beta": fg_params["beta_c"]},
        {"ell": ell, "ell_0": ell_0, "alpha": 2 - fg_params["n_CIBC"]})

    components = fg_model["components"]
    component_list = {s: components[s] for s in requested_cls}
    fg_dict = {}
    for c1, f1 in enumerate(frequencies):
        for c2, f2 in enumerate(frequencies):
            for s in requested_cls:
                fg_dict[s, "all", f1, f2] = np.zeros(len(ell))
                for comp in component_list[s]:
                    fg_dict[s, comp, f1, f2] = model[s, comp][c1, c2]
                    fg_dict[s, "all", f1, f2] += fg_dict[s, comp, f1, f2]

    return fg_dict
Esempio n. 3
0
    def _get_foreground_model(self, fg_params):
        # Might change given different lmax
        lmin, lmax = 2, self.lmax
        l = np.arange(lmin, lmax)

        foregrounds = self.foregrounds
        normalisation = foregrounds["normalisation"]
        nu_0 = normalisation["nu_0"]
        ell_0 = normalisation["ell_0"]
        T_CMB = normalisation["T_CMB"]

        all_freqs = np.concatenate(
            [v for exp in self.experiments for k, v in exp.items()])

        from fgspectra import cross as fgc
        from fgspectra import power as fgp
        from fgspectra import frequency as fgf
        cirrus = fgc.FactorizedCrossSpectrum(fgf.PowerLaw(), fgp.PowerLaw())
        ksz = fgc.FactorizedCrossSpectrum(fgf.ConstantSED(), fgp.kSZ_bat())
        cibp = fgc.FactorizedCrossSpectrum(fgf.ModifiedBlackBody(),
                                           fgp.PowerLaw())
        radio = fgc.FactorizedCrossSpectrum(fgf.PowerLaw(), fgp.PowerLaw())
        tsz = fgc.FactorizedCrossSpectrum(fgf.ThermalSZ(), fgp.tSZ_150_bat())
        cibc = fgc.FactorizedCrossSpectrum(fgf.CIB(), fgp.PowerLaw())

        model = {}
        model["tt", "kSZ"] = fg_params["a_kSZ"] * ksz({"nu": all_freqs}, {
            "ell": l,
            "ell_0": ell_0
        })
        model["tt", "cibp"] = fg_params["a_p"] * cibp(
            {
                "nu": all_freqs,
                "nu_0": nu_0,
                "temp": fg_params["T_d"],
                "beta": fg_params["beta_p"]
            }, {
                "ell": l,
                "ell_0": ell_0,
                "alpha": 2
            })
        model["tt", "radio"] = fg_params["a_s"] * radio(
            {
                "nu": all_freqs,
                "nu_0": nu_0,
                "beta": -0.5 - 2
            }, {
                "ell": l,
                "ell_0": ell_0,
                "alpha": 2
            })
        model["tt",
              "tSZ"] = fg_params["a_tSZ"] * tsz({
                  "nu": all_freqs,
                  "nu_0": nu_0
              }, {
                  "ell": l,
                  "ell_0": ell_0
              })
        model["tt", "cibc"] = fg_params["a_c"] * cibc(
            {
                "nu": all_freqs,
                "nu_0": nu_0,
                "temp": fg_params["T_d"],
                "beta": fg_params["beta_c"]
            }, {
                "ell": l,
                "ell_0": ell_0,
                "alpha": 2 - fg_params["n_CIBC"]
            })

        components = foregrounds["components"]
        component_list = {s: components[s] for s in self.requested_cls}
        fg_model = {}
        for c1, f1 in enumerate(all_freqs):
            for c2, f2 in enumerate(all_freqs):
                for s in self.requested_cls:
                    fg_model[s, "all", f1, f2] = np.zeros(len(l))
                    for comp in component_list[s]:
                        fg_model[s, comp, f1, f2] = model[s, comp][c1, c2]
                        fg_model[s, "all", f1, f2] += fg_model[s, comp, f1, f2]

        return fg_model
Esempio n. 4
0
def test_ksz():
    assert fgp.kSZ_bat() is not None
Esempio n. 5
0
def test_ACT_models():
    # define the models from fgspectra
    ksz = fgc.FactorizedCrossSpectrum(fgf.ConstantSED(), fgp.kSZ_bat())
    cibp = fgc.FactorizedCrossSpectrum(fgf.ModifiedBlackBody(), fgp.PowerLaw())
    radio = fgc.FactorizedCrossSpectrum(fgf.PowerLaw(), fgp.PowerLaw())
    cirrus = fgc.FactorizedCrossSpectrum(fgf.PowerLaw(), fgp.PowerLaw())

    # if there are correlations between components,
    # have to define them in a joined spectrum
    tSZ_and_CIB = fgc.CorrelatedFactorizedCrossSpectrum(
        fgf.Join(fgf.ThermalSZ(), fgf.CIB()), fgp.SZxCIB_Addison2012())

    # for testing purposes we'll also compute the tSZ and clustered CIB alone
    tsz = fgc.FactorizedCrossSpectrum(fgf.ThermalSZ(), fgp.tSZ_150_bat())
    cibc = fgc.FactorizedCrossSpectrum(fgf.CIB(), fgp.PowerLaw())

    ells = np.array([2000])

    par = {
        'nu_0': 150.0,
        'ell_0': 3000,
        'T_CMB': 2.725,
        'T_d': 9.7,
        'a_tSZ': 4.66,
        'a_kSZ': 1.60,
        'a_p': 6.87,
        'beta_p': 2.08,
        'a_c': 6.10,
        'beta_c': 2.08,
        'n_CIBC': 1.20,
        'xi': 0.09,
        'a_s': 3.50,
        'a_g': 0.88,
        'f0_sz': 146.9,
        'f0_synch': 147.6,
        'f0_dust': 149.7
    }

    fsz = np.array([par['f0_sz']])
    fsynch = np.array([par['f0_synch']])
    fdust = np.array([par['f0_dust']])

    result = (par['a_tSZ'] * tsz({
        'nu': fsz,
        'nu_0': par['nu_0']
    }, {
        'ell': ells,
        'ell_0': par['ell_0']
    }), par['a_kSZ'] * ksz({'nu': fsz}, {
        'ell': ells,
        'ell_0': par['ell_0']
    }), par['a_p'] * cibp(
        {
            'nu': fdust,
            'nu_0': par['nu_0'],
            'temp': par['T_d'],
            'beta': par['beta_p']
        }, {
            'ell': ells,
            'ell_0': par['ell_0'],
            'alpha': 2
        }), par['a_c'] * cibc(
            {
                'nu': fdust,
                'nu_0': par['nu_0'],
                'temp': par['T_d'],
                'beta': par['beta_c']
            }, {
                'ell': ells,
                'ell_0': par['ell_0'],
                'alpha': 2 - par['n_CIBC']
            }),
              tSZ_and_CIB(
                  {
                      'kwseq': ({
                          'nu': fsz,
                          'nu_0': par['nu_0']
                      }, {
                          'nu': fdust,
                          'nu_0': par['nu_0'],
                          'temp': par['T_d'],
                          'beta': par['beta_c']
                      })
                  }, {
                      'kwseq': ({
                          'ell': ells,
                          'ell_0': par['ell_0'],
                          'amp': par['a_tSZ']
                      }, {
                          'ell': ells,
                          'ell_0': par['ell_0'],
                          'alpha': 2 - par['n_CIBC'],
                          'amp': par['a_c']
                      }, {
                          'ell':
                          ells,
                          'ell_0':
                          par['ell_0'],
                          'amp':
                          -par['xi'] * np.sqrt(par['a_tSZ'] * par['a_c'])
                      })
                  }), par['a_s'] *
              radio({
                  'nu': fsynch,
                  'nu_0': par['nu_0'],
                  'beta': -0.5 - 2
              }, {
                  'ell': ells,
                  'ell_0': par['ell_0'],
                  'alpha': 2
              }), par['a_g'] *
              cirrus({
                  'nu': fdust,
                  'nu_0': par['nu_0'],
                  'beta': 3.8 - 2
              }, {
                  'ell': ells,
                  'ell_0': par['ell_0'],
                  'alpha': -0.7
              }))
    """
    The following array `dunk13` was generated by inserting this code block to
    line 188 of `ACT_equa_likelihood.f90` in the Fortran ACT multifrequency
    likelihood.

    ```fortran
    if(il==2000) then
      write(*,*) (f1*f1)/(f0*f0)*amp_tsz*cl_tsz(il)
      write(*,*) amp_ksz*cl_ksz(il)
      write(*,*) amp_d*cl_p(il)*(f1_dust/feff)**(2.d0*beta_d)*(planckratiod1*fluxtempd1)**2.d0
      write(*,*) amp_c*cl_c(il)*(f1_dust/feff)**(2.d0*beta_c)*(planckratiod1*fluxtempd1)**2.d0
      write(*,*) -2.d0*sqrt(amp_c*amp_tsz)*xi*cl_szcib(il)*((f1_dust**beta_c*f1*planckratiod1*fluxtempd1)/(feff**beta_c*f0))
      write(*,*) amp_s*cl_p(il)*(f1_synch/feff)**(2.d0*alpha_s)*fluxtemps1**2.d0
      write(*,*) amp_ge*cl_cir(il)*(f1_dust**2.d0/feff**2.d0)**beta_g*fluxtempd1**2.d0
    endif
    ```
    """
    dunk13 = np.array([
        4.46395567509345,  # tsz
        1.37903889069153,  # ksz
        3.02039291213271,  # cibp
        4.36478789541715,  # cibc
        -0.611930900267790,  # cibxtsz
        1.63099887443075,  # sync
        1.15557760337592
    ])  # cirrus

    # for testing purposes, subtract tsz and cibc alone
    # from the combined tsz,cibc,tszxcibc.
    result = np.array([r[0][0][0] for r in result])
    result[-3] -= result[0]
    result[-3] -= result[3]

    tsz_fg, ksz_fg, cibp_fg, cibc_fg, cibxtxz_fg, sync_fg, cirrus_fg = result

    assert (np.abs(tsz_fg - dunk13[0]) / dunk13[0] < 1e-3)
    assert (np.abs(ksz_fg - dunk13[1]) / dunk13[1] < 1e-3)
    assert (np.abs(cibp_fg - dunk13[2]) / dunk13[2] < 1e-3)
    assert (np.abs(cibc_fg - dunk13[3]) / dunk13[3] < 1e-3)
    assert (np.abs(cibxtxz_fg - dunk13[4]) / dunk13[4] < 1e-3)
    assert (np.abs(sync_fg - dunk13[5]) / dunk13[5] < 1e-3)
    assert (np.abs(cirrus_fg - dunk13[6]) / dunk13[6] < 1e-3)