Example #1
0
 def setUp(self):
     self.freqs = np.array([50, 100, 300])
     self.temp = 19.6
     self.beta_d = 1.7
     self.dust_t_b = Dust(150.)
     self.dust_b = Dust(150., temp=self.temp)
     self.dust_t = Dust(150., beta_d=self.beta_d)
     self.dust = Dust(150., temp=self.temp, beta_d=self.beta_d)
Example #2
0
 def __setstate__(self, state):
     self.__dict__.update(state)
     self.cosmo = Class()
     self.components = [CMB(), Dust(150.), Synchrotron(150.)]
     self.mixing_matrix = MixingMatrix(*self.components)
     self.mixing_matrix_evaluator = self.mixing_matrix.evaluator(
         self.instrument.Frequencies)
Example #3
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")
Example #4
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")
Example #5
0
class TestModifiedBlackBody(unittest.TestCase):
    def setUp(self):
        self.freqs = np.array([50, 100, 300])
        self.temp = 19.6
        self.beta_d = 1.7
        self.dust_t_b = Dust(150.)
        self.dust_b = Dust(150., temp=self.temp)
        self.dust_t = Dust(150., beta_d=self.beta_d)
        self.dust = Dust(150., temp=self.temp, beta_d=self.beta_d)

    def test_init_and_evaluation_parameters(self):
        x = self.dust_t_b.eval(self.freqs, self.beta_d, self.temp)
        np.testing.assert_array_almost_equal(
            x, self.dust_t.eval(self.freqs, self.temp))
        np.testing.assert_array_almost_equal(
            x, self.dust_b.eval(self.freqs, self.beta_d))
        np.testing.assert_array_almost_equal(x, self.dust.eval(self.freqs))
Example #6
0
 def get_A_ev(self, fix_temp=False):
     self.fix_temp = fix_temp
     if not self.fix_temp:
         components = [
             CMB(),
             Dust(sky_map.dust_freq),
             Synchrotron(sky_map.synchrotron_freq)
         ]
     else:
         components = [
             CMB(),
             Dust(sky_map.dust_freq, temp=20),
             Synchrotron(sky_map.synchrotron_freq)
         ]
     A = MixingMatrix(*components)
     self.A = A
     A_ev = A.evaluator(self.frequencies)
     self.A_ev = A_ev
    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)
Example #8
0
def get_cl_noise(nl, instrument='SAT'):
    nl_inv = 1 / nl
    if instrument == 'SAT':
        frequencies = V3.so_V3_SA_bands()
    if instrument == 'LAT':
        frequencies = V3.so_V3_LA_bands()

    components = [CMB(), Dust(150.), Synchrotron(20.)]
    A = MixingMatrix(*components)
    A_ev = A.evaluator(frequencies)
    res = [1.59, 20, -3]
    A_ = A_ev(res)
    AtNA = np.einsum('fi, fl, fj -> lij', A_, nl_inv, A_)
    inv_AtNA = np.linalg.inv(AtNA)

    return inv_AtNA.swapaxes(-3, -1)
Example #9
0
from fgbuster.separation_recipies import _get_prewhiten_factors, _A_evaluators
import fgbuster.algebra as fgal

#P_i = list of list for component i, each list corresponds to the pixel of one patch, i.e. P_d=[patch0, patch1,...,patchn] & patchi=[pixel0,pixel1,...]
#input_set_of_betas is a list of all betas for each component and patch i.e. input_set_of_betas=[beta_d1,beta_d2,...,beta_dn,beta_s1,...,beta_sm,temp1,...,templ]
#by convention the component are ordered as beta_dust,beta_sync,temperature_dust

#------------------------------------------------------SKY GENERATION----------------------------------------------------
nside = 2
pixel_number = hp.nside2npix(nside)
sky = get_sky(nside, 'c1d1s1')
instrument = get_instrument(nside, 'litebird')
freq_maps = instrument.observe(sky, write_outputs=False)[0]
freq_maps = freq_maps[:,
                      1:, :]  #on retire la temperature (1:) car on ne prend en compte que Q&U pas I
components = [CMB(), Dust(150.), Synchrotron(20.)]
prewhiten_factors = _get_prewhiten_factors(
    instrument, freq_maps.shape)  # correspond a N^-1/2

# P_d=[range(24),range(24,48)]
# P_t=[range(48)]
# P_s=[range(12),range(12,24),range(24,36),range(36,48)]
# for i in range(len(P_s)):
#     try:
#         P_s[i].index(45)
#         bd_index=i
#         print('bd_index=',bd_index)
#     except:
#         pass
# print bd_index
#
Example #10
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