コード例 #1
0
ファイル: sphtfunc.py プロジェクト: afarahi/XCat
def alm2map(alm, nside, lmax=-1, mmax=-1,pixwin=False,
            fwhm=0.0,sigma=None,degree=False,arcmin=False):
    """Computes an Healpix map given the alm.

    The alm are given as a complex array. You can specify lmax
    and mmax, or they will be computed from array size (assuming
    lmax==mmax).

    Parameters:
    - alm: a complex array of alm. Size must be of the form
           size=mmax(lmax-mmax+1)/2+lmax
    - nside: the nside of the output map.
    - lmax: explicitly define lmax (needed if mmax!=lmax)
    - mmax: explicitly define mmax (needed if mmax!=lmax)
    - fwhm, sigma, degree and arcmin (as in smoothalm): smooth by a Gaussian
      symmetric beam

    Return: an Healpix map in RING scheme at nside.
    """
    smoothalm(alm,fwhm=fwhm,sigma=sigma,degree=degree,arcmin=arcmin)
    if pixwin:
        pw=globals()['pixwin'](nside,True)
        if type(alm[0]) is npy.ndarray:
            if len(alm) != 3:
                raise TypeError("alm must be a sequence of 3 ndarray "
                                "or a 1D ndarray")
            alm[0] = almxfl(alm[0],pw[0],inplace=True)
            alm[1] = almxfl(alm[1],pw[1],inplace=True)
            alm[2] = almxfl(alm[2],pw[1],inplace=True)
        else:
            alm = almxfl(alm,pw[0],inplace=True)
    return sphtlib._alm2map(alm,nside,lmax=lmax,mmax=mmax)
コード例 #2
0
def alm2map(alm,
            nside,
            lmax=-1,
            mmax=-1,
            pixwin=False,
            fwhm=0.0,
            sigma=None,
            degree=False,
            arcmin=False):
    """Computes an Healpix map given the alm.

    The alm are given as a complex array. You can specify lmax
    and mmax, or they will be computed from array size (assuming
    lmax==mmax).

    Parameters
    ----------
    alm : complex, array
      A complex array of alm. Size must be of the form mmax*(lmax-mmax+1)/2+lmax
    nside : int, scalar
      The nside of the output map.
    lmax : int, scalar, optional
      Explicitly define lmax (needed if mmax!=lmax)
    mmax : int, scalar, optional
      Explicitly define mmax (needed if mmax!=lmax)
    fwhm : float, scalar, optional
      The fwhm of the Gaussian used to smooth the map (applied on alm)
    sigma : float, scalar, optional
      The sigma of the Gaussian used to smooth the map (applied on alm)
    degree : bool, scalar, optional
      If True, unit of sigma or fwhm is degree, otherwise it is radian
    arcmin : bool, scalar, optional
      If True, unit of sigma or fwhm is arcmin, otherwise it is radian

    Returns
    -------
    map : array or list of arrays
      An Healpix map in RING scheme at nside or a list of T,Q,U maps (if
      polarized input)
    """
    smoothalm(alm, fwhm=fwhm, sigma=sigma, degree=degree, arcmin=arcmin)
    if pixwin:
        pw = globals()['pixwin'](nside, True)
        if type(alm[0]) is npy.ndarray:
            if len(alm) != 3:
                raise TypeError("alm must be a sequence of 3 ndarray "
                                "or a 1D ndarray")
            alm[0] = almxfl(alm[0], pw[0], inplace=True)
            alm[1] = almxfl(alm[1], pw[1], inplace=True)
            alm[2] = almxfl(alm[2], pw[1], inplace=True)
        else:
            alm = almxfl(alm, pw[0], inplace=True)
    return sphtlib._alm2map(alm, nside, lmax=lmax, mmax=mmax)
