Exemplo n.º 1
0
    def test_Sigma_synchrotron(self):
        NSIDE = 8
        MODEL = 's0'
        INSTRUMENT = 'litebird'
        SIGNAL_TO_NOISE = 20
        sky = pysm.Sky(get_sky(NSIDE, MODEL))
        instrument = pysm.Instrument(get_instrument(INSTRUMENT, NSIDE))
        components = [cm.Synchrotron(100.)]
        ref = []
        for component in components:
            ref += component.defaults

        with suppress_stdout():
            freq_maps, noise_maps = instrument.observe(sky,
                                                       write_outputs=False)

        signal = freq_maps[:, 0, 0]
        noise = np.std(noise_maps[:, 0], axis=-1)
        maps = signal / np.dot(signal, noise) * SIGNAL_TO_NOISE
        maps = maps[:, np.newaxis] + noise_maps[:, 0]
        res = basic_comp_sep(components,
                             instrument,
                             maps,
                             nside=hp.get_nside(maps))
        white = (res.x[0] - ref[0]) / res.Sigma[0, 0]**0.5
        _, p = kstest(white, 'norm')
        assert p > 0.01
Exemplo n.º 2
0
    def __init__(self, NSIDE):
        self.NSIDE = NSIDE
        self.Npix = 12 * NSIDE**2
        print("Initialising sampler")
        self.cosmo = Class()
        print("Maps")
        self.templates_map, self.templates_var = aggregate_pixels_params(
            get_pixels_params(self.NSIDE))
        print("betas")
        self.matrix_mean, self.matrix_var = aggregate_mixing_params(
            get_mixing_matrix_params(self.NSIDE))
        print("Cosmo params")
        self.cosmo_means = np.array(COSMO_PARAMS_MEANS)
        self.cosmo_var = (np.diag(COSMO_PARAMS_SIGMA) / 2)**2

        plt.hist(self.templates_map)
        plt.savefig("mean_values.png")
        plt.close()
        plt.hist(self.templates_var)
        plt.savefig("std_values.png")
        plt.close()
        self.instrument = pysm.Instrument(
            get_instrument('litebird', self.NSIDE))
        self.components = [CMB(), Dust(150.), Synchrotron(150.)]
        self.mixing_matrix = MixingMatrix(*self.components)
        self.mixing_matrix_evaluator = self.mixing_matrix.evaluator(
            self.instrument.Frequencies)
        print("End of initialisation")
Exemplo n.º 3
0
    def test_Sigma_dust_sync_betas_temp(self):
        NSIDE = 8
        MODEL = 'd0s0'
        INSTRUMENT = 'litebird'
        SIGNAL_TO_NOISE = 10000
        UNITS = 'uK_CMB'
        sky = pysm.Sky(get_sky(NSIDE, MODEL))
        instrument = pysm.Instrument(
            get_instrument(INSTRUMENT, NSIDE, units=UNITS))
        components = [
            cm.Dust(150., temp=20., units=UNITS),
            cm.Synchrotron(150., units=UNITS)
        ]
        ref = []
        for component in components:
            ref += component.defaults
        ref = np.array(ref)

        with suppress_stdout():
            freq_maps, noise_maps = instrument.observe(sky,
                                                       write_outputs=False)

        signal = freq_maps[:, 0, 0]  # Same signal for all the pixels
        noise = noise_maps[:, 0]
        signal_ver = signal / np.dot(signal, signal)**0.5
        noise_std = np.std([np.dot(n, signal_ver) for n in noise.T])
        maps = signal_ver * noise_std * SIGNAL_TO_NOISE
        maps = maps[:, np.newaxis] + noise

        res = basic_comp_sep(components, instrument, maps, nside=NSIDE)
        diff = (res.x.T - ref)
        postS = np.mean(diff[..., None] * diff[..., None, :], axis=0)
        S = res.Sigma.T[0]
        aac(postS, S, rtol=1. / NSIDE)
