# Pixel corners and edges¶

In some cases, you may need to find out the longitude/latitude or celestial coordinates of the corners or edges of HEALPix pixels.

The `boundaries_lonlat()` method can be used to sample points long the edge of one or more HEALPix pixels:

```>>> from astropy_healpix import HEALPix
>>> hp = HEALPix(nside=16, order='nested')
>>> hp.boundaries_lonlat(, step=1)
(<Longitude [[ 1.17809725, 1.08747438, 1.12199738, 1.20830487]] rad>, <Latitude [[ 0.94842784, 0.89458259, 0.84022258, 0.89458259]] rad>)
```

This method takes a `step` argument which specifies how many points to sample along each edge. Setting `step` to 1 returns the corner positions, while setting e.g. 2 returns the corners and points along the middle of each edge, and larger values can be used to get the precise curved edges of the pixels.

The following example shows the difference between the boundary constructed from just the corners (in red) and a much higher-resolution boundary computed with 100 steps on each side (in black):

```import numpy as np
from astropy import units as u
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from astropy_healpix.core import boundaries_lonlat

ax = plt.subplot(1, 1, 1)

for step, color in [(1, 'red'), (100, 'black')]:
lon, lat = boundaries_lonlat(, nside=1, step=step)
lon = lon.to(u.deg).value
lat = lat.to(u.deg).value
vertices = np.vstack([lon.ravel(), lat.ravel()]).transpose()
p = Polygon(vertices, closed=True, edgecolor=color, facecolor='none')

plt.xlim(210, 330)
plt.ylim(-50, 50)
```

As for other methods, the `HEALPix` class has an equivalent `boundaries_skycoord()` method that can return the celestial coordinates of the boundaries as a `SkyCoord` object if the `frame` is set:

```>>> from astropy.coordinates import Galactic
>>> hp = HEALPix(nside=16, order='nested', frame=Galactic())
>>> hp.boundaries_skycoord(, step=1)
<SkyCoord (Galactic): (l, b) in deg
[[( 67.5       ,  54.3409123 ), ( 62.30769231,  51.25580695),
( 64.28571429,  48.14120779), ( 69.23076923,  51.25580695)]]>
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.65774125,"math_prob":0.9774001,"size":2075,"snap":"2023-14-2023-23","text_gpt3_token_len":606,"char_repetition_ratio":0.107194595,"word_repetition_ratio":0.0,"special_character_ratio":0.33927712,"punctuation_ratio":0.21291865,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99293727,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-02T15:01:55Z\",\"WARC-Record-ID\":\"<urn:uuid:ddb70b3b-928c-459e-bdef-ecc337bbf26a>\",\"Content-Length\":\"15713\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:928fae89-05fe-42d0-8bf2-a105388da88d>\",\"WARC-Concurrent-To\":\"<urn:uuid:c6767841-fc53-4b3c-9431-248e737a6ba9>\",\"WARC-IP-Address\":\"104.17.32.82\",\"WARC-Target-URI\":\"https://astropy-healpix.readthedocs.io/en/latest/boundaries.html\",\"WARC-Payload-Digest\":\"sha1:DCEFXMAZIENIT57KMI3CJKOBUB34YMYG\",\"WARC-Block-Digest\":\"sha1:7WXP4NFH67Z2DXIE4ENV4FSHCHEQ2W7A\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224648695.4_warc_CC-MAIN-20230602140602-20230602170602-00010.warc.gz\"}"}