realpix

Crates.iorealpix
lib.rsrealpix
version0.1.3
created_at2026-01-11 14:57:25.354645+00
updated_at2026-01-18 16:05:28.888552+00
descriptionA HEALPix implementation in pure rust
homepage
repository
max_upload_size
id2035928
size48,424
Joatin Granlund (Joatin)

documentation

README

Cargo Build & Test

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 (Hierarchical Equal Area Latitude Pixelization) 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:

nside Pixel size
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

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
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.
Commit count: 0

cargo fmt