Exemplo n.º 4
0
    def __init__(self, NSIDE, As):
        self.NSIDE = NSIDE
        self.Npix = 12 * NSIDE**2
        self.As = As
        print("Initialising sampler")
        self.cosmo = Class()
        #print("Maps")
        #A recommenter
        #self.Qs, self.Us, self.sigma_Qs, self.sigma_Us = aggregate_by_pixels_params(get_pixels_params(self.NSIDE))
        #print("betas")
        self.matrix_mean, self.matrix_var = aggregate_mixing_params(
            get_mixing_matrix_params(self.NSIDE))
        print("Cosmo params")
        self.cosmo_means = np.array(COSMO_PARAMS_MEANS)
        self.cosmo_stdd = np.diag(COSMO_PARAMS_SIGMA)

        self.instrument = pysm.Instrument(
            get_instrument('litebird', self.NSIDE))
        self.components = [CMB(), Dust(150.), Synchrotron(150.)]
        self.mixing_matrix = MixingMatrix(*self.components)
        self.mixing_matrix_evaluator = self.mixing_matrix.evaluator(
            self.instrument.Frequencies)

        self.noise_covar_one_pix = self.noise_covariance_in_freq(self.NSIDE)
        #A recommenter
        #self.noise_stdd_all = np.concatenate([np.sqrt(self.noise_covar_one_pix) for _ in range(2*self.Npix)])
        print("End of initialisation")
Exemplo n.º 5
0
    def test_Sigma_dust_sync_betas_temp(self):
        NSIDE = 8
        MODEL = 'd0s0'
        INSTRUMENT = 'LiteBIRD'
        SIGNAL_TO_NOISE = 10000
        UNITS = 'uK_CMB'
        sky = get_sky(NSIDE, MODEL)
        instrument = get_instrument(INSTRUMENT)
        components = [
            cm.Dust(150., temp=20., units=UNITS),
            cm.Synchrotron(150., units=UNITS)
        ]
        ref = []
        for component in components:
            ref += component.defaults
        ref = np.array(ref)

        freq_maps = get_observation(instrument, sky, unit=UNITS)
        noise_maps = get_noise_realization(NSIDE, instrument, unit=UNITS)

        signal = freq_maps[:, 0, 0]  # Same signal for all the pixels
        noise = noise_maps[:, 0]
        signal_ver = signal / np.dot(signal, signal)**0.5
        noise_std = np.std([np.dot(n, signal_ver) for n in noise.T])
        maps = signal_ver * noise_std * SIGNAL_TO_NOISE
        maps = maps[:, np.newaxis] + noise
        if not hasattr(instrument, 'depth_i'):
            instrument['depth_i'] = instrument.depth_p / np.sqrt(2)

        res = basic_comp_sep(components, instrument, maps, nside=NSIDE)
        diff = (res.x.T - ref)
        postS = np.mean(diff[..., None] * diff[..., None, :], axis=0)
        S = res.Sigma.T[0]
        aac(postS, S, rtol=1. / NSIDE)
Exemplo n.º 6
0
    def test_Sigma_synchrotron(self):
        NSIDE = 8
        MODEL = 's0'
        INSTRUMENT = 'LiteBIRD'
        SIGNAL_TO_NOISE = 20
        sky = get_sky(NSIDE, MODEL)
        instrument = get_instrument(INSTRUMENT)
        components = [cm.Synchrotron(100.)]
        ref = []
        for component in components:
            ref += component.defaults

        freq_maps = get_observation(instrument, sky)
        noise_maps = get_noise_realization(NSIDE, instrument)

        signal = freq_maps[:, 0, 0]
        noise = np.std(noise_maps[:, 0], axis=-1)
        maps = signal / np.dot(signal, noise) * SIGNAL_TO_NOISE
        maps = maps[:, np.newaxis] + noise_maps[:, 0]
        if not hasattr(instrument, 'depth_i'):
            instrument['depth_i'] = instrument.depth_p / np.sqrt(2)
        res = basic_comp_sep(components,
                             instrument,
                             maps,
                             nside=hp.get_nside(maps))
        white = (res.x[0] - ref[0]) / res.Sigma[0, 0]**0.5
        _, p = kstest(white, 'norm')
        assert p > 0.01, f'KS probability is {p}'
