Exemplo n.º 1
0
def slice_beam(rows,
               cols,
               fname='/mn/svati/d1/eirikgje/data/beams/hdf/tempbeam_30GHz.hdf',
               temponly=True,
               file_has_temp_only=True,
               ordering='ring'):
    inF = tables.openFile(fname)
    if isinstance(rows, int):
        rows = [rows]
    if isinstance(cols, int):
        cols = [cols]

    if ordering == 'ring':
        rows = mapmod.ring2nest_ind(rows, nside=512)
        cols = mapmod.ring2nest_ind(cols, nside=512)
    if temponly:
        out = np.zeros((len(rows), len(cols)))
    else:
        out = np.zeros((len(rows), len(cols), 6))
    for i in range(len(rows)):
        path = "/pix%07d" % rows[i]
        tempgroup = inF.getNode(path)
        if not file_has_temp_only or not temponly:
            tmap = np.reshape(np.array(tempgroup.map), (-1, 6))

        lpix = tempgroup.listpix[:]
        for j in range(len(cols)):
            if cols[j] in lpix:
                if temponly:
                    if file_has_temp_only:
                        out[i,
                            j] = tempgroup.map[np.where(lpix == cols[j])[0][0]]
                    else:
                        #print np.where(tempgroup.listpix == cols[j])
                        out[i, j] = tmap[np.where(lpix == cols[j])[0][0], 0]
                else:
                    out[i, j, :] = tmap[np.where(lpix == cols[j])[0][0], :]
            else:
                if temponly:
                    out[i, j] = 0
                else:
                    out[i, j, :] = 0

    inF.close()
    return out
Exemplo n.º 2
0
def slice_beam(rows, cols, fname='/mn/svati/d1/eirikgje/data/beams/hdf/tempbeam_30GHz.hdf', temponly=True, file_has_temp_only=True, ordering='ring'):
    inF = tables.openFile(fname)
    if isinstance(rows, int):
        rows = [rows]
    if isinstance(cols, int):
        cols = [cols]

    if ordering=='ring':
        rows = mapmod.ring2nest_ind(rows, nside=512)
        cols = mapmod.ring2nest_ind(cols, nside=512)
    if temponly:
        out = np.zeros((len(rows), len(cols)))
    else:
        out = np.zeros((len(rows), len(cols), 6))
    for i in range(len(rows)):
        path = "/pix%07d" % rows[i] 
        tempgroup = inF.getNode(path)
        if not file_has_temp_only or not temponly:
            tmap = np.reshape(np.array(tempgroup.map), (-1, 6))

        lpix = tempgroup.listpix[:]
        for j in range(len(cols)):
            if cols[j] in lpix:
                if temponly:
                    if file_has_temp_only:
                        out[i, j] = tempgroup.map[np.where
                                (lpix == cols[j])[0][0]]
                    else:
                        #print np.where(tempgroup.listpix == cols[j])
                        out[i, j] = tmap[np.where
                                        (lpix == cols[j])[0][0], 0]
                else:
                    out[i, j, :] = tmap[np.where
                                        (lpix == cols[j])[0][0], :]
            else:
                if temponly:
                    out[i, j] = 0
                else:
                    out[i, j, :] = 0

    inF.close()
    return out
Exemplo n.º 3
0
def test_ordering_conversion():
    r2npixs = {0:15, 44:95, 112:99, 55:52}
    n2rpixs = {0:74, 106:94, 66:135, 176:191}
    nside = 4
    npix = 12*nside**2
    map = np.arange(npix)
    md = mapmod.MapData(map=map, ordering='ring', nside=nside)
    md = md.switchordering()
    for key, value in r2npixs.items():
        yield eq_, md.map[value], key
    md = md.switchordering()
    yield ok_, np.all(map == md.map)

    md = mapmod.MapData(map=map, ordering='nested', nside=nside)
    md = md.switchordering()
    for key, value in n2rpixs.items():
        yield eq_, md.map[value], key
    md = md.switchordering()
    yield ok_, np.all(map == md.map)

    #Reload the module because init_r2n and init_n2r acts differently depending
    #on whether the other has been initialized:
    reload(mapmod)
    md = mapmod.MapData(map=map, ordering='nested', nside=nside)
    md = md.switchordering()
    for key, value in n2rpixs.items():
        yield eq_, md.map[value], key
    md = md.switchordering()
    yield ok_, np.all(map == md.map)

    md = mapmod.MapData(map=map, ordering='ring', nside=nside)
    md = md.switchordering()
    for key, value in r2npixs.items():
        yield eq_, md.map[value], key
    md = md.switchordering()
    yield ok_, np.all(map == md.map)

    #Test for other nsides
    nside = 2
    npix = 12*nside**2
    map = np.arange(npix)
    md = mapmod.MapData(map=map, ordering='ring', nside=nside)
    md = md.switchordering()
    md = md.switchordering()
    yield ok_, np.all(map == md.map)

    nside = 8
    npix = 12*nside**2
    map = np.arange(npix)
    md = mapmod.MapData(map=map, ordering='ring', nside=nside)
    md = md.switchordering()
    md = md.switchordering()
    yield ok_, np.all(map == md.map)

    #Test for other shapes
    map = shaperange((3, 4, npix))
    md = mapmod.MapData(nside, map=map)
    md = md.switchordering()
    md = md.switchordering()
    yield eq_, md.map.shape, (3, 4, npix)
    yield ok_, np.all(map == md.map)

    #Test the pixel versions as well
    nside = 4
    for key, value in r2npixs.items():
        yield eq_, mapmod.ring2nest_ind(key, nside), value
    for key, value in n2rpixs.items():
        yield eq_, mapmod.nest2ring_ind(key, nside), value