コード例 #3
0
ファイル: sphtfunc.py プロジェクト: dhanson/healpy
def alm2map(alm, nside, lmax=-1, mmax=-1,pixwin=False,
            fwhm=0.0,sigma=None,degree=False,arcmin=False):
    """Computes an Healpix map given the alm.

    The alm are given as a complex array. You can specify lmax
    and mmax, or they will be computed from array size (assuming
    lmax==mmax).

    Parameters
    ----------
    alm : complex, array
      A complex array of alm. Size must be of the form mmax*(lmax-mmax+1)/2+lmax
    nside : int, scalar
      The nside of the output map.
    lmax : int, scalar, optional
      Explicitly define lmax (needed if mmax!=lmax)
    mmax : int, scalar, optional
      Explicitly define mmax (needed if mmax!=lmax)
    fwhm : float, scalar, optional
      The fwhm of the Gaussian used to smooth the map (applied on alm)
    sigma : float, scalar, optional
      The sigma of the Gaussian used to smooth the map (applied on alm)
    degree : bool, scalar, optional
      If True, unit of sigma or fwhm is degree, otherwise it is radian
    arcmin : bool, scalar, optional
      If True, unit of sigma or fwhm is arcmin, otherwise it is radian

    Returns
    -------
    map : array or list of arrays
      An Healpix map in RING scheme at nside or a list of T,Q,U maps (if
      polarized input)
    """
    smoothalm(alm,fwhm=fwhm,sigma=sigma,degree=degree,arcmin=arcmin)
    if pixwin:
        pw=globals()['pixwin'](nside,True)
        if type(alm[0]) is npy.ndarray:
            if len(alm) != 3:
                raise TypeError("alm must be a sequence of 3 ndarray "
                                "or a 1D ndarray")
            alm[0] = almxfl(alm[0],pw[0],inplace=True)
            alm[1] = almxfl(alm[1],pw[1],inplace=True)
            alm[2] = almxfl(alm[2],pw[1],inplace=True)
        else:
            alm = almxfl(alm,pw[0],inplace=True)
    return sphtlib._alm2map(alm,nside,lmax=lmax,mmax=mmax)
コード例 #4
0
def alm2map(alm,
            nside,
            lmax=-1,
            mmax=-1,
            pixwin=False,
            fwhm=0.0,
            sigma=None,
            degree=False,
            arcmin=False):
    """Computes an Healpix map given the alm.

    The alm are given as a complex array. You can specify lmax
    and mmax, or they will be computed from array size (assuming
    lmax==mmax).

    Parameters:
    - alm: a complex array of alm. Size must be of the form
           size=mmax(lmax-mmax+1)/2+lmax
    - nside: the nside of the output map.
    - lmax: explicitly define lmax (needed if mmax!=lmax)
    - mmax: explicitly define mmax (needed if mmax!=lmax)
    - fwhm, sigma, degree and arcmin (as in smoothalm): smooth by a Gaussian
      symmetric beam

    Return: an Healpix map in RING scheme at nside.
    """
    smoothalm(alm, fwhm=fwhm, sigma=sigma, degree=degree, arcmin=arcmin)
    if pixwin:
        pw = globals()['pixwin'](nside, True)
        if type(alm[0]) is npy.ndarray:
            if len(alm) != 3:
                raise TypeError("alm must be a sequence of 3 ndarray "
                                "or a 1D ndarray")
            alm[0] = almxfl(alm[0], pw[0], inplace=True)
            alm[1] = almxfl(alm[1], pw[1], inplace=True)
            alm[2] = almxfl(alm[2], pw[1], inplace=True)
        else:
            alm = almxfl(alm, pw[0], inplace=True)
    return sphtlib._alm2map(alm, nside, lmax=lmax, mmax=mmax)
コード例 #5
0
ファイル: sphtfunc.py プロジェクト: philbull/healpy
def alm2map(
    alms, nside, lmax=None, mmax=None, pixwin=False, fwhm=0.0, sigma=None, invert=False, pol=True, inplace=False
):
    """Computes an Healpix map given the alm.

    The alm are given as a complex array. You can specify lmax
    and mmax, or they will be computed from array size (assuming
    lmax==mmax).

    Parameters
    ----------
    alms : complex, array or sequence of arrays
      A complex array or a sequence of complex arrays.
      Each array must have a size of the form: mmax * (2 * lmax + 1 - mmax) / 2 + lmax + 1
    nside : int, scalar
      The nside of the output map.
    lmax : None or int, scalar, optional
      Explicitly define lmax (needed if mmax!=lmax)
    mmax : None or int, scalar, optional
      Explicitly define mmax (needed if mmax!=lmax)
    pixwin : bool, optional
      Smooth the alm using the pixel window functions. Default: False.
    fwhm : float, scalar, optional
      The fwhm of the Gaussian used to smooth the map (applied on alm)
      [in radians]
    sigma : float, scalar, optional
      The sigma of the Gaussian used to smooth the map (applied on alm)
      [in radians]
    invert : bool, optional
      If True, alms are divided by Gaussian beam function (un-smooth).
      Otherwise, alms are multiplied by Gaussian beam function (smooth).
      Default: False.
    pol : bool, optional
      If True, assumes input alms are TEB. Output will be TQU maps.
      (input must be 1 or 3 alms)
      If False, apply spin 0 harmonic transform to each alm.
      (input can be any number of alms)
      If there is only one input alm, it has no effect. Default: True.
    inplace : bool, optional
      If True, input alms may be modified by pixel window function and beam
      smoothing (if alm(s) are complex128 contiguous arrays).
      Otherwise, input alms are not modified. A copy is made if needed to
      apply beam smoothing or pixel window.
      
    Returns
    -------
    maps : array or list of arrays
      An Healpix map in RING scheme at nside or a list of T,Q,U maps (if
      polarized input)
    """
    if not cb.is_seq(alms):
        raise TypeError("alms must be a sequence")

    alms = smoothalm(alms, fwhm=fwhm, sigma=sigma, invert=invert, pol=pol, inplace=inplace)

    if not cb.is_seq_of_seq(alms):
        alms = [alms]
        lonely = True
    else:
        lonely = False

    if pixwin:
        pw = globals()["pixwin"](nside, True)
        alms_new = []
        for ialm, alm in enumerate(alms):
            pixelwindow = pw[1] if ialm >= 1 and pol else pw[0]
            alms_new.append(almxfl(alm, pixelwindow, inplace=inplace))
    else:
        alms_new = alms

    if lmax is None:
        lmax = -1
    if mmax is None:
        mmax = -1
    if pol:
        output = sphtlib._alm2map(alms_new[0] if lonely else alms_new, nside, lmax=lmax, mmax=mmax)
        if lonely:
            output = [output]
    else:
        output = [sphtlib._alm2map(alm, nside, lmax=lmax, mmax=mmax) for alm in alms_new]
    if lonely:
        return output[0]
    else:
        return output
