예제 #1
0
            ]:
                print(attr, getattr(fm1, attr), getattr(fm2, attr))
            error += '\nProj{}: fits error'.format(p)
        assert (np.allclose(fm1, fm2))
        assert (np.allclose(fm1.wcs.wcs.crpix, fm2.wcs.wcs.crpix))
        assert (np.allclose(fm1.wcs.wcs.crval, fm2.wcs.wcs.crval))
        assert (np.allclose(fm1.wcs.wcs.cdelt, fm2.wcs.wcs.cdelt))
        assert (np.allclose(fm1.wcs.wcs.pc, fm2.wcs.wcs.pc))

        w = fm2.wcs
        hdr = maps.fitsio.create_wcs_header(fm2)
        if verbose:
            print(repr(hdr))
        pixs = np.array([[0, 0], [0, dim - 1], [dim // 2, dim // 2],
                         [dim - 1, 0], [dim - 1, dim - 1]]).astype(float)
        ra, dec = maps.get_ra_dec_map(fm2)

        angs = []
        bad = False
        for pix in pixs:
            wcs_ang = np.asarray(w.all_pix2world(pix[0], pix[1], 0))
            wcs_ang[wcs_ang > 180] -= 360
            g3_ang = np.asarray(fm2.xy_to_angle(*pix)) / deg
            idx = (int(pix[1]), int(pix[0]))
            try:
                try:
                    assert (np.allclose(g3_ang,
                                        [ra[idx] / deg, dec[idx] / deg]))
                except IndexError:
                    pass
                assert (np.allclose(wcs_ang, g3_ang))
예제 #2
0
    if pair[0] is m3:
        assert (t[15] == 0)
    assert (m1.npix_allocated == nm1)
    assert (m2.npix_allocated == nm2)
    assert (m3.npix_allocated == 0)

for shape in [(20, 500), (21, 501)]:
    print('shape', shape)

    # patch extraction / insertion
    m = FlatSkyMap(shape[1],
                   shape[0],
                   core.G3Units.arcmin,
                   proj=MapProjection.ProjZEA)
    np.asarray(m)[:] = np.random.randn(*m.shape)
    malpha, mdelta = get_ra_dec_map(m)

    x0 = 45
    y0 = 13

    for dy, dx in [[10, 50], [11, 51]]:
        print('    patch', (dy, dx))
        p = m.extract_patch(45, 13, dx, dy)
        palpha, pdelta = get_ra_dec_map(p)
        x1 = x0 - dx // 2
        y1 = y0 - dy // 2
        sx = slice(x1, x1 + dx)
        sy = slice(y1, y1 + dy)
        assert (np.allclose(np.asarray(malpha)[sy, sx], palpha))
        assert (np.allclose(np.asarray(mdelta)[sy, sx], pdelta))
        assert (np.allclose(np.asarray(m)[sy, sx], p))
예제 #3
0
# Conversion to/from flatsky maps
fm_stub = maps.FlatSkyMap(
    300, 300, core.G3Units.arcmin, proj=maps.MapProjection.ProjZEA
)
fm = maps.maputils.healpix_to_flatsky(x, map_stub=fm_stub)
x2 = maps.maputils.flatsky_to_healpix(fm, map_stub=x.clone(False))

hitpix = np.asarray(x2) > 0
assert(np.allclose(np.asarray(x)[hitpix], np.asarray(x2)[hitpix]))


# Coordinate system rotations
a = np.arange(49152)
x = maps.HealpixSkyMap(a)
alpha, delta = maps.get_ra_dec_map(x)

# equatorial to galactic
xgal = x.clone(False)
x.coord_ref = maps.MapCoordReference.Equatorial
xgal.coord_ref = maps.MapCoordReference.Galactic
maps.reproj_map(x, xgal)
ra, dec = maps.azel.convert_gal_to_radec(alpha, delta)
pix = xgal.angles_to_pixels(ra, dec)
assert(np.allclose(np.asarray(pix), np.asarray(xgal)))

# ... and back
xeq = x.clone(False)
x.coord_ref = maps.MapCoordReference.Galactic
xeq.coord_ref = maps.MapCoordReference.Equatorial
maps.reproj_map(x, xeq)