(
    filename, alms, out_dtype=None, lmax=-1, mmax=-1, mmax_in=-1, overwrite=False
)
Write alms to a fits file.

    In the fits file the alms are written
    with explicit index scheme, index = l*l + l + m +1, possibly out of order.
    By default write_alm makes a table with the same precision as the alms.
    If specified, the lmax and mmax parameters truncate the input data to
    include only alms for which l <= lmax and m <= mmax.

    Parameters
    ----------
    filename : str
      The filename of the output fits file
    alms : array, complex or list of arrays
      A complex ndarray holding the alms, index = m*(2*lmax+1-m)/2+l, see Alm.getidx
    lmax : int, optional
      The maximum l in the output file
    mmax : int, optional
      The maximum m in the output file
    out_dtype : data type, optional
      data type in the output file (must be a numpy dtype). Default: *alms*.real.dtype
    mmax_in : int, optional
      maximum m in the input array
Write alms to a fits file.
Write alms to a fits file .
def write_alm(
    filename, alms, out_dtype=None, lmax=-1, mmax=-1, mmax_in=-1, overwrite=False
):
    """Write alms to a fits file.

    In the fits file the alms are written
    with explicit index scheme, index = l*l + l + m +1, possibly out of order.
    By default write_alm makes a table with the same precision as the alms.
    If specified, the lmax and mmax parameters truncate the input data to
    include only alms for which l <= lmax and m <= mmax.

    Parameters
    ----------
    filename : str
      The filename of the output fits file
    alms : array, complex or list of arrays
      A complex ndarray holding the alms, index = m*(2*lmax+1-m)/2+l, see Alm.getidx
    lmax : int, optional
      The maximum l in the output file
    mmax : int, optional
      The maximum m in the output file
    out_dtype : data type, optional
      data type in the output file (must be a numpy dtype). Default: *alms*.real.dtype
    mmax_in : int, optional
      maximum m in the input array
    """

    if not cb.is_seq_of_seq(alms):
        alms = [alms]

    l2max = Alm.getlmax(len(alms[0]), mmax=mmax_in)
    if lmax != -1 and lmax > l2max:
        raise ValueError("Too big lmax in parameter")
    elif lmax == -1:
        lmax = l2max

    if mmax_in == -1:
        mmax_in = l2max

    if mmax == -1:
        mmax = lmax
    if mmax > mmax_in:
        mmax = mmax_in

    if out_dtype is None:
        out_dtype = alms[0].real.dtype

    l, m = Alm.getlm(lmax)
    idx = np.where((l <= lmax) * (m <= mmax))
    l = l[idx]
    m = m[idx]

    idx_in_original = Alm.getidx(l2max, l=l, m=m)

    index = l ** 2 + l + m + 1

    hdulist = pf.HDUList()
    for alm in alms:
        out_data = np.empty(
            len(index), dtype=[("index", "i"), ("real", out_dtype), ("imag", out_dtype)]
        )
        out_data["index"] = index
        out_data["real"] = alm.real[idx_in_original]
        out_data["imag"] = alm.imag[idx_in_original]

        cindex = pf.Column(
            name="index",
            format=getformat(np.int32),
            unit="l*l+l+m+1",
            array=out_data["index"],
        )
        creal = pf.Column(
            name="real",
            format=getformat(out_dtype),
            unit="unknown",
            array=out_data["real"],
        )
        cimag = pf.Column(
            name="imag",
            format=getformat(out_dtype),
            unit="unknown",
            array=out_data["imag"],
        )

        tbhdu = pf.BinTableHDU.from_columns([cindex, creal, cimag])
        hdulist.append(tbhdu)
    # Add str to convert pathlib.Path into str
    # Due to https://github.com/astropy/astropy/issues/10594
    hdulist.writeto(str(filename), overwrite=overwrite)
def write_alm ( filename , alms , out_dtype = None , lmax = - 1 , mmax = - 1 , mmax_in = - 1 , overwrite = False ) : if not cb . is_seq_of_seq ( alms ) : alms = [ alms ] l2max = Alm . getlmax ( len ( alms [ 0 ] ) , mmax = mmax_in ) if lmax != - 1 and lmax > l2max : raise ValueError ( "Too big lmax in parameter" ) elif lmax == - 1 : lmax = l2max if mmax_in == - 1 : mmax_in = l2max if mmax == - 1 : mmax = lmax if mmax > mmax_in : mmax = mmax_in if out_dtype is None : out_dtype = alms [ 0 ] . real . dtype l , m = Alm . getlm ( lmax ) idx = np . where ( ( l <= lmax ) * ( m <= mmax ) ) l = l [ idx ] m = m [ idx ] idx_in_original = Alm . getidx ( l2max , l = l , m = m ) index = l ** 2 + l + m + 1 hdulist = pf . HDUList ( ) for alm in alms : out_data = np . empty ( len ( index ) , dtype = [ ( "index" , "i" ) , ( "real" , out_dtype ) , ( "imag" , out_dtype ) ] ) out_data [ "index" ] = index out_data [ "real" ] = alm . real [ idx_in_original ] out_data [ "imag" ] = alm . imag [ idx_in_original ] cindex = pf . Column ( name = "index" , format = getformat ( np . int32 ) , unit = "l*l+l+m+1" , array = out_data [ "index" ] , ) creal = pf . Column ( name = "real" , format = getformat ( out_dtype ) , unit = "unknown" , array = out_data [ "real" ] , ) cimag = pf . Column ( name = "imag" , format = getformat ( out_dtype ) , unit = "unknown" , array = out_data [ "imag" ] , ) tbhdu = pf . BinTableHDU . from_columns ( [ cindex , creal , cimag ] ) hdulist . append ( tbhdu ) # Add str to convert pathlib.Path into str # Due to https://github.com/astropy/astropy/issues/10594 hdulist . writeto ( str ( filename ) , overwrite = overwrite )