コード例 #6
0
ファイル: sphtfunc.py プロジェクト: rainwoodman/healpy
def alm2map(alms, nside, lmax = None, mmax = None, pixwin = False,
            fwhm = 0.0, sigma = None, invert = False, pol = True,
            inplace = False):
    """Computes an Healpix map given the alm.

    The alm are given as a complex array. You can specify lmax
    and mmax, or they will be computed from array size (assuming
    lmax==mmax).

    Parameters
    ----------
    alms : complex, array or sequence of arrays
      A complex array or a sequence of complex arrays.
      Each array must have a size of the form: mmax * (2 * lmax + 1 - mmax) / 2 + lmax + 1
    nside : int, scalar
      The nside of the output map.
    lmax : None or int, scalar, optional
      Explicitly define lmax (needed if mmax!=lmax)
    mmax : None or int, scalar, optional
      Explicitly define mmax (needed if mmax!=lmax)
    pixwin : bool, optional
      Smooth the alm using the pixel window functions. Default: False.
    fwhm : float, scalar, optional
      The fwhm of the Gaussian used to smooth the map (applied on alm)
      [in radians]
    sigma : float, scalar, optional
      The sigma of the Gaussian used to smooth the map (applied on alm)
      [in radians]
    invert : bool, optional
      If True, alms are divided by Gaussian beam function (un-smooth).
      Otherwise, alms are multiplied by Gaussian beam function (smooth).
      Default: False.
    pol : bool, optional
      If True, assumes input alms are TEB. Output will be TQU maps.
      (input must be 1 or 3 alms)
      If False, apply spin 0 harmonic transform to each alm.
      (input can be any number of alms)
      If there is only one input alm, it has no effect. Default: True.
    inplace : bool, optional
      If True, input alms may be modified by pixel window function and beam
      smoothing (if alm(s) are complex128 contiguous arrays).
      Otherwise, input alms are not modified. A copy is made if needed to
      apply beam smoothing or pixel window.
      
    Returns
    -------
    maps : array or list of arrays
      An Healpix map in RING scheme at nside or a list of T,Q,U maps (if
      polarized input)
    """
    if not cb.is_seq(alms):
        raise TypeError("alms must be a sequence")

    alms = smoothalm(alms, fwhm = fwhm, sigma = sigma, invert = invert, 
                     pol = pol, inplace = inplace)

    if not cb.is_seq_of_seq(alms):
        alms = [alms]
        lonely = True
    else:
        lonely = False
    
    if pixwin:
        pw = globals()['pixwin'](nside,True)
        alms_new = []
        for ialm, alm in enumerate(alms):
            pixelwindow = pw[1] if ialm >= 1 and pol else pw[0]
            alms_new.append(almxfl(alm, pixelwindow, inplace = inplace))
    else:
        alms_new = alms

    if lmax is None:
        lmax = -1
    if mmax is None:
        mmax = -1
    if pol:
        output = sphtlib._alm2map(alms_new[0] if lonely else alms_new,
                                  nside, lmax = lmax, mmax = mmax)
        if lonely:
            output = [output]
    else:
        output = [sphtlib._alm2map(alm, nside, lmax = lmax, mmax = mmax)
                  for alm in alms_new]
    if lonely:
        return output[0]
    else:
        return output