Exemple #1
0
def gaussianfg(ctx):
    """Generate a full-sky Gaussian random field for synchrotron emission.
    """

    import numpy as np

    from cora.core import skysim
    from cora.util import hputil
    from cora.foreground import galaxy

    fsyn = galaxy.FullSkySynchrotron()
    fpol = galaxy.FullSkyPolarisedSynchrotron()

    # Set frequency parameters
    fsyn.frequencies = ctx.obj.freq
    nfreq = len(fsyn.frequencies)

    nside = ctx.obj.nside
    lmax = 3 * nside
    npol = 4 if ctx.obj.full_pol else 1

    cv_fg = np.zeros((lmax + 1, npol, nfreq, npol, nfreq))

    cv_fg[:, 0, :, 0, :] = skysim.clarray(fsyn.angular_powerspectrum, lmax,
                                          fsyn.nu_pixels)

    if ctx.obj.full_pol:
        cv_fg[:, 1, :, 1, :] = skysim.clarray(fpol.angular_powerspectrum, lmax,
                                              fsyn.nu_pixels)
        cv_fg[:, 2, :, 2, :] = skysim.clarray(fpol.angular_powerspectrum, lmax,
                                              fsyn.nu_pixels)

    cv_fg = cv_fg.reshape(lmax + 1, npol * nfreq, npol * nfreq)

    alms = skysim.mkfullsky(cv_fg, nside,
                            alms=True).reshape(npol, nfreq, lmax + 1, lmax + 1)
    alms = alms.transpose((1, 0, 2, 3))

    maps = hputil.sphtrans_inv_sky(alms, nside)
    write_map(ctx.obj.filename, maps, fsyn.frequencies, ctx.obj.freq_width,
              ctx.obj.include_pol)
Exemple #2
0
def foreground_model(lmax, frequencies, npol, pol_frac=1.0, pol_length=None):

    fsyn = galaxy.FullSkySynchrotron()
    fps = PointSources()

    nfreq = frequencies.size

    cv_fg = np.zeros((npol, npol, lmax + 1, nfreq, nfreq))

    cv_fg[0, 0] = skysim.clarray(fsyn.angular_powerspectrum, lmax, frequencies)

    if npol >= 3:
        fpol = galaxy.FullSkyPolarisedSynchrotron()

        if pol_length is not None:
            fpol.zeta = pol_length

        cv_fg[1, 1] = pol_frac * skysim.clarray(fpol.angular_powerspectrum,
                                                lmax, frequencies)
        cv_fg[2, 2] = pol_frac * skysim.clarray(fpol.angular_powerspectrum,
                                                lmax, frequencies)

    cv_fg[0, 0] += skysim.clarray(fps.angular_powerspectrum, lmax, frequencies)
    return cv_fg