Exemplo n.º 7
0
    def test_Sigma_dust_one_parameter(self):
        NSIDE = 8
        MODEL = 'd0'
        INSTRUMENT = 'LiteBIRD'
        SIGNAL_TO_NOISE = 10
        sky = get_sky(NSIDE, MODEL)
        instrument = get_instrument(INSTRUMENT)
        components = [cm.Dust(100., temp=20.)]
        ref = []
        for component in components:
            ref += component.defaults

        freq_maps = get_observation(instrument, sky)
        noise_maps = get_noise_realization(NSIDE, instrument)

        signal = freq_maps[:, 0, 0]
        noise = noise_maps[:, 0]
        signal_ver = signal / np.dot(signal, signal)**0.5
        noise_std = np.std([np.dot(n, signal_ver) for n in noise.T])
        maps = signal_ver * noise_std * SIGNAL_TO_NOISE
        maps = maps[:, np.newaxis] + noise
        if not hasattr(instrument, 'depth_i'):
            instrument['depth_i'] = instrument.depth_p / np.sqrt(2)

        res = basic_comp_sep(components,
                             instrument,
                             maps,
                             nside=hp.get_nside(maps))
        white = (res.x[0] - ref[0]) / res.Sigma[0, 0]**0.5
        _, p = kstest(white, 'norm')
        assert p > 0.01
Exemplo n.º 8
0
    def test_dependence_on_nu0_RJ(self):
        NSIDE = 8
        MODEL = 'c1s0'
        INSTRUMENT = 'litebird'
        sky = pysm.Sky(get_sky(NSIDE, MODEL))
        instrument = pysm.Instrument(
            get_instrument(INSTRUMENT, NSIDE, units='uK_RJ'))
        components100 = [
            cm.CMB(units='K_RJ'),
            cm.Synchrotron(100., units='K_RJ')
        ]
        components10 = [
            cm.CMB(units='K_RJ'),
            cm.Synchrotron(10., units='K_RJ')
        ]

        with suppress_stdout():
            freq_maps, _ = instrument.observe(sky, write_outputs=False)

        res100 = basic_comp_sep(components100, instrument, freq_maps)
        res10 = basic_comp_sep(components10, instrument, freq_maps)
        aac(res100.Sigma, res10.Sigma)
        aac(res100.x, res10.x)
        aac(res100.s[0], res10.s[0])
        aac(res100.s[1], res10.s[1] * 10**res10.x[0])
Exemplo n.º 9
0
    def test_Sigma_dust_one_parameter(self):
        NSIDE = 8
        MODEL = 'd0'
        INSTRUMENT = 'litebird'
        SIGNAL_TO_NOISE = 10
        sky = pysm.Sky(get_sky(NSIDE, MODEL))
        instrument = pysm.Instrument(get_instrument(INSTRUMENT, NSIDE))
        components = [cm.Dust(100., temp=20.)]
        ref = []
        for component in components:
            ref += component.defaults

        with suppress_stdout():
            freq_maps, noise_maps = instrument.observe(sky,
                                                       write_outputs=False)

        signal = freq_maps[:, 0, 0]
        noise = noise_maps[:, 0]
        signal_ver = signal / np.dot(signal, signal)**0.5
        noise_std = np.std([np.dot(n, signal_ver) for n in noise.T])
        maps = signal_ver * noise_std * SIGNAL_TO_NOISE
        maps = maps[:, np.newaxis] + noise

        res = basic_comp_sep(components,
                             instrument,
                             maps,
                             nside=hp.get_nside(maps))
        white = (res.x[0] - ref[0]) / res.Sigma[0, 0]**0.5
        _, p = kstest(white, 'norm')
        assert p > 0.01
