HEALPix is an interesting framework that can be used to store information about spherical surfaces in a digital format as pixels that have nice properties (hierarchical, equal-area and isolatitude), and it is used by NASA and SETI@home (among others). The detail of HEALPix is presented in a paper by Górski et al. (2005), which was published in The Astrophysical Journal and is titled “HEALPix: A Framework for High-Resolution Discretization and Fast Analysis of Data Distributed on the Sphere” (DOI:10.1086/427976). Despite being an excellent paper that is filled with mathematical info and descriptions, it seems like the authors ran out of steam as they got to Equation 18, since this equation apparently does not accurately reflect the general case for calculating the longitude index in the nested scheme of pixel indexing. The following describes a revised version of Equation 18, along with some additional comments. (Be sure to have a copy of the paper at hand — if you cannot download the original paper through the DOI link above, see the Harvard Astronomy Abstract Service for alternative links or visit arXiv:astro-ph/0409513.)

Having wrecked my brain on this, it seems that Equation 18 (on page 765) actually only describes the case for pixels in the equatorial zone. The general equation that describes the longitude index also for polar pixels needs to look slightly different, namely:

j = (F_{2} . n_{r} + h + s) / 2 ,

where n_{r} is introduced shortly and replaces the N_{side} constant in the published Equation 18. The variable n_{r} represents the number of pixels in one quadrant of a specific constant-latitude ring and is therefore a function of ring index i: for the north polar cap (where i < N_{side}) we have n_{r} = i, for the entire equatorial belt (where N_{side} <= i <= 3 . N_{side}) we use n_{r} = N_{side} (which again produces the original Equation 18 for this region), and for the south polar cap (where i > 3 . N_{side}) we need to define n_{r} = 4 . N_{side} - i (thus, using mirror symmetry with respect to the equator).

For verification purposes, nested pixel index 29 makes for a good test candidate along with N_{side} = 4, which is also conveniently illustrated in the bottom panel of Figure 4 (on page 764). For this case the pixel is thoroughly in the northern polar region and we have: p_{n} = 29, p_{n}' = 13, f = 1, f_{row} = 0, F_{1} = 2, F_{2} = 3, x = 3, y = 2, v = 5, h = 1, i = 2, s = 1, and z = cos(theta) = 11 / 12 = 0.9167. Using the original Equation 18, it incorrectly produces j = 7, resulting in phi / pi = 1.6250 when substituted into Equation 5. Visual inspection of Figure 4 shows that the phi / pi value should be somewhere between 0.75 and 1.0 for this pixel (considering the pixel’s boundaries), and, since this is the 4^{th} pixel in the second ring, the value of j should be somewhere in the region of 3 or 4, but not 7. Even if one were to attempt substituting j = 7 into Equation 9 (actually meant for the equatorial belt), this would still produce an incorrect result of phi / pi = 0.8125 (although it would be more in line with the expected range). But if one were to use the revised equation stated above for the north polar cap, we would get j = 4 that would result in phi / pi = 0.8750 from Equation 5 (which is also exactly in the center of our expected range). This last result is also the value returned by the reference implementation of the HEALPix software, version 2.12a (available from SourceForge).

A few minor points before I get to an interesting observation in the last section:

- This is really just a technicality, but on page 761 (roughly in the center of the right column) where it states “for odd and even values of N
_{theta}, respectively”, I suspect that the words “odd and even” should have been reversed (if I interpret this correctly).
- If you are wondering what the variables p and p
_{h} mean, which are used for the first time on page 763 above Equation 2 without introduction, this is how I have come to think of them: variable p is simply an integer pixel index that runs from 0 up to and including 12 . N_{side}^{2} - 1. The variable p_{h} can then be interpreted as the half-step-size pixel-index counterpart of p, which runs from 0.5 up to and including 6 . N_{side}^{2} in steps of half units. Furthermore, the p' variable is simply the equatorial pixel-index, starting at zero for the first pixel in the equatorial band. Also, although p is used to index pixels in a linear fashion, similar to the ring scheme, it is probably best not to interpret p as the ring-scheme index per se.
- Although the paper does not state this explicitly (and I was wondering about it as I got to the start of page 765), one can calculate the base-resolution pixel index number, f, from the nested index, p
_{n}, using f = I( p_{n} / N_{side}^{2} ), where I(x) represents the integer floor function as it does in the rest of the paper. This may be obvious, but it is nice to know for sure that you are using the right equation.

Finally, and I found this quite refreshing, if you want to calculate the longitude, phi, of a pixel center from its nested pixel index, p_{n}, you actually need not calculate either s or j to arrive at phi. Substitution of the revised Equation 18 into Equations 5 and 9 (for the different regions) produces a unified general equation that can be applied anywhere on the sphere:

phi = ( pi / 4 ) . ( F_{2} . n_{r} + h ) / n_{r} .

This last equation could likely be used to optimize some of the functions in the reference implementation of the HEALPix software; for example, one may eliminate calculations and usages of the internal variables named `kshift`

(the boolean complement of variable s) in the `pix2ang_nest`

functions of the C, Java, Fortran and IDL code, as well as the `pix2ang_z_phi`

implementation in C++, and possibly elsewhere.

## Comments

## Thanks

Thank you. I had been looking at equation (18) for a long time trying to figure out what was going on. You saved me a lot of hassle!