How to use the pixell.enmap.geometry function in pixell

To help you get started, we’ve selected a few pixell examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simonsobs / pixell / tests / test_pixell.py View on Github external
oalm = curvedsky.map2alm(imap.copy(),lmax=lmax)
        rmap = curvedsky.alm2map(oalm,enmap.empty(shape,wcs),spin=0)

        imap2 = imap.copy()[...,::-1]
        oalm = curvedsky.map2alm(imap2.copy(),lmax=lmax)
        rmap2 = curvedsky.alm2map(oalm,enmap.empty(shape,wcs),spin=0)

        assert np.all(np.isclose(rmap[0],rmap2[0]))
        assert np.all(np.isclose(rmap[1],rmap2[1]))
        assert np.all(np.isclose(rmap[2],rmap2[2]))
        

        # Flat-sky
        px = 2.0
        N = 300
        shape,iwcs = enmap.geometry(pos=(0,0),res=np.deg2rad(px/60.),shape=(300,300))
        shape = (3,) + shape
        a = enmap.zeros(shape,iwcs)
        a = a[...,::-1]
        wcs = a.wcs

        seed = 100
        imap = enmap.rand_map(shape,wcs,ps_cmb,seed=seed)
        kmap = enmap.map2harm(imap.copy())
        rmap = enmap.harm2map(kmap,spin=0) # reference map

        imap = imap[...,::-1]
        kmap = enmap.map2harm(imap.copy())
        rmap2 = enmap.harm2map(kmap,spin=0)[...,::-1] # comparison map
        
        assert np.all(np.isclose(rmap[0],rmap2[0]))
        assert np.all(np.isclose(rmap[1],rmap2[1],atol=1e0))
github simonsobs / pixell / tests / test_pixell.py View on Github external
def test_pospix(self):
        # Posmap separable and non-separable on CAR
        for res in [6,12,24]:
            shape,wcs = enmap.fullsky_geometry(res=np.deg2rad(res/60.),proj='car')
            posmap1 = enmap.posmap(shape,wcs)
            posmap2 = enmap.posmap(shape,wcs,separable=True)
            assert np.all(np.isclose(posmap1,posmap2))

        # Pixmap plain
        pres = 0.5
        shape,wcs = enmap.geometry(pos=(0,0),shape=(30,30),res=pres*u.degree,proj='plain')
        yp,xp = enmap.pixshapemap(shape,wcs)
        assert np.all(np.isclose(yp,pres*u.degree))
        assert np.all(np.isclose(xp,pres*u.degree))
        yp,xp = enmap.pixshape(shape,wcs)
        parea = enmap.pixsize(shape,wcs)
        assert np.isclose(parea,(pres*u.degree)**2)
        assert np.isclose(yp,pres*u.degree)
        assert np.isclose(xp,pres*u.degree)
        pmap = enmap.pixsizemap(shape,wcs)
        assert np.all(np.isclose(pmap,(pres*u.degree)**2))

        # Pixmap CAR
        pres = 0.1
        dec_cut = 89.5 # pixsizemap is not accurate near the poles currently
        shape,wcs = enmap.band_geometry(dec_cut=dec_cut*u.degree,res=pres*u.degree,proj='car')
        # Current slow and general but inaccurate near the poles implementation
github simonsobs / pixell / tests / test_geom.py View on Github external
def test_zenithal(self):
        DELT = 0.05
        patch0 = Patch.centered_at(308., -38., 1.+DELT, 1.+DELT)
        patch1 = Patch.centered_at(309., -39., 1.+DELT, 1.+DELT)
        ref = patch0.center()   # (dec,ra) in degrees.
        for proj in ['tan', 'zea', 'air']:
            print('Checking reference tracking of "%s"...' % proj)
            shape0, wcs0 = enmap.geometry(pos=patch0.pos(),
                                          res=DELT*utils.degree,
                                          proj=proj,
                                          ref=ref*DEG)
            shape1, wcs1 = enmap.geometry(pos=patch1.pos(),
                                          res=DELT*utils.degree,
                                          proj=proj,
                                          ref=ref*DEG)
            # Note world2pix wants [(ra,dec)], in degrees...
            pix0 = wcs0.wcs_world2pix(ref[::-1][None],0)
            pix1 = wcs1.wcs_world2pix(ref[::-1][None],0)
            print(shape0,wcs0,pix0)
            assert(np.all(is_centered(pix0)))
            assert(np.all(is_centered(pix1)))
github simonsobs / pixell / tests / test_pixell.py View on Github external
def test_extract(self):
        # Tests that extraction is sensible
        shape,wcs = enmap.geometry(pos=(0,0),shape=(500,500),res=0.01)
        imap = enmap.enmap(np.random.random(shape),wcs)
        smap = imap[200:300,200:300]
        sshape,swcs = smap.shape,smap.wcs
        smap2 = enmap.extract(imap,sshape,swcs)
        pixbox = enmap.pixbox_of(imap.wcs,sshape,swcs)
        # Do write and read test
        filename = "temporary_extract_map.fits" # NOT THREAD SAFE
        enmap.write_map(filename,imap)
        smap3 = enmap.read_map(filename,pixbox=pixbox)
        os.remove(filename)
        assert np.all(np.isclose(smap,smap2))
        assert np.all(np.isclose(smap,smap3))
        assert wcsutils.equal(smap.wcs,smap2.wcs)
        assert wcsutils.equal(smap.wcs,smap3.wcs)
github simonsobs / pixell / tests / test_geom.py View on Github external
def test_reference(self):
        """Test that WCS are properly adjusted, on request, to put a reference
        pixel at integer pixel number.

        """
        DELT = 0.1
        # Note we're adding a half-pixel margin to stay away from rounding cut.
        patch = Patch.centered_at(-52., -38., 12. + DELT, 12.0 + DELT)
        # Test a few reference RAs.
        for ra1 in [0., 0.001, 90.999, 91.101, 120., 179.9, 180.0, 180.1, 270.]:
            shape, wcs = enmap.geometry(pos=patch.pos(),
                                        res=DELT*DEG,
                                        proj='cea',
                                        ref=(0, ra1*DEG))
            ref = np.array([[ra1,0]])
            ref_pix = wcs.wcs_world2pix(ref, 0)
            assert(np.all(is_centered(ref_pix)))
github simonsobs / pixell / tests / test_pixell.py View on Github external
def test_enplot(self):
        print("Testing enplot...")
        shape,wcs = enmap.geometry(pos=(0,0),shape=(3,100,100),res=0.01)
        a = enmap.ones(shape,wcs)
        p = enplot.get_plots(a)
github simonsobs / pixell / tests / test_pixell.py View on Github external
def test_fft(self):
        # Tests that ifft(ifft(imap))==imap, i.e. default normalizations are consistent
        shape,wcs = enmap.geometry(pos=(0,0),shape=(3,100,100),res=0.01)
        imap = enmap.enmap(np.random.random(shape),wcs)
        assert np.all(np.isclose(imap,enmap.ifft(enmap.fft(imap,normalize='phy'),normalize='phy').real))
        assert np.all(np.isclose(imap,enmap.ifft(enmap.fft(imap)).real))
github simonsobs / pixell / pixell / reproject.py View on Github external
def rect_geometry(width, res, height=None, center=(0., 0.), proj="car"):
    shape, wcs = enmap.geometry(pos=rect_box(
        width, center=center, height=height), res=res, proj=proj)
    return shape, wcs