Exemplo n.º 10
0
    def get_noise(self, sensitiviy_mode=2, one_over_f_mode=2):
        # TODO: put SAT and LAT caracteristics in class atributes
        if self.instrument == 'SAT':
            print('SAT white noise')
            # noise_covariance = np.eye(12)
            # inv_noise = np.eye(12)
            white_noise = np.repeat(
                V3.so_V3_SA_noise(sensitiviy_mode, one_over_f_mode, 1, 0.1,
                                  self.nside * 3)[2], 2, 0)

            # noise_covariance = np.diag(
            #     (white_noise / hp.nside2resol(self.nside, arcmin=True))**2)
            # inv_noise = np.diag((hp.nside2resol(
            #     self.nside, arcmin=True)/white_noise)**2)
            #
            # noise_N_ell = np.repeat(
            #     V3.so_V3_SA_noise(sensitiviy_mode, one_over_f_mode, 1, 0.1,
            #                       self.nside*3, beam_corrected=True)[1],
            #     2, 0)
            # ells = np.shape(noise_N_ell)[-1]
            # noise_cov_ell = [np.diag(noise_N_ell[:, k]) for k in range(ells)]
            # inv_noise_cov_ell = [np.diag(1/noise_N_ell[:, k])
            #                      for k in range(ells)]

        elif self.instrument == 'LAT':
            white_noise = np.repeat(V3.so_V3_LA_noise(0, 0.4, 5000)[2], 2, 0)
            noise_covariance = np.diag(
                (white_noise / hp.nside2resol(self.nside, arcmin=True))**2)
            inv_noise = np.diag(
                1 / (white_noise / hp.nside2resol(self.nside, arcmin=True))**2)

        elif self.instrument == 'LiteBIRD':
            sensitivity = np.array([
                37.5, 24.0, 19.9, 16.2, 13.5, 11.7, 9.2, 7.6, 5.9, 6.5, 5.8,
                7.7, 13.2, 19.5, 37.5
            ])
        elif self.instrument == 'Planck':
            print('Planck white noise')
            # noise_covariance = np.eye(12)
            # inv_noise = np.eye(12)

            white_noise = np.repeat(get_instrument('planck_P')['sens_P'], 2, 0)

        noise_covariance = np.diag(
            (white_noise / hp.nside2resol(self.nside, arcmin=True))**2)
        inv_noise = np.diag(
            (hp.nside2resol(self.nside, arcmin=True) / white_noise)**2)

        # noise_N_ell = np.repeat(
        #     V3.so_V3_SA_noise(sensitiviy_mode, one_over_f_mode, 1, 0.1,
        #                       self.nside*3, beam_corrected=True)[1],
        #     2, 0)
        # ells = np.shape(noise_N_ell)[-1]
        # noise_cov_ell = [np.diag(noise_N_ell[:, k]) for k in range(ells)]
        # inv_noise_cov_ell = [np.diag(1/noise_N_ell[:, k])
        #                      for k in range(ells)]

        self.noise_covariance = noise_covariance
        self.inv_noise = inv_noise
Exemplo n.º 11
0
    def _get_comp_instr(self, nu0, fit, x0):

        comp = []
        comp.append(fgbuster.component_model.CMB())
        for i in self.skyconfig.keys():
            if i == 'dust':
                if fit == 'd0' or fit == 'd1':
                    comp.append(fgbuster.component_model.Dust(nu0=nu0,
                                                              temp=20))
                else:
                    comp.append(
                        fgbuster.component_model.Dust_2b(nu0=nu0,
                                                         temp=20,
                                                         break_width=0.3))
            elif i == 'synchrotron':
                comp.append(fgbuster.component_model.Synchrotron(nu0=nu0))

        self._define_defaults_comp(comp, x0)
        if len(self.config['frequency']) == 9:
            instr = get_instrument('CMBS4')
        else:
            instr = get_instrument('CMBS4BI')

        return comp, instr
