コード例 #1
0
ファイル: pixelfunc.py プロジェクト: PaulPrice/healpy
def get_neighbours(nside,theta,phi=None,nest=False):
    """Return the 4 nearest pixels and corresponding weights.

    Parameters
    ----------
    nside : int
      the healpix nside
    theta, phi : float, scalar or array-like
      if phi is not given, theta is interpreted as pixel number,
      otherwise theta[rad],phi[rad] are angular coordinates
    nest : bool
      if ``True``, NESTED ordering, otherwise RING ordering.

    Returns
    -------
    res : tuple of length 2
      contains pixel numbers in res[0] and weights in res[1].
      Usual numpy broadcasting rules apply.

    See Also
    --------
    get_interp_val, get_all_neighbours

    Examples
    --------
    >>> import healpy as hp
    >>> hp.get_neighbours(1, 0)
    (array([0, 1, 4, 5]), array([ 1.,  0.,  0.,  0.]))

    >>> hp.get_neighbours(1, 0, 0)
    (array([1, 2, 3, 0]), array([ 0.25,  0.25,  0.25,  0.25]))

    >>> hp.get_neighbours(1, [0, np.pi/2], 0)
    (array([[ 1,  4],
           [ 2,  5],
           [ 3, 11],
           [ 0,  8]]), array([[ 0.25,  1.  ],
           [ 0.25,  0.  ],
           [ 0.25,  0.  ],
           [ 0.25,  0.  ]]))
    """
    if not isnsideok(nside):
        raise ValueError('Wrong nside value. Must be a power of 2.')
    if phi == None:
        theta,phi = pix2ang(nside,theta,nest=nest)
    if nest:
        r=pixlib._get_interpol_nest(nside,theta,phi)
    else:
        r=pixlib._get_interpol_ring(nside,theta,phi)
    p=np.array(r[0:4])
    w=np.array(r[4:8])
    return (p,w)
コード例 #2
0
ファイル: pixelfunc.py プロジェクト: dhanson/healpy
def get_neighbours(nside,theta,phi=None,nest=False):
    """Return the 4 nearest pixels and corresponding weights.

    Parameters
    ----------
    nside : int
      the healpix nside
    theta, phi : float, scalar or array-like
      if phi is not given, theta is interpreted as pixel number,
      otherwise theta[rad],phi[rad] are angular coordinates
    nest : bool
      if ``True``, NESTED ordering, otherwise RING ordering.

    Returns
    -------
    res : tuple of length 2
      contains pixel numbers in res[0] and weights in res[1].
      Usual numpy broadcasting rules apply.

    See Also
    --------
    get_interp_val, get_all_neighbours

    Examples
    --------
    >>> import healpy as hpy
    >>> hpy.get_neighbours(1, 0)
    (array([0, 1, 4, 5]), array([ 1.,  0.,  0.,  0.]))

    >>> hpy.get_neighbours(1, 0, 0)
    (array([1, 2, 3, 0]), array([ 0.25,  0.25,  0.25,  0.25]))

    >>> hpy.get_neighbours(1, [0, npy.pi/2], 0)
    (array([[ 1,  4],
           [ 2,  5],
           [ 3, 11],
           [ 0,  8]]), array([[ 0.25,  1.  ],
           [ 0.25,  0.  ],
           [ 0.25,  0.  ],
           [ 0.25,  0.  ]]))
    """
    if not isnsideok(nside):
        raise ValueError('Wrong nside value. Must be a power of 2.')
    if phi == None:
        theta,phi = pix2ang(nside,theta,nest=nest)
    if nest:
        r=pixlib._get_interpol_nest(nside,theta,phi)
    else:
        r=pixlib._get_interpol_ring(nside,theta,phi)
    p=npy.array(r[0:4])
    w=npy.array(r[4:8])
    return (p,w)
コード例 #3
0
ファイル: pixelfunc.py プロジェクト: Alwnikrotikz/healpy
def get_interp_val(m,theta,phi,nest=False):
    """Return the bi-linear interpolation value of a map at given direction.

    Input:
      - m: a map (an ndarray)
      - theta, phi : the direction [rad] (either scalar or arrays of same size)
    Parameters:
      - nest: if True, the map is in NEST scheme. Default: False (ie RING)
    Return:
      - the interpolated value(s)
    """
    m2=m.ravel()
    nside=npix2nside(m2.size)
    if nest:
        r=pixlib._get_interpol_nest(nside,theta,phi)
    else:
        r=pixlib._get_interpol_ring(nside,theta,phi)
    p=npy.array(r[0:4])
    w=npy.array(r[4:8])
    del r
    return npy.sum(m2[p]*w,0)
コード例 #4
0
def get_interp_val(m, theta, phi, nest=False):
    """Return the bi-linear interpolation value of a map at given direction.

    Input:
      - m: a map (an ndarray)
      - theta, phi : the direction [rad] (either scalar or arrays of same size)
    Parameters:
      - nest: if True, the map is in NEST scheme. Default: False (ie RING)
    Return:
      - the interpolated value(s)
    """
    m2 = m.ravel()
    nside = npix2nside(m2.size)
    if nest:
        r = pixlib._get_interpol_nest(nside, theta, phi)
    else:
        r = pixlib._get_interpol_ring(nside, theta, phi)
    p = npy.array(r[0:4])
    w = npy.array(r[4:8])
    del r
    return npy.sum(m2[p] * w, 0)
