Пример #1
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)
Пример #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")
Пример #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")
Пример #4
0
    def __init__(self, nu, dnu, bnu, bp_number, config, phi_nu=None):
        self.number = bp_number
        self.nu = nu
        self.bnu_dnu = bnu * nu**2 * dnu
        self.nu_mean = np.sum(CMB('K_RJ').eval(self.nu) * self.bnu_dnu * nu) / \
                       np.sum(CMB('K_RJ').eval(self.nu) * self.bnu_dnu)
        field = 'bandpass_%d' % bp_number

        # Get frequency-dependent angle if necessary
        try:
            fname=config['systematics']['bandpasses'][field]['phase_nu']
        except KeyError:
            fname=None
            self.is_complex = False
        if fname:
            from scipy.interpolate import interp1d
            nu_phi,phi=np.loadtxt(fname,unpack=True)
            phif=interp1d(nu_phi, np.radians(phi),
                          bounds_error=False, fill_value=0)
            phi_arr=phif(self.nu)
            phase = np.cos(2*phi_arr) + 1j * np.sin(2*phi_arr)
            self.bnu_dnu = self.bnu_dnu * phase
            self.is_complex = True

        # Checking if we'll be sampling over bandpass systematics
        self.do_shift = False
        self.name_shift = None
        self.do_gain = False
        self.name_gain = None
        self.do_angle = False
        self.name_angle = None
        try:
            d = config['systematics']['bandpasses'][field]['parameters']
        except KeyError:
            d = {}
        for n, p in d.items():
            if p[0] == 'shift':
                self.do_shift = True
                self.name_shift = n
            if p[0] == 'gain':
                self.do_gain = True
                self.name_gain = n
            if p[0] == 'angle':
                self.do_angle = True
                self.name_angle = n

        self.cmb_norm = 1./np.sum(CMB('K_RJ').eval(self.nu) * self.bnu_dnu)
Пример #5
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
Пример #6
0
    def get_cmb_norms(self):
        """
        Evaulates the CMB unit conversion over the bandpasses. 
        """
        cmb_norms = []
        for tn in range(self.nfreqs):
            nus = self.bpasses[tn][0]
            bpass = self.bpasses[tn][1]
            dnu = self.bpasses[tn][2]
            bpass_integration = bpass * dnu

            cmb_thermo_units = CMB('K_RJ').eval(nus) * nus**2
            cmb_norms.append(np.dot(bpass_integration, cmb_thermo_units))
        self.cmb_norm = np.asarray(cmb_norms)
        return
Пример #7
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)
Пример #8
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
#
Пример #9
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