Ejemplo n.º 1
0
def test_dust_model(model_tag, freq):

    # for 'd6' model fix the random seed and skip buggy 353 GHz
    if model_tag == "d6":
        if freq == 353:
            return
        np.random.seed(123)

    model = pysm3.Sky(preset_strings=[model_tag], nside=64)

    model_number = {"d0": 1, "d1": 1, "d2": 6, "d3": 9, "d6": 12}[model_tag]
    expected_output = pysm3.read_map(
        "pysm_2_test_data/check{}therm_{}p0_64.fits".format(model_number, freq),
        64,
        unit="uK_RJ",
        field=(0, 1, 2),
    )

    # for some models we do not have tests, we compare with output from a simular model
    # and we increase tolerance, mostly just to exercise the code.
    rtol = {"d0": 0.9}.get(model_tag, 1e-5)

    assert_quantity_allclose(
        expected_output, model.get_emission(freq * units.GHz), rtol=rtol
    )
Ejemplo n.º 2
0
def test_cmb_map_bandpass():

    nside = 32

    # pretend for testing that the Dust is CMB
    model = pysm3.CMBMap(map_IQU="pysm_2/lensed_cmb.fits", nside=nside)

    freq = 100 * u.GHz

    expected_map = pysm3.read_map(
        "pysm_2/lensed_cmb.fits", field=0, nside=nside, unit=u.uK_CMB
    ).to(u.uK_RJ, equivalencies=u.cmb_equivalencies(freq))

    print(
        "expected_scaling",
        (1 * u.K_CMB).to_value(u.K_RJ, equivalencies=u.cmb_equivalencies(freq)),
    )

    freqs = np.array([98, 99, 100, 101, 102]) * u.GHz
    weights = np.ones(len(freqs))

    # just checking that the result is reasonably close
    # to the delta frequency at the center frequency

    assert_quantity_allclose(
        expected_map, model.get_emission(freqs, weights)[0], rtol=1e-3
    )
Ejemplo n.º 3
0
def test_mpi_smoothing(mpi_comm):
    nside = 128
    lmax = 2 * nside
    map_dist = pysm3.MapDistribution(
        pixel_indices=None, mpi_comm=mpi_comm, smoothing_lmax=lmax, nside=nside
    )
    model = pysm3.Model(nside, map_dist=map_dist)
    distributed_map = model.read_map("pysm_2/dust_temp.fits")
    fwhm = 5 * u.deg
    smoothed_distributed_map = pysm3.mpi_smoothing(
        distributed_map, fwhm, map_dist=map_dist
    )
    full_map_rank0 = pysm3.mpi.assemble_map_on_rank0(
        mpi_comm,
        smoothed_distributed_map,
        model.map_dist.pixel_indices,
        n_components=1,
        npix=hp.nside2npix(nside),
    )[0]
    if mpi_comm.rank == 0:
        np.testing.assert_allclose(
            full_map_rank0,
            hp.smoothing(
                pysm3.read_map("pysm_2/dust_temp.fits", nside=nside).value,
                fwhm.to(u.rad).value,
                iter=0,
                lmax=lmax,
                use_pixel_weights=False,
            ),
            rtol=1e-5,
        )
Ejemplo n.º 4
0
def test_read_map_mpi_pixel_indices(mpi_comm):
    # Reads pixel [0] on rank 0
    # pixels [0,1] on rank 1
    # pixels [0,1,2] on rank 2 and so on.
    map_dist = pysm3.MapDistribution(
        mpi_comm=mpi_comm, pixel_indices=list(range(0, mpi_comm.rank + 1))
    )
    m = pysm3.read_map("pysm_2/dust_temp.fits", nside=8, field=0, map_dist=map_dist)
    assert len(m) == mpi_comm.rank + 1
Ejemplo n.º 5
0
def test_read_map_mpi_uniform_distribution(mpi_comm):
    # Spreads the map equally across processes
    map_dist = pysm3.MapDistribution(
        mpi_comm=mpi_comm,
        pixel_indices=pysm3.mpi.distribute_pixels_uniformly(mpi_comm, nside=8),
    )
    m = pysm3.read_map("pysm_2/dust_temp.fits", nside=8, field=0, map_dist=map_dist)
    npix = hp.nside2npix(8)
    assert (
        npix % mpi_comm.size == 0
    ), "This test requires the size of the communicator to divide the number of pixels {}".format(
        npix
    )
    num_local_pix = len(m)
    assert num_local_pix == npix / mpi_comm.size

    complete_m = pysm3.read_map("pysm_2/dust_temp.fits", nside=8, field=0)
    np.testing.assert_allclose(
        m,
        complete_m[num_local_pix * mpi_comm.rank : num_local_pix * (mpi_comm.rank + 1)],
    )
Ejemplo n.º 6
0
def test_bandpass_unit_conversion():
    nside = 32
    freqs = np.array([250, 300, 350]) * u.GHz
    weights = np.ones(len(freqs))
    sky = pysm3.Sky(nside=nside, preset_strings=["c2"])
    CMB_rj_int = sky.get_emission(freqs, weights)
    CMB_thermo_int = CMB_rj_int*pysm3.utils.bandpass_unit_conversion(
        freqs, weights, u.uK_CMB
    )
    expected_map = pysm3.read_map(
        "pysm_2/lensed_cmb.fits", field=(0, 1), nside=nside, unit=u.uK_CMB
    )
    for pol in [0, 1]:
        assert_quantity_allclose(expected_map[pol], CMB_thermo_int[pol], rtol=1e-4)
