示例#1
0
def galaxy(fstate, nside, pol, filename, spectral_index):
    """Generate a Milky way only foreground map.

    Use Haslam (extrapolated with a spatially varying spectral index) as a base,
    and then generate random spatial, spectral and polarisation fluctuations for
    unconstrained modes.

    The requested map must have more than two frequencies for this type.
    """

    if fstate.frequencies.shape[0] < 2:
        print("Number of frequencies must be more than two.")
        return

    from cora.foreground import galaxy

    # Read in arguments.
    gal = galaxy.ConstrainedGalaxy()
    gal.nside = nside
    gal.frequencies = fstate.frequencies
    gal.spectral_map = spectral_index

    # Fetch galactic sky
    cs = gal.getpolsky() if pol == "full" else gal.getsky()

    # Save map
    write_map(filename, cs, gal.frequencies, fstate.freq_width, pol != "none")
示例#2
0
def foreground(fstate, nside, pol, filename, maxflux):
    """Generate a full foreground sky map.

    The requested map must have more than two frequencies for this type.
    """

    if fstate.frequencies.shape[0] < 2:
        print("Number of frequencies must be more than two.")
        return

    from cora.foreground import galaxy, pointsource

    # Read in arguments.
    gal = galaxy.ConstrainedGalaxy()
    gal.nside = nside
    gal.frequencies = fstate.frequencies

    # Fetch galactic sky
    cs = gal.getpolsky() if pol == "full" else gal.getsky()

    # Fetch point source maps
    ps = pointsource.CombinedPointSources.like_map(gal)
    ps.flux_max = maxflux

    cs = cs + (ps.getpolsky() if pol == "full" else ps.getsky())

    # Save map
    write_map(filename, cs, gal.frequencies, fstate.freq_width, pol != "none")
示例#3
0
def gen_galaxy(nside, freq, num):

    gal_map = np.zeros((num, 1, hp.nside2npix(nside)), dtype=np.float64)

    gal = galaxy.ConstrainedGalaxy()
    gal.nside = nside
    # gal.frequencies = freq
    gal.frequencies = np.array(
        [freq, freq + 0.1])  # the number of frequencies must be more than two.

    for i in range(num):
        gal_ = gal.getsky()
        gal_map[i] = gal_.mean(axis=0, keepdims=True)

    return gal_map
示例#4
0
    def get_cora_polsky(self, pfrac_max=None):
        from cora.foreground import galaxy

        gal = galaxy.ConstrainedGalaxy()
        gal.nside = self.nside
        gal.frequencies = self.nu_axis * 1e-6  # MHz - self.nu_axis is in Hz.

        stokes_cubes = gal.getpolsky()
        I, Q, U, V = [stokes_cubes[:, i, :] for i in range(4)]

        if self.unpolarized == True:
            Q *= 0
            U *= 0
            V *= 0

        return I, Q, U, V
示例#5
0
def galaxy(ctx, spectral_index):
    """Generate a Milky way only foreground map.

    Use Haslam (extrapolated with a spatially varying spectral index) as a base,
    and then generate random spatial, spectral and polarisation fluctuations for
    unconstrained modes.
    """

    from cora.foreground import galaxy

    # Read in arguments.
    gal = galaxy.ConstrainedGalaxy()
    gal.nside = ctx.obj.nside
    gal.frequencies = ctx.obj.freq
    gal.spectral_map = spectral_index

    # Fetch galactic sky
    cs = gal.getpolsky() if ctx.obj.full_pol else gal.getsky()

    # Save map
    write_map(ctx.obj.filename, cs, gal.frequencies, ctx.obj.freq_width,
              ctx.obj.include_pol)
示例#6
0
def foreground(ctx, maxflux):
    """Generate a full foreground sky map."""

    from cora.foreground import galaxy, pointsource

    # Read in arguments.
    gal = galaxy.ConstrainedGalaxy()
    gal.nside = ctx.obj.nside
    gal.frequencies = ctx.obj.freq

    # Fetch galactic sky
    cs = gal.getpolsky() if ctx.obj.full_pol else gal.getsky()

    # Fetch point source maps
    ps = pointsource.CombinedPointSources.like_map(gal)
    ps.flux_max = maxflux

    cs = cs + (ps.getpolsky() if ctx.obj.full_pol else ps.getsky())

    # Save map
    write_map(ctx.obj.filename, cs, gal.frequencies, ctx.obj.freq_width,
              ctx.obj.include_pol)
示例#7
0
def test_galaxy():

    cr = galaxy.ConstrainedGalaxy()
    cr.nside = nside
    cr.frequencies = fa

    unpol = cr.getsky()
    assert unpol.shape == (32, 12 * nside**2)

    pol = cr.getpolsky()
    assert pol.shape == (32, 4, 12 * nside**2)

    # Check fluctuation amplitude for unpol
    ustd = unpol.std(axis=-1)
    assert (ustd > 10.0).all()
    assert (ustd < 50.0).all()

    # Check fluctuation amplitude for pol
    pstd = pol.std(axis=-1)
    assert (pstd[:, 0] > 10.0).all()
    assert (pstd[:, 0] < 50.0).all()
    assert (pol.std(axis=-1)[:, 1:3] > 0.1).all()
    assert (pol.std(axis=-1)[:, 1:3] < 3.0).all()
    assert (pol.std(axis=-1)[:, 3] == 0.0).all()