Exemplo n.º 12
0
 def get_frequency(self):
     if self.instrument == 'SAT':
         print(self.instrument)
         self.frequencies = V3.so_V3_SA_bands()
     if self.instrument == 'LAT':
         print(self.instrument)
         self.frequencies = V3.so_V3_LA_bands()
     if self.instrument == 'LiteBIRD':
         print(self.instrument)
         self.frequencies = np.array([
             40.0, 50.0, 60.0, 68.4, 78.0, 88.5, 100.0, 118.9, 140.0, 166.0,
             195.0, 234.9, 280.0, 337.4, 402.1
         ])
     if self.instrument == 'Planck':
         self.frequencies = get_instrument('planck_P')['frequencies']
Exemplo n.º 13
0
    def setUp(self):
        NSIDE = 16
        MODEL = 'c1d0s0f1'
        INSTRUMENT = 'LiteBIRD'
        X0_FACTOR = 0.99
        sky = get_sky(NSIDE, MODEL)
        self.instrument = get_instrument(INSTRUMENT)
        self.freq_maps = get_observation(self.instrument, sky)

        self.components = [cm.CMB(), cm.Dust(200.), cm.Synchrotron(100.)]
        freefree = cm.PowerLaw(100.)
        freefree.defaults = [-2.14]  # Otherwise it is the same as Synchrotron
        self.components.append(freefree)
        self.input = []
        for component in self.components:
            self.input += component.defaults
            component.defaults = [d * X0_FACTOR for d in component.defaults]
Exemplo n.º 14
0
    def test_dependence_on_nu0_CMB(self):
        NSIDE = 4
        MODEL = 'c1s0'
        INSTRUMENT = 'LiteBIRD'
        sky = get_sky(NSIDE, MODEL)
        instrument = get_instrument(INSTRUMENT)
        components100 = [cm.CMB(), cm.Synchrotron(100.)]
        components10 = [cm.CMB(), cm.Synchrotron(10.)]

        freq_maps = get_observation(instrument, sky)

        res10 = basic_comp_sep(components10, instrument, freq_maps)
        res100 = basic_comp_sep(components100, instrument, freq_maps)
        aac(res100.Sigma, res10.Sigma)
        aac(res100.x, res10.x)
        aac(res100.s[0], res10.s[0], atol=1e-7)
        factor = _cmb2rj(10.) * _rj2cmb(100.)
        aac(res100.s[1], res10.s[1] * 10**res10.x[0] * factor)
Exemplo n.º 15
0
    def setUp(self):
        NSIDE = 16
        MODEL = 'c1d0s0f1'
        INSTRUMENT = 'litebird'
        X0_FACTOR = 0.99
        sky = pysm.Sky(get_sky(NSIDE, MODEL))
        self.instrument = pysm.Instrument(get_instrument(INSTRUMENT, NSIDE))
        with suppress_stdout():
            self.freq_maps, self.noise = self.instrument.observe(
                sky, write_outputs=False)

        self.components = [cm.CMB(), cm.Dust(200.), cm.Synchrotron(100.)]
        freefree = cm.PowerLaw(100.)
        freefree.defaults = [-2.14]  # Otherwise it is the same as Synchrotron
        self.components.append(freefree)
        self.input = []
        for component in self.components:
            self.input += component.defaults
            component.defaults = [d * X0_FACTOR for d in component.defaults]
