def index_pixels(lon,lat,pixels,nside):
"""
Find the index for object amoung a subset of healpix pixels.
Set index of objects outside the pixel subset to -1
# ADW: Not really safe to set index = -1 (accesses last entry);
# -np.inf would be better, but breaks other code...
"""
pix = ang2pix(nside,lon,lat)
# pixels should be pre-sorted, otherwise...???
index = np.searchsorted(pixels,pix)
if np.isscalar(index):
if not np.in1d(pix,pixels).any(): index = -1
else:
# Find objects that are outside the roi
#index[np.take(pixels,index,mode='clip')!=pix] = -1
index[~np.in1d(pix,pixels)] = -1
return index
############################################################
评论列表
文章目录