Beispiel #1
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])
    def test(self, tag):
        # NOTE: this does not test the funciton when the nsides are actually
        # defferent. It just checks that, if they are all the same, the results
        # is equal to the basic_comp_sep result despite all the parameters were
        # fitted at once.
        _, sky_tag, comp_sep_tag = tag.split('___')

        data, s, x = _get_sky(sky_tag)

        components, instrument, nsidepar = comp_sep_tag.split('__')
        components = _get_component(components)
        for c in components:
            c.defaults = [1.1 * d for d in c.defaults]

        instrument = _get_instrument(instrument)
        nsidepar = _get_nside(nsidepar)
        assert len(nsidepar) == 1
        nsidepar = nsidepar[0]

        # basic comp sep call
        res_multipatch = basic_comp_sep(components, instrument, data, nsidepar)

        # multi res comp sep call, with equal resolutions for each spectral index
        res_multires = multi_res_comp_sep(components,
                                          instrument,
                                          data,
                                          nsides=[nsidepar] * len(x))

        aac(res_multipatch.s, s, rtol=2e-5)
        aac(res_multires.s, s, rtol=2e-5)
        aac(res_multipatch.s, res_multires.s, rtol=2e-5)
        for res_x, xx in zip(res_multires.x, x):
            aac(res_x, xx, rtol=2e-5)
Beispiel #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)
Beispiel #4
0
 def test_basic_comp_sep_T(self):
     res_T = basic_comp_sep(self.components,
                            self.instrument,
                            self.freq_maps[:, :1, :],
                            tol=1e-12)
     aac(res_T.x, np.array(self.input), rtol=1e-4)
     aac(res_T.chi, 0, atol=0.05)
Beispiel #5
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
Beispiel #6
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
Beispiel #7
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}'
Beispiel #8
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)
Beispiel #9
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
Beispiel #10
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)
Beispiel #11
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])
    def test(self, tag):
        # NOTE: this does not test the funciton when the nsides are actually
        # defferent. It just checks that, if they are all the same, the results
        # is equal to the basic_comp_sep result despite all the parameters were
        # fitted at once.
        _, sky_tag, comp_sep_tag = tag.split('___')

        data, s, x = _get_sky(sky_tag)

        components, instrument, nsidepar = comp_sep_tag.split('__')
        components = _get_component(components)
        for c in components:
            # NOTE: The starting point tweaked to pass the tests.
            # The problematic ones are those in which we fit for
            # both a powerlaw and a curved-powerlaw.
            c.defaults = [1.09 * d for d in c.defaults]

        instrument = _get_instrument(instrument)
        nsidepar = _get_nside(nsidepar)
        assert len(nsidepar) == 1
        nsidepar = nsidepar[0]

        # basic comp sep call
        res_multipatch = basic_comp_sep(components, instrument, data, nsidepar)

        # multi res comp sep call, with equal resolutions for each spectral index
        res_multires = multi_res_comp_sep(components,
                                          instrument,
                                          data,
                                          nsides=[nsidepar] * len(x))

        # NOTE: The criterion was tweaked (2e-5 -> 3e-5) to make the test pass
        # on TravisCI (it passed already on local machines).
        # The problematic tests are those in which we fit for
        # both a powerlaw and a curved-powerlaw.
        aac(res_multipatch.s, s, rtol=3e-5)
        aac(res_multires.s, s, rtol=3e-5)
        aac(res_multipatch.s, res_multires.s, rtol=3e-5)
        for res_x, xx in zip(res_multires.x, x):
            aac(res_x, xx, rtol=3e-5)
    def test(self, tag):
        _, sky_tag, comp_sep_tag = tag.split('___')

        data, s, x = _get_sky(sky_tag)

        components, instrument, nsidepar = comp_sep_tag.split('__')
        components = _get_component(components)
        for c in components:
            c.defaults = [1.1 * d for d in c.defaults]

        instrument = _get_instrument(instrument)
        nsidepar = _get_nside(nsidepar)
        assert len(nsidepar) == 1
        nsidepar = nsidepar[0]
        res = basic_comp_sep(components, instrument, data, nsidepar)

        if len(x):
            aac(res.x, x, rtol=1e-5)

        aac(res.s, s, rtol=1e-4)
        aac(res.chi[data == hp.UNSEEN], hp.UNSEEN, rtol=0)
        aac(res.chi[data != hp.UNSEEN], 0, atol=0.05)
Beispiel #14
0
 def test_basic_comp_sep_P(self):
     res_P = basic_comp_sep(self.components[:-1], self.instrument,
                            self.freq_maps[:, 1:, :])
     aac(res_P.x, np.array(self.input[:-1]), rtol=1e-5)
     aac(res_P.chi, 0, atol=0.01)