Esempio n. 1
0
def test_geometry_constructor():
    nside = 1
    lmax = 4

    g = scarf.Geometry(
        nrings=3,
        nph=[4, 4, 4],
        ofs=[0, 4, 8],
        stride=1,
        phi0=[np.pi / 4, 0, np.pi / 4],
        theta=[np.arccos(1 - 1 / 3), np.pi / 2,
               np.arccos(1 / 3 - 1)],
        wgt=[np.pi / 3] * 3,
    )
    hg = scarf.healpix_geometry(1, 1)

    m = np.random.random(12 * nside**2)
    alm = np.random.random(hp.Alm.getsize(lmax)).astype(np.complex)

    g_alm = g.map2alm(m, lmax, lmax, 1, [-1, 1])
    hg_alm = hg.map2alm(m, lmax, lmax, 1, [-1, 1])

    g_map = g.alm2map(alm, lmax, lmax, 1, [-1, 1])
    hg_map = hg.alm2map(alm, lmax, lmax, 1, [-1, 1])
    assert np.linalg.norm(g_alm - hg_alm) < 1e-7
    assert np.linalg.norm(g_map - hg_map) < 1e-7
Esempio n. 2
0
def test_alm2phase2map_spin():
    nside = 128
    lmax = nside
    mmax = nside

    alm = np.random.random(size=(3, hp.Alm.getsize(lmax, mmax))) * (1j + 2)
    map = hp.sphtfunc.alm2map(alm, nside, lmax=lmax, mmax=mmax, pol=True)
    geom = scarf.healpix_geometry(nside, 1)

    phase_from_alm = geom.alm2phase_spin(alm[1:], 2, lmax, mmax, 10, [-1, 1])
    map_from_alm = geom.phase2map(phase_from_alm, lmax, mmax, 10, [-1, 1])

    assert np.linalg.norm(map_from_alm[0] - map[1]) < 1e-7
Esempio n. 3
0
def test_map2phase2alm():
    nside = 128
    lmax = nside
    mmax = nside

    m = np.array(range(1, 12 * nside**2 + 1))
    geom = scarf.healpix_geometry(nside, 1)

    alm = hp.sphtfunc.map2alm(m, lmax=lmax, mmax=mmax, iter=0)
    phase_from_map = geom.map2phase(m, lmax, mmax, 1, [-1, 1])
    alm_from_map = geom.phase2alm(phase_from_map, lmax, mmax, 1, [-1, 1])

    assert np.linalg.norm(alm_from_map - alm) < 1e-7
Esempio n. 4
0
def test_alm2phase2map():
    nside = 128
    lmax = nside
    mmax = nside

    alm = np.random.random(hp.Alm.getsize(lmax, mmax)) * (1j + 2)
    map = hp.sphtfunc.alm2map(alm, nside, lmax=lmax, mmax=mmax)
    geom = scarf.healpix_geometry(nside, 1)

    phase_from_alm = geom.alm2phase(alm, lmax, mmax, 1, [-1, 1])
    map_from_alm = geom.phase2map(phase_from_alm, lmax, mmax, 10, [-1, 1])

    assert np.linalg.norm(map_from_alm - map) < 1e-7
Esempio n. 5
0
def test_map2phase2alm_spin():
    nside = 128
    lmax = nside
    mmax = nside

    m = np.random.random(size=(3, 12 * nside**2))
    geom = scarf.healpix_geometry(nside, 1)
    alm = hp.sphtfunc.map2alm(m, lmax=lmax, mmax=mmax, iter=0, pol=True)

    phase_from_map = geom.map2phase(m[1:2], lmax, mmax, 1, [-1, 1])
    alm_from_map = geom.phase2alm_spin(phase_from_map, 2, lmax, mmax, 1,
                                       [-1, 1])

    assert np.linalg.norm(alm_from_map[0] - alm[1]) < 1e-7
Esempio n. 6
0
def test_attributes():
    nside = 512
    g = scarf.healpix_geometry(512, 1)
    assert (np.linalg.norm(
        g.theta - [g.get_theta(iring)
                   for iring in range(0, g.get_nrings())]) < 1e-7)
    assert (np.linalg.norm(
        g.weight - [g.get_weight(iring)
                    for iring in range(0, g.get_nrings())]) < 1e-7)
    assert (np.linalg.norm(
        g.phi0 - [g.get_phi0(iring)
                  for iring in range(0, g.get_nrings())]) < 1e-7)
    assert (np.linalg.norm(
        g.nph - [g.get_nph(iring)
                 for iring in range(0, g.get_nrings())]) < 1e-7)
Esempio n. 7
0
def test_alm2phase2alm():

    nside = 128
    lmax = nside
    mmax = nside

    map = np.random.random(12 * nside**2)
    alm = hp.sphtfunc.map2alm(map, lmax, iter=0)
    alm_back = hp.sphtfunc.map2alm(hp.sphtfunc.alm2map(alm, nside, lmax),
                                   lmax,
                                   iter=0)
    geom = scarf.healpix_geometry(nside, 1)

    phase_from_alm = geom.alm2phase(alm, lmax, mmax, 10, [-1, 1])
    alm_from_phase = geom.phase2alm(phase_from_alm, lmax, mmax, 10, [-1, 1])

    assert np.linalg.norm(alm_from_phase - alm_back) < 1e-5
Esempio n. 8
0
def test_alm2phase2alm_spin():
    nside = 128
    lmax = nside
    mmax = nside

    map = np.random.random(size=(3, 12 * nside**2))
    alm = hp.sphtfunc.map2alm(map, lmax, iter=0, pol=True)
    alm_back = hp.sphtfunc.map2alm(hp.sphtfunc.alm2map(alm,
                                                       nside,
                                                       lmax,
                                                       pol=True),
                                   lmax,
                                   iter=0,
                                   pol=True)

    geom = scarf.healpix_geometry(nside, 1)
    phase_from_alm = geom.alm2phase_spin(alm[1:], 2, lmax, mmax, 10, [-1, 1])
    alm_from_phase = geom.phase2alm_spin(phase_from_alm, 2, lmax, mmax, 10,
                                         [-1, 1])

    assert np.linalg.norm(alm_from_phase - alm_back[1:]) < 1e-4