(map_in, inp=None, out=None, r2n=None, n2r=None)
Reorder a healpix map from RING/NESTED ordering to NESTED/RING

    Parameters
    ----------
    map_in : array-like
      the input map to reorder, accepts masked arrays
    inp, out : ``'RING'`` or ``'NESTED'``
      define the input and output ordering
    r2n : bool
      if True, reorder from RING to NESTED
    n2r : bool
      if True, reorder from NESTED to RING

    Returns
    -------
    map_out : array-like
      the reordered map, as masked array if the input was a
      masked array

    Notes
    -----
    if ``r2n`` or ``n2r`` is defined, override ``inp`` and ``out``.

    See Also
    --------
    nest2ring, ring2nest

    Examples
    --------
    >>> import healpy as hp
    >>> hp.reorder(np.arange(48), r2n = True)
    array([13,  5,  4,  0, 15,  7,  6,  1, 17,  9,  8,  2, 19, 11, 10,  3, 28,
           20, 27, 12, 30, 22, 21, 14, 32, 24, 23, 16, 34, 26, 25, 18, 44, 37,
           36, 29, 45, 39, 38, 31, 46, 41, 40, 33, 47, 43, 42, 35])
    >>> hp.reorder(np.arange(12), n2r = True)
    array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
    >>> hp.reorder(hp.ma(np.arange(12.)), n2r = True)
    masked_array(data = [  0.   1.   2.   3.   4.   5.   6.   7.   8.   9.  10.  11.],
                 mask = False,
           fill_value = -1.6375e+30)
    <BLANKLINE>
    >>> m = [np.arange(12.), np.arange(12.), np.arange(12.)]
    >>> m[0][2] = hp.UNSEEN
    >>> m[1][2] = hp.UNSEEN
    >>> m[2][2] = hp.UNSEEN
    >>> m = hp.ma(m)
    >>> hp.reorder(m, n2r = True)
    masked_array(data =
     [[0.0 1.0 -- 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0]
     [0.0 1.0 -- 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0]
     [0.0 1.0 -- 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0]],
                 mask =
     [[False False  True False False False False False False False False False]
     [False False  True False False False False False False False False False]
     [False False  True False False False False False False False False False]],
           fill_value = -1.6375e+30)
    <BLANKLINE>
