[](https://github.com/Joatin/realpix/actions/workflows/ci.yaml)
# REALPix
**`REALPix`** is a Rust crate providing a **HEALPix-style spherical pixelization**, supporting both **RING** and **NESTED** indexing schemes.
It is designed for **astronomy, astrometry, and fast spatial indexing on the sphere**, with a strong focus on **correctness, performance, and portability**.
---
## Features
* β
HEALPix-compatible pixelization
* π’ RING and NESTED indexing schemes
* π RA/Dec and ΞΈ/Ο support
* β‘ Fast angle β pixel conversion
* π§ Spatial locality with NESTED ordering
* π¦ Written in safe Rust
* π¦ **`std` enabled by default**
* π« Optional **`no_std`** support
---
## What is HEALPix?
HEALPix (**H**ierarchical **E**qual **A**rea **L**atitude **Pix**elization) divides the sphere into:
* **12 base faces**
* Each face subdivided into an **N Γ N grid**
* Total pixel count:
```
12 Γ NΒ²
```
All pixels cover **equal area** on the sphere.
---
## RING vs NESTED ordering
Both schemes describe the **same pixelization**, but differ in how pixels are **numbered**.
### RING ordering
Pixels are numbered in **latitude rings**, starting at the north pole and moving south.
```
North pole
[ 0 1 2 ]
[ 3 4 5 6 ]
[ 7 8 9 10 11 ]
...
South pole
```
**Characteristics:**
* Latitude-ordered
* Easy full-sky iteration
* Poor spatial locality
* Commonly used for spherical harmonics
---
### NESTED ordering
Pixels are numbered **hierarchically**, using a quad-tree structure on each face.
```
Base face
βββββββββ
β 0 β
βββββββββ
Level 1
βββββ¬ββββ
β 0 β 1 β
βββββΌββββ€
β 2 β 3 β
βββββ΄ββββ
Level 2
βββββ¬ββββ¬ββββ¬ββββ
β00 β01 β10 β11 β
βββββΌββββΌββββΌββββ€
β02 β03 β12 β13 β
βββββΌββββΌββββΌββββ€
β20 β21 β30 β31 β
βββββΌββββΌββββΌββββ€
β22 β23 β32 β33 β
βββββ΄ββββ΄ββββ΄ββββ
```
**Characteristics:**
* Strong spatial locality
* Hierarchical (multi-resolution)
* Efficient neighbor and range queries
* Ideal for star catalogs and plate solving
> For astrometry, quad matching, and fast spatial indexing, **NESTED ordering is strongly recommended**.
---
## Coordinate conventions
`realpix` supports both:
* **Spherical angles**
* ΞΈ (colatitude): `[0, Ο]`
* Ο (longitude): `[0, 2Ο)`
* **Astronomical coordinates**
* Right Ascension (RA)
* Declination (Dec)
Standard conversions are used:
```
ΞΈ = Ο/2 β Dec
Ο = RA
```
---
## Resolution parameter
HEALPix resolution is controlled by a single parameter (`nside`):
* `nside` is the number of subdivisions **per edge of each base face**
* Must be a **power of two**
```
pixels = 12 Γ nsideΒ²
```
Approximate pixel angular size:
```
pixel size β 2 / nside radians
```
Examples:
| 32 | ~3.6Β° |
| 64 | ~1.8Β° |
| 128 | ~0.9Β° |
| 256 | ~0.45Β° |
---
## `std` and `no_std`
* **`std` is enabled by default**
* `realpix` can be built in **`no_std` environments**
* No heap allocation is required
* Suitable for:
* Embedded systems
* WASM
* Freestanding / constrained environments
---
## Design goals
* Correct handling of poles and boundaries
* Deterministic, explicit math
* No hidden allocations
* Clear mapping between theory and implementation
* Robust behavior across resolutions
---
## Status
* β RING indexing
* β NESTED indexing
* β RA/Dec β ΞΈ/Ο conversions
* β Unit-tested across edge cases
* π§ Neighbor queries (planned)
* π§ Cone / radius searches (planned)
---
## License
MIT OR Apache-2.0
---
## Inspiration
* HEALPix reference implementation
* healpy
* astrometry.net
#### License
<sup>
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
</sup>
<br>
<sub>
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.
</sub>