| 1 |
Pixel corners and edges |
| 2 |
======================= |
| 3 |
|
| 4 |
In some cases, you may need to find out the longitude/latitude or celestial |
| 5 |
coordinates of the corners or edges of HEALPix pixels. |
| 6 |
|
| 7 |
The :meth:`~astropy_healpix.HEALPix.boundaries_lonlat` method can be used to |
| 8 |
sample points long the edge of one or more HEALPix pixels:: |
| 9 |
|
| 10 |
>>> from astropy_healpix import HEALPix |
| 11 |
>>> hp = HEALPix(nside=16, order='nested') |
| 12 |
>>> hp.boundaries_lonlat([120], step=1) # doctest: +FLOAT_CMP |
| 13 |
(<Longitude [[ 1.17809725, 1.08747438, 1.12199738, 1.20830487]] rad>, <Latitude [[ 0.94842784, 0.89458259, 0.84022258, 0.89458259]] rad>) |
| 14 |
|
| 15 |
This method takes a ``step`` argument which specifies how many points to sample |
| 16 |
along each edge. Setting ``step`` to 1 returns the corner positions, while |
| 17 |
setting e.g. 2 returns the corners and points along the middle of each edge, and |
| 18 |
larger values can be used to get the precise curved edges of the pixels. |
| 19 |
|
| 20 |
The following example shows the difference between the boundary constructed from |
| 21 |
just the corners (in red) and a much higher-resolution boundary computed with |
| 22 |
100 steps on each side (in black): |
| 23 |
|
| 24 |
.. plot:: |
| 25 |
:include-source: |
| 26 |
|
| 27 |
import numpy as np |
| 28 |
from astropy import units as u |
| 29 |
import matplotlib.pyplot as plt |
| 30 |
from matplotlib.patches import Polygon |
| 31 |
from astropy_healpix.core import boundaries_lonlat |
| 32 |
|
| 33 |
ax = plt.subplot(1, 1, 1) |
| 34 |
|
| 35 |
for step, color in [(1, 'red'), (100, 'black')]: |
| 36 |
lon, lat = boundaries_lonlat([7], nside=1, step=step) |
| 37 |
lon = lon.to(u.deg).value |
| 38 |
lat = lat.to(u.deg).value |
| 39 |
vertices = np.vstack([lon.ravel(), lat.ravel()]).transpose() |
| 40 |
p = Polygon(vertices, closed=True, edgecolor=color, facecolor='none') |
| 41 |
ax.add_patch(p) |
| 42 |
|
| 43 |
plt.xlim(210, 330) |
| 44 |
plt.ylim(-50, 50) |
| 45 |
|
| 46 |
As for other methods, the :class:`~astropy_healpix.HEALPix` class has an |
| 47 |
equivalent :meth:`~astropy_healpix.HEALPix.boundaries_skycoord` method that can |
| 48 |
return the celestial coordinates of the boundaries as a |
| 49 |
:class:`~astropy.coordinates.SkyCoord` object if the ``frame`` is set:: |
| 50 |
|
| 51 |
>>> from astropy.coordinates import Galactic |
| 52 |
>>> hp = HEALPix(nside=16, order='nested', frame=Galactic()) |
| 53 |
>>> hp.boundaries_skycoord([120], step=1) # doctest: +FLOAT_CMP |
| 54 |
<SkyCoord (Galactic): (l, b) in deg |
| 55 |
[[( 67.5 , 54.3409123 ), ( 62.30769231, 51.25580695), |
| 56 |
( 64.28571429, 48.14120779), ( 69.23076923, 51.25580695)]]> |