Reorder a healpix map from RING/NESTED ordering to NESTED/RING
Reorder a healpix map from RING / NESTED ordering to NESTED / RING
def reorder(map_in, inp=None, out=None, r2n=None, n2r=None):
    """Reorder a healpix map from RING/NESTED ordering to NESTED/RING

    Parameters
    ----------
    map_in : array-like
      the input map to reorder, accepts masked arrays
    inp, out : ``'RING'`` or ``'NESTED'``
      define the input and output ordering
    r2n : bool
      if True, reorder from RING to NESTED
    n2r : bool
      if True, reorder from NESTED to RING

    Returns
    -------
    map_out : array-like
      the reordered map, as masked array if the input was a
      masked array

    Notes
    -----
    if ``r2n`` or ``n2r`` is defined, override ``inp`` and ``out``.

    See Also
    --------
    nest2ring, ring2nest

    Examples
    --------
    >>> import healpy as hp
    >>> hp.reorder(np.arange(48), r2n = True)
    array([13,  5,  4,  0, 15,  7,  6,  1, 17,  9,  8,  2, 19, 11, 10,  3, 28,
           20, 27, 12, 30, 22, 21, 14, 32, 24, 23, 16, 34, 26, 25, 18, 44, 37,
           36, 29, 45, 39, 38, 31, 46, 41, 40, 33, 47, 43, 42, 35])
    >>> hp.reorder(np.arange(12), n2r = True)
    array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
    >>> hp.reorder(hp.ma(np.arange(12.)), n2r = True)
    masked_array(data = [  0.   1.   2.   3.   4.   5.   6.   7.   8.   9.  10.  11.],
                 mask = False,
           fill_value = -1.6375e+30)
    <BLANKLINE>
    >>> m = [np.arange(12.), np.arange(12.), np.arange(12.)]
    >>> m[0][2] = hp.UNSEEN
    >>> m[1][2] = hp.UNSEEN
    >>> m[2][2] = hp.UNSEEN
    >>> m = hp.ma(m)
    >>> hp.reorder(m, n2r = True)
    masked_array(data =
     [[0.0 1.0 -- 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0]
     [0.0 1.0 -- 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0]
     [0.0 1.0 -- 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0]],
                 mask =
     [[False False  True False False False False False False False False False]
     [False False  True False False False False False False False False False]
     [False False  True False False False False False False False False False]],
           fill_value = -1.6375e+30)
    <BLANKLINE>
    """
    typ = maptype(map_in)
    if typ == 0:
        npix = len(map_in)
    else:
        npix = len(map_in[0])
    nside = npix2nside(npix)
    if nside > 128:
        bunchsize = npix // 24
    else:
        bunchsize = npix
    if r2n:
        inp = "RING"
        out = "NEST"
    if n2r:
        inp = "NEST"
        out = "RING"
    inp = str(inp).upper()[0:4]
    out = str(out).upper()[0:4]
    if inp not in ["RING", "NEST"] or out not in ["RING", "NEST"]:
        raise ValueError("inp and out must be either RING or NEST")
    if typ == 0:
        mapin = [map_in]
    else:
        mapin = map_in
    mapout = []
    for m_in in mapin:
        if inp == out:
            mapout.append(m_in)
        elif inp == "RING":
            m_out = np.zeros(npix, dtype=type(m_in[0]))
            for ibunch in range(npix // bunchsize):
                ipix_n = np.arange(ibunch * bunchsize, (ibunch + 1) * bunchsize)
                ipix_r = nest2ring(nside, ipix_n)
                m_out[ipix_n] = np.asarray(m_in)[ipix_r]
            mapout.append(m_out)
        elif inp == "NEST":
            m_out = np.zeros(npix, dtype=type(m_in[0]))
            for ibunch in range(npix // bunchsize):
                ipix_r = np.arange(ibunch * bunchsize, (ibunch + 1) * bunchsize)
                ipix_n = ring2nest(nside, ipix_r)
                m_out[ipix_r] = np.asarray(m_in)[ipix_n]
            mapout.append(m_out)
    if typ == 0:
        return mapout[0]
    else:
        return np.array(mapout)
def reorder ( map_in , inp = None , out = None , r2n = None , n2r = None ) : typ = maptype ( map_in ) if typ == 0 : npix = len ( map_in ) else : npix = len ( map_in [ 0 ] ) nside = npix2nside ( npix ) if nside > 128 : bunchsize = npix // 24 else : bunchsize = npix if r2n : inp = "RING" out = "NEST" if n2r : inp = "NEST" out = "RING" inp = str ( inp ) . upper ( ) [ 0 : 4 ] out = str ( out ) . upper ( ) [ 0 : 4 ] if inp not in [ "RING" , "NEST" ] or out not in [ "RING" , "NEST" ] : raise ValueError ( "inp and out must be either RING or NEST" ) if typ == 0 : mapin = [ map_in ] else : mapin = map_in mapout = [ ] for m_in in mapin : if inp == out : mapout . append ( m_in ) elif inp == "RING" : m_out = np . zeros ( npix , dtype = type ( m_in [ 0 ] ) ) for ibunch in range ( npix // bunchsize ) : ipix_n = np . arange ( ibunch * bunchsize , ( ibunch + 1 ) * bunchsize ) ipix_r = nest2ring ( nside , ipix_n ) m_out [ ipix_n ] = np . asarray ( m_in ) [ ipix_r ] mapout . append ( m_out ) elif inp == "NEST" : m_out = np . zeros ( npix , dtype = type ( m_in [ 0 ] ) ) for ibunch in range ( npix // bunchsize ) : ipix_r = np . arange ( ibunch * bunchsize , ( ibunch + 1 ) * bunchsize ) ipix_n = ring2nest ( nside , ipix_r ) m_out [ ipix_r ] = np . asarray ( m_in ) [ ipix_n ] mapout . append ( m_out ) if typ == 0 : return mapout [ 0 ] else : return np . array ( mapout )