Beispiel #1
0
def getAllFacesIndex(nside, nested=False):
    #RETURN FOR EACH PIXEL ITS INDEX IN CUBE OF FACES
    if not hp.isnsideok(nside):
        raise ValueError('Incorrect nside')
    npix = hp.nside2npix(nside)
    index_map = np.zeros((npix))
    offset = nside * nside
    #Number one face
    if (nested):
        #Only need to do it for one face
        index = np.array([
            hp.xyf2pix(nside, range(nside), y, 0, nested) for y in range(nside)
        ])
        for face in range(12):
            index_map[index + face * offset] = np.linspace(
                0, offset - 1, offset) + face * offset
    else:
        for face in range(12):
            index = np.array([
                hp.xyf2pix(nside, range(nside), y, face, nested)
                for y in range(nside)
            ])
            index_map[index] = np.linspace(0, offset - 1,
                                           offset) + face * offset
    return index_map
Beispiel #2
0
def getAllIndicesForFace(nside, face, nested=False):
    #Note X: column, y : Rows, Row-Major ordering: Face[y,x]
    index = np.array([
        hp.xyf2pix(nside, range(nside), y, face, nest=nested)
        for y in range(nside)
    ])
    return np.reshape(index, (nside, nside))
Beispiel #3
0
def dgrade(nside_in, nside_out):
    """ map ordering to down grade an healpix map

    Parameters
    ----------
    nside_in : integer
        Nside parameter for the input map.
        Must be a valid healpix Nside value
    nside_out: integer
        Nside parameter for the output map.
        Must be a valid healpix Nside value

    Returns
    -------
    order_out : array
        array defining the re-ordering of the input map to obtain a map with
        nside_out while performing convolution
    """

    assert hp.isnsideok(
        nside_in,
        nest=True), "invalid input nside {0} in call to dgrade".format(
            nside_in)

    assert hp.isnsideok(
        nside_out,
        nest=True), "invalid output nside {0} in call to dgrade".format(
            nside_out)

    assert nside_out < nside_in

    try:
        return read_dgrade(nside_in, nside_out)
    except FileNotFoundError:
        fact = nside_in // nside_out
        pixels = hp.nside2npix(nside_out)
        stride = fact * fact
        result = np.empty(pixels * stride)
        x, y, f = hp.pix2xyf(nside_out, np.arange(pixels))

        i = np.empty(stride, dtype="int")
        j = np.empty(stride, dtype="int")
        f_spread = np.empty(stride, dtype="int")
        for pixnum in range(pixels):
            make_indices(
                i,
                j,
                fact * x[pixnum],
                fact * (x[pixnum] + 1),
                fact * y[pixnum],
                fact * (y[pixnum] + 1),
            )
            f_spread[:] = f[pixnum]
            result[(pixnum * stride):((pixnum + 1) * stride)] = hp.xyf2pix(
                nside_in, i, j, f_spread)

        file_name = dgrade_file_name(nside_in, nside_out)
        write_ancillary_file(file_name, result)
        return result
def get_all_faces(Imag, nested=False):
    r"""
    This function maps a function defined on the sphere to an array of 12
    cartesian images, where each of the cartesian images corresponds to
    a pullback of the given function with respect to one of the 12 HEALPix
    charts.

    **Required parameter**

    :param numpy.ndarray Imag:
       The function defined on the sphere, in the form of a one-dimensional
       :class:`numpy.ndarray` (a HEALPix map).

       .. warning::
           If the HEALPix map ``Imag`` uses "NESTED" ordering, the parameter
           ``nested`` needs to be set to ``True``.

    **Keyword parameter**

    :param bool nested:
        This parameter determines the ordering with which the different
        HEALPix pixels are stored in the array ``Imag``; see
        http://healpix.jpl.nasa.gov/html/intronode4.htm for more details.

        If ``nested`` is set to ``False``, this signifies that ``Imag`` uses
        the "RING" ordering.

    **Return value**

    :return:
        A 3-dimensional :class:`numpy.ndarray` consisting of 12 cartesian
        images (2-dimensional arrays), where each image is a pullback of
        the input function ``Imag`` with respect to one of  the 12 HEALPix
        charts.
    """
    npix = np.shape(Imag)[0]
    assert npix % 12 == 0
    nside = hp.npix2nside(npix)
    taille_face = npix // 12
    cote = int(math.sqrt(taille_face))
    CubeFace = np.zeros((12, cote, cote))
    if not nested:
        NewIm = hp.reorder(Imag, r2n=True)
    else:
        NewIm = Imag
    index = np.zeros((cote, cote))
    index = np.array([hp.xyf2pix(nside, x, y, 0, True)
                      for x in range(nside)
                      for y in range(nside)])
    for face in range(12):
        # print("Process Face {0}".format(face))
        CubeFace[face] = np.resize(NewIm[index + taille_face * face],
                                   (cote, cote))
        # plt.figure(),imshow(np.log10(1+CubeFace[face,:,:]*1e6))
        # plt.title("face {0}".format(face)),plt.colorbar()
    return CubeFace