Exemplo n.º 16
0
    def test_dependence_on_nu0_RJ(self):
        NSIDE = 8
        MODEL = 'c1s0'
        INSTRUMENT = 'LiteBIRD'
        sky = get_sky(NSIDE, MODEL)
        instrument = get_instrument(INSTRUMENT)
        components100 = [
            cm.CMB(units='K_RJ'),
            cm.Synchrotron(100., units='K_RJ')
        ]
        components10 = [
            cm.CMB(units='K_RJ'),
            cm.Synchrotron(10., units='K_RJ')
        ]

        freq_maps = get_observation(instrument, sky, unit='K_RJ')

        res100 = basic_comp_sep(components100, instrument, freq_maps)
        res10 = basic_comp_sep(components10, instrument, freq_maps)
        aac(res100.Sigma, res10.Sigma)
        aac(res100.x, res10.x)
        aac(res100.s[0], res10.s[0])
        aac(res100.s[1], res10.s[1] * 10**res10.x[0])
Exemplo n.º 17
0
def _get_instrument(tag, nside=None):
    if 'dict' in tag:
        instrument = {}
        instrument['Frequencies'] = np.arange(10., 300, 30.)
        if 'h**o' in tag:
            instrument['Sens_I'] = (np.linspace(20., 40., 10) - 30)**2
            instrument['Sens_P'] = instrument['Sens_I']
        elif 'vary' in tag:
            np.random.seed(0)
            instrument['Cov_N'] = (np.linspace(20., 40., 10) - 30)**4
            instrument['Cov_N'] /= hp.nside2resol(nside, arcmin=True)**2
            shape = (instrument['Frequencies'].size, hp.nside2npix(nside))
            factor = 10**np.random.uniform(-1, 1, size=np.prod(shape))
            factor = factor.reshape(shape)
            instrument['Cov_N'] = instrument['Cov_N'][:, np.newaxis] * factor

            instrument['Cov_I'] = instrument['Cov_N'][:, np.newaxis]

            instrument['Cov_P'] = np.stack([instrument['Cov_N']] * 2, axis=1)
    elif 'pysm' in tag:
        instrument = pysm.Instrument(get_instrument('test', nside))
    else:
        raise ValueError('Unsupported tag: %s' % tag)
    return instrument
Exemplo n.º 18
0
def estimate_Stat_and_Sys_residuals(
    idpatches,
    galactic_binmask,
    parameter_string,
    randomseed=1234567,
    version="v28",
    instrument_conf="LiteBIRD",
):

    nside = hp.get_nside(galactic_binmask)
    v = {
        "v27": np.array(
            [
                39.76,
                25.76,
                20.69,
                12.72,
                10.39,
                8.95,
                6.43,
                4.3,
                4.43,
                4.86,
                5.44,
                9.72,
                12.91,
                19.07,
                43.53,
            ]
        ),
        "v28": np.array(
            [
                59.29,
                32.78,
                25.76,
                15.91,
                13.10,
                11.25,
                7.74,
                5.37,
                5.65,
                5.81,
                6.48,
                15.16,
                17.98,
                24.99,
                49.90,
            ]
        ),
    }

    sens_I_LB = np.array(
        [
            25.60283688,
            13.90070922,
            14.32624113,
            8.0141844,
            7.30496454,
            5.95744681,
            4.96453901,
            4.11347518,
            3.33333333,
            4.96453901,
            4.11347518,
            5.67375887,
            6.45390071,
            8.08510638,
            13.90070922,
        ]
    )
    skyconst = get_sky(nside, "d0s0")

    instrument = get_instrument(instrument_conf)
    instrument.depth_i = sens_I_LB
    instrument.depth_p = v["v28"]
    patches = np.zeros_like(galactic_binmask, dtype=np.int_)

    patches[galactic_binmask] = np.int_(idpatches) + 1

    skyvar, patchlist = fitting_parameters(parameter_string, nside, patches)

    np.random.seed(seed=randomseed)

    signalvar = get_observation(instrument, skyvar, noise=False)

    signoisemaps = get_observation(instrument, skyconst, noise=True)

    signalvar[:, :, ~galactic_binmask] = hp.UNSEEN
    signoisemaps[:, :, ~galactic_binmask] = hp.UNSEEN
    components = [CMB(), Synchrotron(20), Dust(353)]

    sysresult = adaptive_comp_sep(components, instrument, signalvar[:, 1:], patchlist)
    statresult = adaptive_comp_sep(
        components, instrument, signoisemaps[:, 1:], patchlist
    )

    msys = np.zeros_like(signalvar[0])
    mstat = np.zeros_like(signoisemaps[0])

    # Mask eventually unconstrained pixels
    for i in range(2):
        nan = np.ma.masked_invalid(sysresult.s[0, i]).mask

        msys[i + 1, :] = sysresult.s[0, i]
        msys[i + 1, nan] = hp.UNSEEN

        nan = np.ma.masked_invalid(statresult.s[0, i]).mask

        mstat[i + 1, :] = statresult.s[0, i]
        mstat[i + 1, nan] = hp.UNSEEN
    return msys, mstat
