Exemplo n.º 1
0
    def test_pix2ring(self):

        with NumpyRNGContext(12345):

            nside = 1024
            hpx = Healpix(nside)
            npix = hpx.npix

            hpx_idx = np.random.random_integers(0, npix - 1, 10000)

            assert_equal(hp.pix2ring(nside, hpx_idx),
                         hpx.pix2ring_many(hpx_idx))
Exemplo n.º 2
0
    def test_pix2ring(self):

        if not DO_HEALPY:
            # not possible on Windows
            return

        with NumpyRNGContext(12345):

            nside = 1024
            hpx = Healpix(nside)
            npix = hpx.npix

            hpx_idx = np.random.random_integers(0, npix - 1, 10000)

            assert_equal(hp.pix2ring(nside, hpx_idx),
                         hpx.pix2ring_many(hpx_idx))
def create_ring_profile(input_map):
    input_map = np.abs(input_map)
    npix = input_map.shape[0]
    nside = hp.npix2nside(npix)

    rings = hp.pix2ring(nside, np.arange(npix)) - 1

    mask = np.ones([npix])
    mask[np.isnan(input_map)] = 0
    rho = np.bincount(rings, weights=mask)
    averages = np.bincount(rings, weights=np.nan_to_num(input_map)) / rho
    # set profile for empty rings to 1
    averages[np.isnan(averages)] = 1

    result = averages[rings]

    return result
Exemplo n.º 4
0
    def test_pix2ring(self):

        if not DO_HEALPY:
            # not possible on Windows
            return

        with NumpyRNGContext(12345):

            nside = 1024
            hpx = Healpix(nside)
            npix = hpx.npix

            hpx_idx = np.random.random_integers(0, npix - 1, 10000)

            assert_equal(
                hp.pix2ring(nside, hpx_idx),
                hpx.pix2ring_many(hpx_idx)
                )
Exemplo n.º 5
0
def calcAvgBkg(ax, datamap, basename, **opts):

    nside = hp.get_nside(datamap)
    npix = hp.nside2npix(nside)

    counts = zeros(4*nside, dtype=float)
    norm = zeros(4*nside, dtype=float)

    ringId = hp.pix2ring(nside, np.array(range(npix)))
    for i, ring in enumerate(ringId):
        counts[ring] += datamap[i]
        norm[ring] += 1.

    bgmap = zeros(npix, dtype=float)
    mapmax = max(datamap)
    for i, ring in enumerate(ringId):
        bgmap[i] = counts[ring] / norm[ring]

    ra, ri, sigmax, sigmay = returnRI(bgmap, datamap, **opts)
    ax.errorbar(ra, ri, xerr=0*sigmax, yerr=sigmay, marker='o', fmt='.',\
            capsize=4, label=basename+" (avg)", linewidth=2, markersize=8, mew=0)
Exemplo n.º 6
0
def polar_profile(m, nest=False):
    """Obtain the marginalized polar profile of sky map.

    Parameters
    ----------

    m : np.ndarray
        The input HEALPix array.

    nest : bool, default=False
        Indicates whether the input sky map is in nested rather than
        ring-indexed HEALPix coordinates (default: ring).

    Returns
    -------

    theta : np.ndarray
        The polar angles (i.e., the colatitudes) of the isolatitude rings.

    m_int : np.ndarray
        The normalized probability density, such that `np.trapz(m_int, theta)`
        is approximately `np.sum(m)`.
    """
    npix = len(m)
    nside = hp.npix2nside(npix)
    nrings, = hp.pix2ring(nside, np.asarray([npix]))
    startpix, ringpix, costheta, sintheta, _ = hp.ringinfo(
        nside, np.arange(1, nrings))

    if nest:
        m = hp.reorder(m, n2r=True)

    theta = np.arccos(costheta)
    m_int = np.asarray([
        m[i:i + j].sum() * stheta * 0.5 * npix / j
        for i, j, stheta in zip(startpix, ringpix, sintheta)
    ])

    return theta, m_int
Exemplo n.º 7
0
def polar_profile(m, nest=False):
    """Obtain the marginalized polar profile of sky map.

    Parameters
    ----------

    m : np.ndarray
        The input HEALPix array.

    nest : bool, default=False
        Indicates whether the input sky map is in nested rather than
        ring-indexed HEALPix coordinates (default: ring).

    Returns
    -------

    theta : np.ndarray
        The polar angles (i.e., the colatitudes) of the isolatitude rings.

    m_int : np.ndarray
        The normalized probability density, such that `np.trapz(m_int, theta)`
        is approximately `np.sum(m)`.
    """
    npix = len(m)
    nside = hp.npix2nside(npix)
    nrings, = hp.pix2ring(nside, np.asarray([npix]))
    startpix, ringpix, costheta, sintheta, _ = hp.ringinfo(
        nside, np.arange(1, nrings))

    if nest:
        m = hp.reorder(m, n2r=True)

    theta = np.arccos(costheta)
    m_int = np.asarray(
        [m[i:i+j].sum() * stheta * 0.5 * npix / j
         for i, j, stheta in zip(startpix, ringpix, sintheta)])

    return theta, m_int