Beispiel #5
0
def put_one_face(Imag, Face, NumFace=0, nested=False):

    npix = np.size(Imag)
    nside = hpy.npix2nside(npix)
    taille_face = np.int(npix / 12.)
    cote = np.int(np.sqrt(taille_face))
    index = np.zeros((cote, cote))
    index = np.array([
        hpy.xyf2pix(nside, x, y, 0, True) for x in range(nside)
        for y in range(nside)
    ])
    Imag[index + taille_face * NumFace] = np.resize(Face, (cote, cote))

    return Imag
def put_all_faces(CubeFace, nested=False):
    r"""
    Given 12 cartesian functions corresponding to the 12 HEALPix
    faces,  this function pushes each of them back to the sphere
    using one of the HEALPix charts. The 12 different functions are
    pasted together to obtain a function defined on all of the sphere.

    **Required parameter**

    :param numpy.ndarray CubeFace:
        A 3-dimensional :class:`numpy.ndarray` consisting of 12 cartesian
        images (2-dimensional arrays) corresponding to the 12 HEALPix faces.

    **Keyword parameter**

    :param bool nested:
        This parameter determines the ordering with which the different
        HEALPix pixels are stored in the returned array. See
        http://healpix.jpl.nasa.gov/html/intronode4.htm for more details.

        If ``nested`` is set to ``False``, this signifies that the return value
        should use the "RING" ordering.

    **Return value**

    :return:
        A one-dimensional :class:`numpy.ndarray` (a HEALPix map)
        corresponding to the resulting "pasted" function.
    """
    npix = np.size(CubeFace)
    assert npix % 12 == 0
    nside = hp.npix2nside(npix)
    taille_face = npix // 12
    cote = int(math.sqrt(taille_face))
    Imag = np.zeros((npix))
    index = np.zeros((cote, cote))
    index = np.array([hp.xyf2pix(nside, x, y, 0, True)
                      for x in range(nside)
                      for y in range(nside)])
    for face in range(12):
        # print("Process Face {0}".format(face))
        Imag[index + taille_face * face] = np.resize(CubeFace[face],
                                                     (cote, cote))

    if not nested:
        NewIm = hp.reorder(Imag, n2r=True)
    else:
        NewIm = Imag
    return NewIm
Beispiel #7
0
def get_one_face(Imag, NumFace=0, nested=False):

    npix = np.shape(Imag)[0]
    nside = hpy.npix2nside(npix)
    taille_face = npix / 12
    cote = np.int(np.sqrt(taille_face))
    if (nested != True):
        NewIm = hpy.reorder(Imag, r2n=True)
    else:
        NewIm = Imag
    index = np.zeros((cote, cote))
    index = np.array([
        hpy.xyf2pix(nside, x, y, 0, True) for x in range(nside)
        for y in range(nside)
    ])
    Face = np.resize(NewIm[index + taille_face * NumFace], (cote, cote))

    return Face
Beispiel #8
0
def put_all_faces(CubeFace, nested=False):
    npix = np.size(CubeFace)
    nside = hpy.npix2nside(npix)
    taille_face = np.int(npix / 12)
    cote = np.int(np.sqrt(taille_face))
    Imag = np.zeros((npix))
    index = np.zeros((cote, cote))
    index = np.array([
        hpy.xyf2pix(nside, x, y, 0, True) for x in range(nside)
        for y in range(nside)
    ])
    for face in range(12):
        #print("Process Face {0}".format(face))
        Imag[index + taille_face * face] = np.resize(CubeFace[face, :, :],
                                                     (cote * cote))

    if (nested != True):
        NewIm = hpy.reorder(Imag, n2r=True)
    else:
        NewIm = Imag
    return NewIm
