示例#1
0
def test_hpxgeom_to_slice(nside, nested, frame, region, axes):
    geom = HpxGeom(nside, nested, frame, region=region, axes=axes)
    slices = tuple([slice(1, 2) for i in range(2, geom.ndim)])
    geom_slice = geom.to_slice(slices)
    assert_allclose(geom_slice.ndim, 2)
    assert_allclose(geom_slice.npix, np.squeeze(geom.npix[slices]))

    idx = geom.get_idx(flat=True)
    idx_slice = geom_slice.get_idx(flat=True)
    if geom.ndim > 2:
        m = np.all([np.isin(t, [1]) for t in idx[1:]], axis=0)
        assert_allclose(idx_slice, (idx[0][m], ))
    else:
        assert_allclose(idx_slice, idx)

    # Test slicing with explicit geometry
    geom = HpxGeom(nside,
                   nested,
                   frame,
                   region=tuple([t[::3] for t in idx]),
                   axes=axes)
    geom_slice = geom.to_slice(slices)
    assert_allclose(geom_slice.ndim, 2)
    assert_allclose(geom_slice.npix, np.squeeze(geom.npix[slices]))

    idx = geom.get_idx()
    idx_slice = geom_slice.get_idx()
    if geom.ndim > 2:
        m = np.all([np.isin(t, [1]) for t in idx[1:]], axis=0)
        assert_allclose(idx_slice, (idx[0][m], ))
    else:
        assert_allclose(idx_slice, idx)
示例#2
0
def test_hpxgeom_init_with_pix(nside, nested, frame, region, axes):
    geom = HpxGeom(nside, nested, frame, region=region, axes=axes)

    idx0 = geom.get_idx(flat=True)
    idx1 = tuple([t[::10] for t in idx0])
    geom = HpxGeom(nside, nested, frame, region=idx0, axes=axes)
    assert_allclose(idx0, geom.get_idx(flat=True))
    assert_allclose(len(idx0[0]), np.sum(geom.npix))
    geom = HpxGeom(nside, nested, frame, region=idx1, axes=axes)
    assert_allclose(idx1, geom.get_idx(flat=True))
    assert_allclose(len(idx1[0]), np.sum(geom.npix))
示例#3
0
def test_hpxgeom_get_pix(nside, nested, frame, region, axes):
    geom = HpxGeom(nside, nested, frame, region=region, axes=axes)
    idx = geom.get_idx(local=False, flat=True)
    idx_local = geom.get_idx(local=True, flat=True)
    assert_allclose(idx, geom.local_to_global(idx_local))

    if axes is not None:
        idx_img = geom.get_idx(local=False,
                               idx=tuple([1] * len(axes)),
                               flat=True)
        idx_img_local = geom.get_idx(local=True,
                                     idx=tuple([1] * len(axes)),
                                     flat=True)
        assert_allclose(idx_img, geom.local_to_global(idx_img_local))