From 9013f55aa6e5d58e40e3a70b636547c2e8230fe7 Mon Sep 17 00:00:00 2001 From: Sasha Rahlin Date: Tue, 19 Sep 2023 22:19:07 +0200 Subject: [PATCH] speed up healpix tests by avoiding indexedsparse backend --- maps/tests/healpix_maps.py | 82 +++++++++++++-------------- maps/tests/healpixskymap_operators.py | 3 +- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/maps/tests/healpix_maps.py b/maps/tests/healpix_maps.py index 0819118f..3857c4f7 100755 --- a/maps/tests/healpix_maps.py +++ b/maps/tests/healpix_maps.py @@ -59,47 +59,6 @@ assert(x2[0] == v0) assert(np.sum(x2) == np.sum(v)) -# angles -pixels = np.arange(x.size, dtype=int) -alpha, delta = x.pixels_to_angles(pixels) -alpha, delta = np.asarray(alpha), np.asarray(delta) -alpha[alpha < 0] += 360 * core.G3Units.deg -theta, phi = hp.pix2ang(x.nside, pixels) - -assert(np.allclose(alpha, phi)) -assert(np.allclose(delta, np.pi / 2 - theta)) - -pixels2 = x.angles_to_pixels(alpha, delta) -assert(np.allclose(pixels, pixels2)) - -# interpolation -dx = x.res / 2.0 -vx = np.asarray(x.get_interp_values(alpha + dx, delta + dx)) -vh = hp.get_interp_val(np.asarray(x), theta - dx, phi + dx) -assert(not np.allclose(vx, vh)) - -# Query disc -avec = [] -dvec = [] -rvec = [] -masked = set() -alpha = 30 * core.G3Units.deg -radius = 5 * core.G3Units.deg -for delta in range(-90, 91, 10): - delta *= core.G3Units.deg - theta = 90 * core.G3Units.deg - delta - avec.append(alpha) - dvec.append(delta) - rvec.append(radius) - pix1 = np.asarray(x.query_disc(alpha, delta, radius), dtype=int) - v = hp.ang2vec(theta, alpha) - pix2 = np.asarray(hp.query_disc(x.nside, v, radius), dtype=int) - masked |= set(pix2) - assert not (set(pix1) ^ set(pix2)) - -mask = maps.make_point_source_mask(x, np.asarray(avec), np.asarray(dvec), np.asarray(rvec)) -assert not (set(mask.nonzero()) ^ masked) - x.shift_ra = True # check attributes @@ -188,6 +147,47 @@ assert((ki == kr).all()) assert((vi == vr).all()) +# angles +pixels = np.arange(x.size, dtype=int) +alpha, delta = x.pixels_to_angles(pixels) +alpha, delta = np.asarray(alpha), np.asarray(delta) +alpha[alpha < 0] += 360 * core.G3Units.deg +theta, phi = hp.pix2ang(x.nside, pixels) + +assert(np.allclose(alpha, phi)) +assert(np.allclose(delta, np.pi / 2 - theta)) + +pixels2 = x.angles_to_pixels(alpha, delta) +assert(np.allclose(pixels, pixels2)) + +# interpolation +dx = x.res / 2.0 +vx = np.asarray(x.get_interp_values(alpha + dx, delta + dx)) +vh = hp.get_interp_val(np.asarray(x), theta - dx, phi + dx) +assert(not np.allclose(vx, vh)) + +# Query disc +avec = [] +dvec = [] +rvec = [] +masked = set() +alpha = 30 * core.G3Units.deg +radius = 5 * core.G3Units.deg +for delta in range(-90, 91, 10): + delta *= core.G3Units.deg + theta = 90 * core.G3Units.deg - delta + avec.append(alpha) + dvec.append(delta) + rvec.append(radius) + pix1 = np.asarray(x.query_disc(alpha, delta, radius), dtype=int) + v = hp.ang2vec(theta, alpha) + pix2 = np.asarray(hp.query_disc(x.nside, v, radius), dtype=int) + masked |= set(pix2) + assert not (set(pix1) ^ set(pix2)) + +mask = maps.make_point_source_mask(x, np.asarray(avec), np.asarray(dvec), np.asarray(rvec)) +assert not (set(mask.nonzero()) ^ masked) + # Conversion to/from flatsky maps fm_stub = maps.FlatSkyMap( 300, 300, core.G3Units.arcmin, proj=maps.MapProjection.ProjZEA diff --git a/maps/tests/healpixskymap_operators.py b/maps/tests/healpixskymap_operators.py index a11b3cb2..c0a9847e 100755 --- a/maps/tests/healpixskymap_operators.py +++ b/maps/tests/healpixskymap_operators.py @@ -68,6 +68,7 @@ assert(n.npix_allocated == 1) assert(n.npix_nonzero == 1) +m.ringsparse = True n = m ** 2 assert(n[15] == 4) assert(n.npix_allocated == 1) @@ -82,7 +83,7 @@ m1 = m m2 = m.copy() -m2.ringsparse = True +m2.indexedsparse = True m3 = m.copy() m3.dense = True