Ejemplo n.º 7
0
def test_highfreq_dust_model(model_tag, freq):

    model = pysm3.Sky(preset_strings=[model_tag], nside=64)

    expected_output = pysm3.read_map(
        "pysm_2_test_data/check_{}_{}_uK_RJ_64.fits".format(model_tag, freq),
        64,
        unit="uK_RJ",
        field=(0, 1, 2),
    )

    rtol = 1e-5

    assert_quantity_allclose(expected_output,
                             model.get_emission(freq * units.GHz),
                             rtol=rtol)
Ejemplo n.º 8
0
def test_cmb_map():

    nside = 32

    # pretend for testing that the Dust is CMB
    model = pysm3.CMBMap(map_IQU="pysm_2/lensed_cmb.fits", nside=nside)

    freq = 100 * u.GHz

    expected_map = pysm3.read_map(
        "pysm_2/lensed_cmb.fits", field=(0, 1), nside=nside, unit=u.uK_CMB
    ).to(u.uK_RJ, equivalencies=u.cmb_equivalencies(freq))

    simulated_map = model.get_emission(freq)
    for pol in [0, 1]:
        assert_quantity_allclose(expected_map[pol], simulated_map[pol], rtol=1e-5)
Ejemplo n.º 9
0
def test_model(model, freq):

    model = pysm3.Sky(preset_strings=[model], nside=64)

    model_number = 8
    expected_map = pysm3.read_map(
        "pysm_2_test_data/check{}spinn_{}p0_64.fits".format(
            model_number, freq),
        64,
        unit=pysm3.units.uK_RJ,
        field=(0, 1, 2),
    )

    assert_quantity_allclose(expected_map,
                             model.get_emission(freq << pysm3.units.GHz),
                             rtol=1e-3)
Ejemplo n.º 10
0
def test_model_d12(freq):
    sky = Sky(
        preset_strings=["d12"],
        nside=8,
        output_unit=u.MJy / u.sr,
    )

    emission = sky.get_emission(freq * u.GHz)

    expected_map = read_map(
        f"mkd_dust/test/layermodel_nside8_{freq}.fits",
        8,
        unit=u.MJy / u.sr,
        field=(0, 1, 2),
    )

    assert_quantity_allclose(expected_map, emission, rtol=1e-5)
Ejemplo n.º 11
0
def test_mpi_assemble(mpi_comm):
    nside = 128
    map_dist = pysm3.MapDistribution(pixel_indices=None, mpi_comm=mpi_comm, nside=nside)
    model = pysm3.Model(nside, map_dist=map_dist)
    distributed_map = model.read_map("pysm_2/dust_temp.fits")
    full_map_rank0 = pysm3.mpi.assemble_map_on_rank0(
        mpi_comm,
        distributed_map,
        model.map_dist.pixel_indices,
        n_components=1,
        npix=hp.nside2npix(nside),
    )[0]
    if mpi_comm.rank == 0:
        np.testing.assert_allclose(
            full_map_rank0,
            pysm3.read_map("pysm_2/dust_temp.fits", nside=nside).value,
            rtol=1e-5,
        )
Ejemplo n.º 12
0
def test_cmb_lensed(model_tag, freq):

    # The PySM test was done with a different seed than the one
    # baked into the preset models
    pysm3.sky.PRESET_MODELS["c1"]["cmb_seed"] = 1234
    model = pysm3.Sky(preset_strings=[model_tag], nside=64)

    model_number = 5
    expected_output = pysm3.read_map(
        "pysm_2_test_data/check{}cmb_{}p0_64.fits".format(model_number, freq),
        64,
        unit="uK_RJ",
        field=(0, 1, 2),
    )

    assert_quantity_allclose(
        expected_output, model.get_emission(freq * u.GHz), rtol=1e-5
    )
Ejemplo n.º 13
0
def test_model(model, freq):

    model = pysm3.Sky(preset_strings=[model], nside=64)

    model_number = 3
    expected_map = pysm3.read_map(
        "pysm_2_test_data/check{}spinn_{}p0_64.fits".format(
            model_number, freq),
        64,
        unit=pysm3.units.uK_RJ,
        field=0,
    )

    emission = model.get_emission(freq << pysm3.units.GHz)
    assert_quantity_allclose(expected_map, emission[0], rtol=1e-5)

    for i in [1, 2]:
        assert_quantity_allclose(0 * pysm3.units.uK_RJ, emission[i])
Ejemplo n.º 14
0
def test_synchrotron_model(model, freq):

    synchrotron = pysm3.Sky(preset_strings=[model], nside=64)

    model_number = {"s0": 2, "s1": 2, "s2": 7, "s3": 10}[model]
    synch = pysm3.read_map(
        "pysm_2_test_data/check{}synch_{}p0_64.fits".format(
            model_number, freq),
        64,
        unit=pysm3.units.uK_RJ,
        field=(0, 1, 2),
    )

    # for some models we do not have tests, we compare with output from a simular model
    # and we increase tolerance, mostly just to exercise the code.
    rtol = {"s0": 5}.get(model, 1e-5)

    assert_quantity_allclose(synch,
                             synchrotron.get_emission(freq << pysm3.units.GHz),
                             rtol=rtol)
Ejemplo n.º 15
0
def test_read_map_unit_dimensionless():
    m = pysm3.read_map("pysm_2/dust_temp.fits", nside=8, field=0)
    assert u.Unit("") == m.unit
Ejemplo n.º 16
0
def test_read_map_unit():
    m = pysm3.read_map("pysm_2/dust_temp.fits", nside=8, field=0, unit="uK_RJ")
    assert u.Unit("uK_RJ") == m.unit