22"""Utilities for interfacing with hpgeom. Originally implemented in
23http://github.com/LSSTDESC/dia_pipe and then translated to hpgeom.
26__all__ = [
"toIndex",
"toRaDec",
"eq2xyz",
"eq2xyzVec",
"convert_spherical",
27 "convert_spherical_array",
"query_disc"]
33def toIndex(nside, ra, dec):
34 """Return healpix index given ra, dec in degrees
39 Power of 2 nside healpix resolution.
43 Declination
in degrees
48 Unique healpix pixel ID containing point RA, DEC at resolution nside.
50 return hpg.angle_to_pixel(nside, ra, dec, nest=
False)
54 """Convert from healpix index to ra,dec in degrees
59 Resolution of healpixel "grid".
61 Index of the healpix pixel we want to find the location of.
65 pos : `numpy.ndarray`, (2,)
66 RA
and DEC of healpix pixel location
in degrees.
68 ra, dec = hpg.pixel_to_angle(nside, index, nest=False)
69 return np.dstack((ra, dec))[0]
73 """Convert from equatorial ra,dec in degrees to x,y,z on unit sphere.
80 Declination
in degrees
84 xyz : `numpy.ndarray`, (3,)
85 Float xyz positions on the unit sphere.
88 theta = np.pi/2 - np.deg2rad(dec)
89 sintheta = np.sin(theta)
90 x = sintheta*np.cos(phi)
91 y = sintheta*np.sin(phi)
93 return np.array([x, y, z])
97 """Convert equatorial ra,dec in degrees to x,y,z on the unit sphere
100 Vectorized version of ``eq2xyz``
104 ra : array_like, (N,)
105 Array of RA in degrees.
106 dec : array_like, (N,)
107 Declination
in degrees
111 vec : `numpy.ndarray`, (N,3)
112 Array of unitsphere 3-vectors.
114 ra = np.array(ra, dtype='f8', ndmin=1, copy=
False)
115 dec = np.array(dec, dtype=
'f8', ndmin=1, copy=
False)
116 if ra.size != dec.size:
117 raise ValueError(
"ra,dec not same size: %s,%s" % (ra.size, dec.size))
119 vec = eq2xyz(ra, dec)
125 """Convert from ra,dec to spherical coordinates.
134 Declination
in radians
136 return np.dstack([np.cos(dec*np.pi/180)*np.cos(ra*np.pi/180),
137 np.cos(dec*np.pi/180)*np.sin(ra*np.pi/180),
138 np.sin(dec*np.pi/180)])[0]
142 """Convert from and a array ra,dec to spherical coordinates.
148 array : `numpy.ndarray`, (N, 2)
149 (N, 2) Array of RA, DEC values.
153 vecs : `numpy.ndarray`, (N, 3)
154 Vectors on the unit sphere
161def query_disc(nside, ra, dec, max_rad, min_rad=0):
162 """Get the list of healpix indices within max_rad, min_rad given in radians
163 around ra,dec given in degrees
168 Resolution of the healpixels to search/
return.
172 Declination
in degrees
174 Max distance
in radians to search nearby healpixels.
175 min_rad : `float`, optional
176 Minimum distance
in radians to search healpixels. Default = 0.
178 ra = np.atleast_1d(ra)
179 dec = np.atleast_1d(dec)
181 max_rad_deg = np.rad2deg(max_rad)
184 [hpg.query_circle(nside, a, b, max_rad_deg, nest=False)
185 for (a, b)
in zip(ra, dec)])
187 if min_rad > 0
and len(pixels) > 0:
189 min_rad2 = min_rad**2
191 dsq = np.sum((vecs - vec0)**2, axis=1)
192 match = dsq > min_rad2
193 pixels = pixels[match]
def toRaDec(nside, index)
def convert_spherical(ra, dec)
def convert_spherical_array(array)