(filename, hdu=1, return_mmax=False)
Read alm from a fits file.

    In the fits file, the alm are written
    with explicit index scheme, index = l**2+l+m+1, while healpix cxx
    uses index = m*(2*lmax+1-m)/2+l. The conversion is done in this
    function.

    Parameters
    ----------
    filename : str or HDUList or HDU or pathlib.Path instance
      The name of the fits file to read
    hdu : int, or tuple of int, optional
      The header to read. Start at 0. Default: hdu=1
    return_mmax : bool, optional
      If true, both the alms and mmax is returned in a tuple. Default: return_mmax=False

    Returns
    -------
    alms[, mmax] : complex array or tuple of a complex array and an int
      The alms read from the file and optionally mmax read from the file
Read alm from a fits file.
Read alm from a fits file .
def read_alm(filename, hdu=1, return_mmax=False):
    """Read alm from a fits file.

    In the fits file, the alm are written
    with explicit index scheme, index = l**2+l+m+1, while healpix cxx
    uses index = m*(2*lmax+1-m)/2+l. The conversion is done in this
    function.

    Parameters
    ----------
    filename : str or HDUList or HDU or pathlib.Path instance
      The name of the fits file to read
    hdu : int, or tuple of int, optional
      The header to read. Start at 0. Default: hdu=1
    return_mmax : bool, optional
      If true, both the alms and mmax is returned in a tuple. Default: return_mmax=False

    Returns
    -------
    alms[, mmax] : complex array or tuple of a complex array and an int
      The alms read from the file and optionally mmax read from the file
    """
    alms = []
    lmaxtot = None
    mmaxtot = None

    opened_file = False
    if isinstance(filename, allowed_paths):
        filename = pf.open(filename)
        opened_file = True

    for unit in np.atleast_1d(hdu):
        idx, almr, almi = [_get_hdu(filename, hdu=unit).data.field(i) for i in range(3)]
        l = np.floor(np.sqrt(idx - 1)).astype(int)
        m = idx - l ** 2 - l - 1
        if (m < 0).any():
            raise ValueError("Negative m value encountered !")
        lmax = l.max()
        mmax = m.max()
        if lmaxtot is None:
            lmaxtot = lmax
            mmaxtot = mmax
        else:
            if lmaxtot != lmax or mmaxtot != mmax:
                raise RuntimeError(
                    "read_alm: harmonic expansion order in {} HDUs {} does not "
                    "match".format(filename, unit, hdu)
                )
        alm = almr * (0 + 0j)
        i = Alm.getidx(lmax, l, m)
        alm.real[i] = almr
        alm.imag[i] = almi
        alms.append(alm)
    if opened_file:
        filename.close()
    if len(alms) == 1:
        alm = alms[0]
    else:
        alm = np.array(alms)
    if return_mmax:
        return alm, mmax
    else:
        return alm
def read_alm ( filename , hdu = 1 , return_mmax = False ) : alms = [ ] lmaxtot = None mmaxtot = None opened_file = False if isinstance ( filename , allowed_paths ) : filename = pf . open ( filename ) opened_file = True for unit in np . atleast_1d ( hdu ) : idx , almr , almi = [ _get_hdu ( filename , hdu = unit ) . data . field ( i ) for i in range ( 3 ) ] l = np . floor ( np . sqrt ( idx - 1 ) ) . astype ( int ) m = idx - l ** 2 - l - 1 if ( m < 0 ) . any ( ) : raise ValueError ( "Negative m value encountered !" ) lmax = l . max ( ) mmax = m . max ( ) if lmaxtot is None : lmaxtot = lmax mmaxtot = mmax else : if lmaxtot != lmax or mmaxtot != mmax : raise RuntimeError ( "read_alm: harmonic expansion order in {} HDUs {} does not " "match" . format ( filename , unit , hdu ) ) alm = almr * ( 0 + 0j ) i = Alm . getidx ( lmax , l , m ) alm . real [ i ] = almr alm . imag [ i ] = almi alms . append ( alm ) if opened_file : filename . close ( ) if len ( alms ) == 1 : alm = alms [ 0 ] else : alm = np . array ( alms ) if return_mmax : return alm , mmax else : return alm