コード例 #1
0
def test_geom_repr():
    geom = HpxGeom(nside=8)
    assert geom.__class__.__name__ in repr(geom)
    assert "nside" in repr(geom)
コード例 #2
0
def test_hpx_global_to_local():
    ax0 = np.linspace(0.0, 1.0, 3)
    ax1 = np.linspace(0.0, 1.0, 3)

    # 2D All-sky
    hpx = HpxGeom(16, False, "galactic")
    assert_allclose(hpx.global_to_local(0, ravel=True), np.array([0]))
    assert_allclose(hpx.global_to_local(633, ravel=True), np.array([633]))
    assert_allclose(hpx.global_to_local((0, 633), ravel=True),
                    np.array([0, 633]))
    assert_allclose(hpx.global_to_local(np.array([0, 633]), ravel=True),
                    np.array([0, 633]))

    # 3D All-sky
    hpx = HpxGeom(16, False, "galactic", axes=[ax0])
    assert_allclose(
        hpx.global_to_local((np.array([177, 177]), np.array([0, 1])),
                            ravel=True),
        np.array([177, 177 + 3072]),
    )

    # 2D Partial-sky
    hpx = HpxGeom(64, False, "galactic", region="DISK(110.,75.,2.)")
    assert_allclose(hpx.global_to_local((0, 633, 706), ravel=True),
                    np.array([-1, 0, 2]))

    # 3D Partial-sky
    hpx = HpxGeom(64,
                  False,
                  "galactic",
                  region="DISK(110.,75.,2.)",
                  axes=[ax0])
    assert_allclose(hpx.global_to_local(633, ravel=True), np.array([0]))
    assert_allclose(hpx.global_to_local(49859, ravel=True), np.array([19]))
    assert_allclose(
        hpx.global_to_local((0, 633, 706, 49859, 49935), ravel=True),
        np.array([-1, 0, 2, 19, 21]),
    )
    assert_allclose(
        hpx.global_to_local(np.array([0, 633, 706, 49859, 49935]), ravel=True),
        np.array([-1, 0, 2, 19, 21]),
    )
    idx_global = (np.array([0, 633, 706, 707, 783]), np.array([0, 0, 0, 1, 1]))
    assert_allclose(hpx.global_to_local(idx_global, ravel=True),
                    [-1, 0, 2, 19, 21])

    # 3D Partial-sky w/ variable bin size
    hpx = HpxGeom([32, 64],
                  False,
                  "galactic",
                  region="DISK(110.,75.,2.)",
                  axes=[ax0])

    assert_allclose(hpx.global_to_local(191, ravel=True), [0])
    assert_allclose(hpx.global_to_local(12995, ravel=True), [6])
    assert_allclose(hpx.global_to_local((0, 191, 233, 12995), ravel=True),
                    [-1, 0, 2, 6])

    idx_global = (np.array([0, 191, 233, 707]), np.array([0, 0, 0, 1]))
    assert_allclose(
        hpx.global_to_local(idx_global, ravel=True),
        np.array([-1, 0, 2, 6]),
    )

    # 4D Partial-sky w/ variable bin size
    hpx = HpxGeom(
        [[16, 32], [32, 64]],
        False,
        "galactic",
        region="DISK(110.,75.,2.)",
        axes=[ax0, ax1],
    )
    assert_allclose(hpx.global_to_local(3263, ravel=True), [1])
    assert_allclose(hpx.global_to_local(28356, ravel=True), [11])

    idx_global = (np.array([46]), np.array([0]), np.array([0]))
    assert_allclose(hpx.global_to_local(idx_global, ravel=True), [0])
コード例 #3
0
def test_make_hpx_to_wcs_mapping():
    ax0 = np.linspace(0.0, 1.0, 3)
    hpx = HpxGeom(16, False, "galactic", region="DISK(110.,75.,2.)")
    # FIXME construct explicit WCS projection here
    wcs = hpx.to_wcs_geom()
    hpx2wcs = HpxToWcsMapping.create(hpx, wcs)
    assert_allclose(
        hpx2wcs.ipix,
        np.array([
            67,
            46,
            46,
            46,
            46,
            29,
            67,
            67,
            46,
            46,
            46,
            46,
            67,
            67,
            67,
            46,
            46,
            46,
            67,
            67,
            67,
            28,
            28,
            28,
            45,
            45,
            45,
            45,
            28,
            28,
            66,
            45,
            45,
            45,
            45,
            28,
        ]),
    )
    assert_allclose(
        hpx2wcs.mult_val,
        np.array([
            0.11111111,
            0.09090909,
            0.09090909,
            0.09090909,
            0.09090909,
            1.0,
            0.11111111,
            0.11111111,
            0.09090909,
            0.09090909,
            0.09090909,
            0.09090909,
            0.11111111,
            0.11111111,
            0.11111111,
            0.09090909,
            0.09090909,
            0.09090909,
            0.11111111,
            0.11111111,
            0.11111111,
            0.16666667,
            0.16666667,
            0.16666667,
            0.125,
            0.125,
            0.125,
            0.125,
            0.16666667,
            0.16666667,
            1.0,
            0.125,
            0.125,
            0.125,
            0.125,
            0.16666667,
        ]),
    )

    hpx = HpxGeom([8, 16],
                  False,
                  "galactic",
                  region="DISK(110.,75.,2.)",
                  axes=[ax0])
    hpx2wcs = HpxToWcsMapping.create(hpx, wcs)
    assert_allclose(
        hpx2wcs.ipix,
        np.array([
            [
                15,
                6,
                6,
                6,
                6,
                6,
                15,
                15,
                6,
                6,
                6,
                6,
                15,
                15,
                15,
                6,
                6,
                6,
                15,
                15,
                15,
                6,
                6,
                6,
                15,
                15,
                15,
                15,
                6,
                6,
                15,
                15,
                15,
                15,
                15,
                6,
            ],
            [
                67,
                46,
                46,
                46,
                46,
                29,
                67,
                67,
                46,
                46,
                46,
                46,
                67,
                67,
                67,
                46,
                46,
                46,
                67,
                67,
                67,
                28,
                28,
                28,
                45,
                45,
                45,
                45,
                28,
                28,
                66,
                45,
                45,
                45,
                45,
                28,
            ],
        ]),
    )
コード例 #4
0
def test_hpxgeom_equal(nside, nested, frame, region, result):
    geom0 = HpxGeom(16, False, "galactic", region=None)
    geom1 = HpxGeom(nside, nested, frame, region=region)

    assert (geom0 == geom1) is result
    assert (geom0 != geom1) is not result