Exemplo n.º 19
0
	hp.mollview(sigma_U_dust, sub=(248), title='sigma U dust')
	pl.show()
	# exit()
def p_template_computation(temp_):
	logprob = -0.5*np.sum(templates_map**2/np.diag(covariance_templates)**2)
	return logprob
# build a random vector of template of size 4 x Npix 
# for example : 
template_test = np.random.normal(0,1,(4,Npix))
print p_template_computation(template_test)
'''
############################################
####  CONSTRUCTING THE MIXING MATRIX A
############################################
# define the instrumental specifications
instrument = pysm.Instrument(get_instrument(NSIDE, 'litebird'))
# define the components in the sky and their scaling laws
components=[CMB(), Dust(150.), Synchrotron(150.)]
# initiate function to estimate scaling laws for LiteBIRD frequencies
A = MixingMatrix(*components)
A_ev = A.evaluator(instrument.Frequencies)
print(A_ev([1.56,20,-3.1]).shape)
print(instrument.Frequencies)

'''
####################################################
####  CONSTRUCTING TEMPLATES OF BETA AND SIGMA BETA
#### -> p(\beta} \propto exp[-1/2 (\beta-\bar{\beta})^T \sigma_\beta^{-2} (\beta-\bar{\beta})]
####################################################
dust_spectral_indices_ = hp.read_map('COM_CompMap_dust-commander_0256_R2.00.fits', field=(3,5,6,8))
dust_spectral_indices_ = hp.ud_grade(dust_spectral_indices_, nside_out=NSIDE)
Exemplo n.º 20
0
    def test_d0s0(self):

        # EXTERNAL_xFORECAST_RUN RESULTS
        EXT_BETA = [1.54000015, 19.99999402, -3.00000035]
        EXT_SIGMA_BETA = np.array(
            [[1.07107731e+09, 1.02802459e+07, 3.05900728e+07],
             [1.02802459e+07, 8.80751745e+05, 2.64258857e+05],
             [3.05900728e+07, 2.64258857e+05, 8.80649611e+05]])
        EXT_NOISE_POST_COMP_SEP = [
            6.985360419978725e-07, 6.954968812329504e-07,
            6.952971018678473e-07, 6.97621370087622e-07, 6.97915989771863e-07,
            6.981532542428136e-07, 6.984690244398313e-07,
            6.963706038663776e-07, 6.962958090983174e-07,
            6.999793141962897e-07, 6.966029199088166e-07,
            6.998332244730213e-07, 6.97245540450936e-07, 7.013469190449905e-07,
            6.98145319051069e-07, 6.997552902541847e-07, 7.006828378883164e-07,
            6.993357502111902e-07, 7.016843277673384e-07, 7.02276431905913e-07,
            7.009651598790946e-07, 7.024327502574484e-07,
            7.058590396724249e-07, 7.035637090541009e-07,
            7.034402740635456e-07, 7.05326337473677e-07, 7.086905417607417e-07,
            7.067287662339356e-07, 7.06396320822362e-07, 7.075857215168964e-07,
            7.102089978543108e-07, 7.118461226661247e-07
        ]
        EXT_CL_STAT_RES = [
            3.43065437e-08, 2.13752688e-07, 2.50160994e-08, 4.39734801e-08,
            1.75192647e-08, 2.10382699e-08, 9.55361360e-09, 8.80726572e-09,
            7.34671936e-09, 4.24354505e-09, 3.50430309e-09, 3.21803173e-09,
            3.62342203e-09, 1.83222822e-09, 2.40687985e-09, 1.76806752e-09,
            2.57252032e-09, 1.19987889e-09, 1.71606507e-09, 1.01867261e-09,
            1.11709059e-09, 1.05584166e-09, 8.37499498e-10, 1.04610499e-09,
            7.27953346e-10, 7.55604710e-10, 5.50190292e-10, 6.38657310e-10,
            4.82912230e-10, 5.21029442e-10, 4.77954181e-10
        ]
        EXT_BIAS_R = 0.00100556
        EXT_SIGMA_R = 0.0003163

        nside = 16
        # define sky and foregrounds simulations
        sky = pysm.Sky(get_sky(nside, 'd0s0'))
        # define instrument
        instrument = pysm.Instrument(get_instrument('litebird', nside))
        # get noiseless frequency maps
        with suppress_stdout():
            freq_maps = instrument.observe(sky, write_outputs=False)[0]
        # take only the Q and U maps
        freq_maps = freq_maps[:, 1:]
        # define components used in the modeling
        components = [CMB(), Dust(150.), Synchrotron(150.)]
        # call for xForecast
        with suppress_stdout():
            res = xForecast(components,
                            instrument,
                            freq_maps,
                            2,
                            2 * nside - 1,
                            1.0,
                            make_figure=False)
        # list of checks
        aac(EXT_BETA, res.x, rtol=1e-03)
        aac(np.diag(EXT_SIGMA_BETA), np.diag(res.Sigma_inv), rtol=5e-02)
        aac(EXT_NOISE_POST_COMP_SEP[0], res.noise[0], rtol=1e-02)
        aac(EXT_BIAS_R, res.cosmo_params['r'][0][0], rtol=1e-02)
        aac(EXT_SIGMA_R, res.cosmo_params['r'][1][0], rtol=1e-02)
