本文整理汇总了Python中healpy.ang2pix方法的典型用法代码示例。如果您正苦于以下问题:Python healpy.ang2pix方法的具体用法?Python healpy.ang2pix怎么用?Python healpy.ang2pix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类healpy
的用法示例。
在下文中一共展示了healpy.ang2pix方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeHealpixMap
# 需要导入模块: import healpy [as 别名]
# 或者: from healpy import ang2pix [as 别名]
def makeHealpixMap(ra, dec, nside=1024, nest=False):
# convert a ra/dec catalog into healpix map with counts per cell
import healpy as hp
ipix = hp.ang2pix(nside, (90-dec)/180*np.pi, ra/180*np.pi, nest=nest)
return np.bincount(ipix, minlength=hp.nside2npix(nside))
示例2: __call__
# 需要导入模块: import healpy [as 别名]
# 或者: from healpy import ang2pix [as 别名]
def __call__(self,j,jk,ra,dec):
"""
NAME:
__call__
PURPOSE:
Evaluate the selection function for multiple (J,J-Ks)
and single (RA,Dec)
INPUT:
j - apparent J magnitude
jk - J-Ks color
ra, dec - sky coordinates (deg)
OUTPUT
selection fraction
HISTORY:
2017-01-18 - Written - Bovy (UofT/CCA)
"""
# Parse j, jk
if isinstance(j,float):
j= numpy.array([j])
if isinstance(jk,float):
jk= numpy.array([jk])
# Parse RA, Dec
theta= numpy.pi/180.*(90.-dec)
phi= numpy.pi/180.*ra
pix= healpy.ang2pix(_BASE_NSIDE,theta,phi,nest=True)
if self._exclude_mask_skyonly[pix]:
return numpy.zeros_like(j)
jkbin= numpy.floor((jk-self._jkmin)\
/(self._jkmax-self._jkmin)*3.).astype('int')
tjt= jt(jk,j)
out= numpy.zeros_like(j)
for ii in range(3):
out[jkbin == ii]= self._sf_splines[ii](tjt[jkbin == ii])
out[out < 0.]= 0.
out[(j < self._jmin)+(j > self._jmax)]= 0.
return out
示例3: getCountAtLocations
# 需要导入模块: import healpy [as 别名]
# 或者: from healpy import ang2pix [as 别名]
def getCountAtLocations(ra, dec, nside=512, per_area=True, return_vertices=False):
"""Get number density of objects from RA/Dec in HealPix cells.
Args:
ra: list of rectascensions
dec: list of declinations
nside: HealPix nside
per_area: return counts in units of 1/arcmin^2
return_vertices: whether to also return the boundaries of HealPix cells
Returns:
bc, ra_, dec_, [vertices]
bc: count of objects in a HealPix cell if count > 0
ra_: rectascension of the cell center (same format as ra/dec)
dec_: declinations of the cell center (same format as ra/dec)
vertices: (N,4,2), RA/Dec coordinates of 4 boundary points of cell
"""
import healpy as hp
# get healpix pixels
ipix = hp.ang2pix(nside, (90-dec)/180*np.pi, ra/180*np.pi, nest=False)
# count how often each pixel is hit
bc = np.bincount(ipix)
pixels = np.nonzero(bc)[0]
bc = bc[bc>0]
if per_area:
bc = bc.astype('f8')
bc /= hp.nside2resol(nside, arcmin=True)**2 # in arcmin^-2
# get position of each pixel in RA/Dec
theta, phi = hp.pix2ang(nside, pixels, nest=False)
ra_ = phi*180/np.pi
dec_ = 90 - theta*180/np.pi
# get the vertices that confine each pixel
# convert to RA/Dec (thanks to Eric Huff)
if return_vertices:
vertices = getHealpixVertices(pixels, nside)
return bc, ra_, dec_, vertices
return bc, ra_, dec_
示例4: reduceAtLocations
# 需要导入模块: import healpy [as 别名]
# 或者: from healpy import ang2pix [as 别名]
def reduceAtLocations(ra, dec, value, reduce_fct=np.mean, nside=512, return_vertices=False):
"""Reduce values at given RA/Dec in HealPix cells to a scalar.
Args:
ra: list of rectascensions
dec: list of declinations
value: list of values to be reduced
reduce_fct: function to operate on values in each cell
nside: HealPix nside
per_area: return counts in units of 1/arcmin^2
return_vertices: whether to also return the boundaries of HealPix cells
Returns:
v, ra_, dec_, [vertices]
v: reduction of values in a HealPix cell if count > 0
ra_: rectascension of the cell center (same format as ra/dec)
dec_: declinations of the cell center (same format as ra/dec)
vertices: (N,4,2), RA/Dec coordinates of 4 boundary points of cell
"""
import healpy as hp
# get healpix pixels
ipix = hp.ang2pix(nside, (90-dec)/180*np.pi, ra/180*np.pi, nest=False)
# count how often each pixel is hit, only use non-empty pixels
pixels = np.nonzero(np.bincount(ipix))[0]
v = np.empty(pixels.size)
for i in xrange(pixels.size):
sel = (ipix == pixels[i])
v[i] = reduce_fct(value[sel])
# get position of each pixel in RA/Dec
theta, phi = hp.pix2ang(nside, pixels, nest=False)
ra_ = phi*180/np.pi
dec_ = 90 - theta*180/np.pi
# get the vertices that confine each pixel
# convert to RA/Dec (thanks to Eric Huff)
if return_vertices:
vertices = getHealpixVertices(pixels, nside)
return v, ra_, dec_, vertices
return v, ra_, dec_
示例5: sky_within
# 需要导入模块: import healpy [as 别名]
# 或者: from healpy import ang2pix [as 别名]
def sky_within(self, ra, dec, degin=False):
"""
Test whether a sky position is within this region
Parameters
----------
ra, dec : float
Sky position.
degin : bool
If True the ra/dec is interpreted as degrees, otherwise as radians.
Default = False.
Returns
-------
within : bool
True if the given position is within one of the region's pixels.
"""
sky = self.radec2sky(ra, dec)
if degin:
sky = np.radians(sky)
theta_phi = self.sky2ang(sky)
# Set values that are nan to be zero and record a mask
mask = np.bitwise_not(np.logical_and.reduce(np.isfinite(theta_phi), axis=1))
theta_phi[mask, :] = 0
theta, phi = theta_phi.transpose()
pix = hp.ang2pix(2**self.maxdepth, theta, phi, nest=True)
pixelset = self.get_demoted()
result = np.in1d(pix, list(pixelset))
# apply the mask and set the shonky values to False
result[mask] = False
return result
示例6: radec2pix
# 需要导入模块: import healpy [as 别名]
# 或者: from healpy import ang2pix [as 别名]
def radec2pix(nside,ra,dec,nest=True):
_,__=np.pi/2-np.deg2rad(dec),np.deg2rad(ra)
return healpy.ang2pix(nside,_,__,nest=nest)
示例7: array2healpix
# 需要导入模块: import healpy [as 别名]
# 或者: from healpy import ang2pix [as 别名]
def array2healpix(image_array, nside=16, max_iter=3, **kwargs):
"""Return a healpix ring-ordered map corresponding to a lat-lon map image array."""
if hp is None:
raise ImportError(
"Please install the `healpy` Python package to "
"enable this feature. See `https://healpy.readthedocs.io`."
)
# Starting value for the zoom
zoom = 2
# Keep track of the number of unseen pixels
unseen = 1
ntries = 0
while unseen > 0:
# Make the image bigger so we have good angular coverage
image_array = ndimage.zoom(image_array, zoom)
# Convert to a healpix map
theta = np.linspace(0, np.pi, image_array.shape[0])[:, None]
phi = np.linspace(-np.pi, np.pi, image_array.shape[1])[::-1]
pix = hp.ang2pix(nside, theta, phi, nest=False)
healpix_map = (
np.ones(hp.nside2npix(nside), dtype=np.float64) * hp.UNSEEN
)
healpix_map[pix] = image_array
# Count the unseen pixels
unseen = np.count_nonzero(healpix_map == hp.UNSEEN)
# Did we do this too many times?
ntries += 1
if ntries > max_iter:
raise ValueError(
"Maximum number of iterations exceeded. Either decreaser `nside` or increase `max_iter`."
)
return healpix_map