コード例 #1
0
def fitting_parameters(string, nside, idpatches):

    npix = hp.nside2npix(nside)  # len(skyvar['dust'][0]['temp'])

    if string == "Bs":
        sky = get_sky(nside, "s1d0")
        param = sky.components[0].pl_index
        patchlist = [
            np.int_(idpatches),
            np.zeros(npix, dtype=np.int_),
            np.zeros(npix, dtype=np.int_),
        ]

    elif string == "Bd":
        sky = get_sky(nside, "s0d1")
        param = sky.components[1].mbb_index
        sky.components[1].mbb_temperature = 20 * sky.components[1].mbb_temperature.unit
        patchlist = [
            np.zeros(npix, dtype=np.int_),
            np.int_(idpatches),
            np.zeros(npix, dtype=np.int_),
        ]

    elif string == "Td":
        sky = get_sky(nside, "s0d1")
        sky.components[1].mbb_index = 1.6 * sky.components[1].mbb_index.unit

        param = (sky.components[1].mbb_temperature).value
        patchlist = [
            np.zeros(npix, dtype=np.int_),
            np.zeros(npix, dtype=np.int_),
            np.int_(idpatches),
        ]

    return sky, patchlist
コード例 #2
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])
コード例 #3
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
コード例 #4
0
ファイル: test_end2end.py プロジェクト: sbiquard/fgbuster
    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}'
コード例 #5
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)
コード例 #6
0
ファイル: test_end2end.py プロジェクト: sbiquard/fgbuster
    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)
コード例 #7
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
コード例 #8
0
ファイル: test_end2end.py プロジェクト: sbiquard/fgbuster
    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
コード例 #9
0
    def test_bandpass_integration_against_pysm(self):
        NSIDE = 2
        N_SAMPLE_BAND = 10
        sky = get_sky(NSIDE, 'd1')
        freqs = np.linspace(80, 120, N_SAMPLE_BAND)
        weights = np.ones(N_SAMPLE_BAND)
        pysm_map = sky.get_emission(freqs * u.GHz, weights)[1].value  # Select Q

        weights = weights / _jysr2rj(freqs)
        weights /= np.trapz(weights, freqs * 1e9)
        dust = sky.components[0]
        fgb_map = Dust(dust.freq_ref_P.value, units='uK_RJ').eval(
            [(freqs, weights)], dust.mbb_index.value, dust.mbb_temperature.value)
        fgb_map = fgb_map[..., 0] * dust.Q_ref.value
        np.testing.assert_allclose(pysm_map, fgb_map, rtol=1e-6)
コード例 #10
0
ファイル: test_end2end.py プロジェクト: sbiquard/fgbuster
    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]
コード例 #11
0
ファイル: test_end2end.py プロジェクト: sbiquard/fgbuster
    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)
コード例 #12
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]
コード例 #13
0
ファイル: test_end2end.py プロジェクト: sbiquard/fgbuster
    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])
コード例 #14
0
 def get_pysm_sky(self):
     sky = pysm.Sky(get_sky(self.nside, self.sky_model))
     self.sky = sky
コード例 #15
0
ファイル: test.py プロジェクト: Gabriel-Ducrocq/Cosmology
from fgbuster.observation_helpers import get_instrument, get_sky
from fgbuster.component_model import CMB, Dust, Synchrotron
from fgbuster.mixingmatrix import MixingMatrix
from pysm import pysm
import sys
import scipy

# make figures
# make_plot = True
make_plot = True

# define resolution of the maps
NSIDE=32#512
Npix = 12*NSIDE**2
# define the sky templates
sky=pysm.Sky(get_sky(NSIDE,'d0s0'))
# dust and synchrotron templates @ 150GHz
dust = sky.dust(150)
sync = sky.synchrotron(150)

############################################
#### CONSTRUCTING TEMPLATES AND COVARIANCE
#### -> p(t) \propto exp[-1/2 (t-\bar{t})^T N_t^{-1} (t-bar{t})]
############################################
# covariance for the templates
# synchrotron template @ 30GHz
sync_map_ = hp.read_map('B3DCMB/COM_CompMap_SynchrotronPol-commander_0256_R2.00.fits', field=(0,1,2,3,4,5))
sync_map_ = hp.ud_grade(sync_map_, nside_out=NSIDE)
Q_sync = sync_map_[0]
U_sync = sync_map_[1]
sigma_Q_sync = sync_map_[4] - sync_map_[2]
コード例 #16
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
コード例 #17
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)