Exemplo n.º 21
0
Npix = 12 * NSIDE**2

COSMO_PARAMS_NAMES = [
    "n_s", "omega_b", "omega_cdm", "100*theta_s", "ln10^{10}A_s", "tau_reio"
]
COSMO_PARAMS_MEANS = [0.9665, 0.02242, 0.11933, 1.04101, 3.047, 0.0561]
COSMO_PARAMS_SIGMA = [0.0038, 0.00014, 0.00091, 0.00029, 0.014, 0.0071]
LiteBIRD_sensitivities = np.array([
    36.1, 19.6, 20.2, 11.3, 10.3, 8.4, 7.0, 5.8, 4.7, 7.0, 5.8, 8.0, 9.1, 11.4,
    19.6
])

Qs, Us, sigma_Qs, sigma_Us = aggregate_by_pixels_params(
    get_pixels_params(NSIDE))

instrument = pysm.Instrument(get_instrument('litebird', NSIDE))
components = [CMB(), Dust(150.), Synchrotron(150.)]
mixing_matrix = MixingMatrix(*components)
mixing_matrix_evaluator = mixing_matrix.evaluator(instrument.Frequencies)


def noise_covariance_in_freq(nside):
    cov = LiteBIRD_sensitivities**2 / hp.nside2resol(nside, arcmin=True)**2
    return cov


noise_covar_one_pix = noise_covariance_in_freq(NSIDE)


def sample_mixing_matrix_parallel(betas):
    return mixing_matrix_evaluator(betas)[:, 1:]