コード例 #5
0
ファイル: pixelfunc.py プロジェクト: jrs65/healpy
def get_interp_val(m, theta, phi, nest=False):
    """Return the bi-linear interpolation value of a map using 4 nearest neighbours.

    Parameters
    ----------
    m : array-like
      an healpix map, accepts masked arrays
    theta, phi : float, scalar or array-like
      angular coordinates of point at which to interpolate the map
    nest : bool
      if True, the is assumed to be in NESTED ordering.

    Returns
    -------
      val : float, scalar or arry-like
        the interpolated value(s), usual numpy broadcasting rules apply.

    See Also
    --------
    get_neighbours, get_all_neighbours

    Examples
    --------
    >>> import healpy as hp
    >>> hp.get_interp_val(np.arange(12.), np.pi/2, 0)
    4.0
    >>> hp.get_interp_val(np.arange(12.), np.linspace(0, np.pi, 10), 0)
    array([ 1.5       ,  1.5       ,  1.5       ,  2.20618428,  3.40206143,
            5.31546486,  7.94639458,  9.5       ,  9.5       ,  9.5       ])
    """
    m2 = m.ravel()
    nside = npix2nside(m2.size)
    if nest:
        r = pixlib._get_interpol_nest(nside, theta, phi)
    else:
        r = pixlib._get_interpol_ring(nside, theta, phi)
    p = np.array(r[0:4])
    w = np.array(r[4:8])
    del r
    return np.sum(m2[p] * w, 0)
コード例 #6
0
ファイル: pixelfunc.py プロジェクト: dhanson/healpy
def get_interp_val(m,theta,phi,nest=False):
    """Return the bi-linear interpolation value of a map using 4 nearest neighbours.

    Parameters
    ----------
    m : array-like
      an healpix map
    theta, phi : float, scalar or array-like
      angular coordinates of point at which to interpolate the map
    nest : bool
      if True, the is assumed to be in NESTED ordering.

    Returns
    -------
      val : float, scalar or arry-like
        the interpolated value(s), usual numpy broadcasting rules apply.

    See Also
    --------
    get_neighbours, get_all_neighbours

    Examples
    --------
    >>> import healpy as hpy
    >>> hpy.get_interp_val(npy.arange(12.), npy.pi/2, 0)
    4.0
    >>> hpy.get_interp_val(npy.arange(12.), npy.linspace(0, npy.pi, 10), 0)
    array([ 1.5       ,  1.5       ,  1.5       ,  2.20618428,  3.40206143,
            5.31546486,  7.94639458,  9.5       ,  9.5       ,  9.5       ])
    """
    m2=m.ravel()
    nside=npix2nside(m2.size)
    if nest:
        r=pixlib._get_interpol_nest(nside,theta,phi)
    else:
        r=pixlib._get_interpol_ring(nside,theta,phi)
    p=npy.array(r[0:4])
    w=npy.array(r[4:8])
    del r
    return npy.sum(m2[p]*w,0)
コード例 #7
0
ファイル: pixelfunc.py プロジェクト: Alwnikrotikz/healpy
def get_neighbours(nside,theta,phi=None,nest=False):
    """Return the 4 nearest pixels and the corresponding weights for
    bi-linear interpolation for the given direction.

    Input:
      - nside: the nside to work with
      - theta, phi: if phi is not given, theta is actually a pixel number
                    if phi is given, theta[rad],phi[rad] is a direction
    Parameters:
      - nest: if True, NEST scheme. Default: False (RING)
    Return:
      - tuple of pixels and weights
    """
    if not isnsideok(nside):
        raise ValueError('Wrong nside value. Must be a power of 2.')
    if phi == None:
        theta,phi = pix2ang(nside,theta,nest=nest)
    if nest:
        r=pixlib._get_interpol_nest(nside,theta,phi)
    else:
        r=pixlib._get_interpol_ring(nside,theta,phi)
    p=npy.array(r[0:4])
    w=npy.array(r[4:8])
    return (p,w)
コード例 #8
0
def get_neighbours(nside, theta, phi=None, nest=False):
    """Return the 4 nearest pixels and the corresponding weights for
    bi-linear interpolation for the given direction.

    Input:
      - nside: the nside to work with
      - theta, phi: if phi is not given, theta is actually a pixel number
                    if phi is given, theta[rad],phi[rad] is a direction
    Parameters:
      - nest: if True, NEST scheme. Default: False (RING)
    Return:
      - tuple of pixels and weights
    """
    if not isnsideok(nside):
        raise ValueError('Wrong nside value. Must be a power of 2.')
    if phi == None:
        theta, phi = pix2ang(nside, theta, nest=nest)
    if nest:
        r = pixlib._get_interpol_nest(nside, theta, phi)
    else:
        r = pixlib._get_interpol_ring(nside, theta, phi)
    p = npy.array(r[0:4])
    w = npy.array(r[4:8])
    return (p, w)