Beispiel #9
0
def get_all_faces(Imag, nested=False):
    npix = np.shape(Imag)[0]
    nside = hpy.npix2nside(npix)
    taille_face = np.int(npix / 12)
    cote = np.int(np.sqrt(taille_face))
    CubeFace = np.zeros((12, cote, cote))
    if (nested != True):
        NewIm = hpy.reorder(Imag, r2n=True)
    else:
        NewIm = Imag
    index = np.zeros((cote, cote))
    index = np.array([
        hpy.xyf2pix(nside, x, y, 0, True) for x in range(nside)
        for y in range(nside)
    ])
    for face in range(12):
        #print("Process Face {0}".format(face))
        CubeFace[face, :, :] = np.resize(NewIm[index + taille_face * face],
                                         (cote, cote))
        #plt.figure(),imshow(numpy.log10(1+CubeFace[face,:,:]*1e6))
        #plt.title("face {0}".format(face)),plt.colorbar()
    return CubeFace
Beispiel #10
0
def put_all_faces(cubeface, nested=False):
    """ Return 12 healpix faces to the shpere """

    npix = np.size(cubeface)
    nside = hpy.npix2nside(npix)
    taille_face = npix / 12
    cote = np.int(np.sqrt(taille_face))
    imag = np.zeros((npix))

    index = np.zeros((cote, cote))
    index = np.array([hpy.xyf2pix(nside, eex, yii, 0, True) for eex in range(nside) \
            for yii in range(nside)])
    for face in range(12):
        imag[index + taille_face * face] = np.resize(cubeface[face, :, :],
                                                     (cote, cote))

    if nested != True:
        newim = hpy.reorder(imag, n2r=True)

    else:
        newim = imag

    return newim
Beispiel #11
0
def get_all_faces(imag, nested=False):
    """ Extract 12 healpix faces """

    npix = np.shape(imag)[0]
    nside = hpy.npix2nside(npix)
    taille_face = npix / 12
    cote = np.int(np.sqrt(taille_face))
    cubeface = np.zeros((12, cote, cote))

    if nested != True:
        newim = hpy.reorder(imag, r2n=True)

    else:
        newim = imag

    index = np.zeros((cote, cote))
    index = np.array([hpy.xyf2pix(nside, eex, yii, 0, True) for eex in range(nside) \
            for yii in range(nside)])
    for face in range(12):
        cubeface[face, :, :] = np.resize(newim[index + taille_face * face],
                                         (cote, cote))

    return cubeface
Beispiel #12
0
def dgrade(nside_in, nside_out):
    """Return the list of indexes used to downgrade a HEALPix map

    Args:
        * nside_in (int): ``NSIDE`` for the input map. It must be a
          valid HEALPix value.
        * nside_out (int): ``NSIDE`` for the output map. It must be a
          valid HEALPix value.

    Returns:
        Array defining the re-ordering of the input map to obtain a map with
        ``nside_out`` while performing convolution

    Example::

        import numpy, healpy, nnhealpix

        nside_in = 2
        nside_out = 1
        idx = nnhealpix.dgrade(nside_in, nside_out)

    """

    assert hp.isnsideok(
        nside_in,
        nest=True), "invalid input nside {0} in call to dgrade".format(
            nside_in)

    assert hp.isnsideok(
        nside_out,
        nest=True), "invalid output nside {0} in call to dgrade".format(
            nside_out)

    assert nside_out < nside_in

    try:
        return __read_dgrade_cache(nside_in, nside_out)
    except FileNotFoundError:
        fact = nside_in // nside_out
        pixels = hp.nside2npix(nside_out)
        stride = fact * fact
        result = np.empty(pixels * stride, dtype="int")
        x, y, f = hp.pix2xyf(nside_out, np.arange(pixels))

        i = np.empty(stride, dtype="int")
        j = np.empty(stride, dtype="int")
        f_spread = np.empty(stride, dtype="int")
        for pixnum in range(pixels):
            __make_indices(
                i,
                j,
                fact * x[pixnum],
                fact * (x[pixnum] + 1),
                fact * y[pixnum],
                fact * (y[pixnum] + 1),
            )
            f_spread[:] = f[pixnum]
            result[(pixnum * stride):((pixnum + 1) * stride)] = hp.xyf2pix(
                nside_in, i, j, f_spread)

        file_name = dgrade_file_name(nside_in, nside_out)
        __write_ancillary_file(file_name, result)
        return result