23"""Utilities for interfacing with hpgeom. Originally implemented in
24http://github.com/LSSTDESC/dia_pipe and then translated to hpgeom.
31def toIndex(nside, ra, dec):
32 """Return healpix index given ra, dec in degrees
37 Power of 2 nside healpix resolution.
41 Declination
in degrees
46 Unique healpix pixel ID containing point RA, DEC at resolution nside.
48 return hpg.angle_to_pixel(nside, ra, dec, nest=
False)
52 """Convert from healpix index to ra,dec in degrees
57 Resolution of healpixel "grid".
59 Index of the healpix pixel we want to find the location of.
63 pos : `numpy.ndarray`, (2,)
64 RA
and DEC of healpix pixel location
in degrees.
66 ra, dec = hpg.pixel_to_angle(nside, index, nest=False)
67 return np.dstack((ra, dec))[0]
71 """Convert from equatorial ra,dec in degrees to x,y,z on unit sphere.
78 Declination
in degrees
82 xyz : `numpy.ndarray`, (3,)
83 Float xyz positions on the unit sphere.
86 theta = np.pi/2 - np.deg2rad(dec)
87 sintheta = np.sin(theta)
88 x = sintheta*np.cos(phi)
89 y = sintheta*np.sin(phi)
91 return np.array([x, y, z])
95 """Convert equatorial ra,dec in degrees to x,y,z on the unit sphere
98 Vectorized version of ``eq2xyz``
102 ra : array_like, (N,)
103 Array of RA in degrees.
104 dec : array_like, (N,)
105 Declination
in degrees
109 vec : `numpy.ndarray`, (N,3)
110 Array of unitsphere 3-vectors.
112 ra = np.array(ra, dtype='f8', ndmin=1, copy=
False)
113 dec = np.array(dec, dtype=
'f8', ndmin=1, copy=
False)
114 if ra.size != dec.size:
115 raise ValueError(
"ra,dec not same size: %s,%s" % (ra.size, dec.size))
117 vec = eq2xyz(ra, dec)
123 """Convert from ra,dec to spherical coordinates.
132 Declination
in radians
134 return np.dstack([np.cos(dec*np.pi/180)*np.cos(ra*np.pi/180),
135 np.cos(dec*np.pi/180)*np.sin(ra*np.pi/180),
136 np.sin(dec*np.pi/180)])[0]
140 """Convert from and a array ra,dec to spherical coordinates.
146 array : `numpy.ndarray`, (N, 2)
147 (N, 2) Array of RA, DEC values.
151 vecs : `numpy.ndarray`, (N, 3)
152 Vectors on the unit sphere
159def query_disc(nside, ra, dec, max_rad, min_rad=0):
160 """Get the list of healpix indices within max_rad, min_rad given in radians
161 around ra,dec given in degrees
166 Resolution of the healpixels to search/
return.
170 Declination
in degrees
172 Max distance
in radians to search nearby healpixels.
173 min_rad : `float`, optional
174 Minimum distance
in radians to search healpixels. Default = 0.
176 ra = np.atleast_1d(ra)
177 dec = np.atleast_1d(dec)
179 max_rad_deg = np.rad2deg(max_rad)
182 [hpg.query_circle(nside, a, b, max_rad_deg, nest=False)
183 for (a, b)
in zip(ra, dec)])
185 if min_rad > 0
and len(pixels) > 0:
187 min_rad2 = min_rad**2
189 dsq = np.sum((vecs - vec0)**2, axis=1)
190 match = dsq > min_rad2
191 pixels = pixels[match]
def toRaDec(nside, index)
def convert_spherical(ra, dec)
def convert_spherical_array(array)