cdshealpix-rust

CDS implementation of the HEALPix tesselation in Rust and modules to generate libraries in WebAssembly, Python, ...

API Documentation on docs.rs Rust

About

This library is an implementation in Rust of the HEALPix tesselation. This implementation has been made by the Strasbourg astronomical Data Centre (Centre de Données astronomique de Strasbourg, CDS).

It is used in: * Aladin Lite V3 * The CDS MOC library in Rust used in: + MOCPy, a Python wrapper to manipulate MOCs; + MOCli a standalone command line tool for linux, MacOS and Windows; + MOCWasm, a WASM library to manipulate MOCs from web browsers. * CDS internal developments

Initially, it is a port of a part of the CDS Java library available here, but improvement have been added while porting the code.

For information on HEALPix in general, see: * The official web site * The Wikipedia page * The two main reference papers: Gorski (2005) and Calabretta (2007)

Official implementations, are available here. It contains GPL v2 codes in Fortran, C++, Java, IDL, Python, ...

Other independent HEALPix implementations: * Astropy-healpix python wrapper using a C code (C code by Dustin Lang, python wrapper by Thomas Robitaille and others) * Javascript/Typescript implementation by Koike Michitaro * Julia implementation by Maurizio Tomasi * C "official" core functionalities implementation in BSD by Martin Reinecke * ... (Help me to add links to other HEALPix resources and codes).

Warning

For best performances on your specific hardware, you can compile using: bash RUSTFLAGS='-C target-cpu=native' cargo build --release This uses BMI2 instructions PDEP and PEXT, if supported by your processor, for bit interleaving.

However, the implementaion of those instructions on AMD Ryzen processors are extremely slow (20x slower than a lookup table, doubling the hash computation time)! You can test it usingi: bash RUSTFLAGS='-C target-cpu=native' cargo bench If the result of ZOrderCurve/BMI is slower thatn ZOrderCurve/LUPT, compile without the native support: bash cargo build --release

Target 32 bit on a 64 bit linux

rust rustup target install i686-unknown-linux-gnu sudo apt-get install gcc-multilib RUSTFLAGS='-C target-cpu=native' cargo build --target=i686-unknown-linux-gnu --release

Features

Missing Features

Examples

Compute the cell number of a given position on the unit-sphere at a given HEALPix depth.

```rust use cdshealpix::{nside}; use cdshealpix::nested::{getorcreate, Layer};

let depth = 12u8; let lon = 12.5f64.toradians(); let lat = 89.99999f64.to_radians();

let nestedd12 = getorcreate(depth); let nside = nside(depth) as u64; let expectedcellnumber = nside * nside - 1

asserteq!(expectedcellnumber, nestedd12.hash(lon, lat)); ```

Get the spherical coorinates of the 4 vertices of a given cell at a given depth:

```rust use cdshealpix::nested::{getorcreate, Layer};

let depth = 12u8; let cellnumber= 10_u64;

let nestedd12 = getor_create(depth);

let [ (lonsouth, latsouth), (loneast, lateast), (lonnorth, latnorth), (lonwest, latwest) ] = nestedd12.vertices(cellnumber);

```

Get a hierarchical view (a MOC) on the cells overlapped by a given cone:

```rust use cdshealpix::nested::{getorcreate, Layer};

let depth = 6u8; let nestedd6 = getorcreate(depth);

let lon = 13.158329f64.toradians(); let lat = -72.80028f64.toradians(); let radius = 5.64323f64.toradians();

let moc = nestedd6.coneoverlapapprox(lon, lat, radius); for cell in moc.intoiter() { println!("cell: {:?}", cell); } ```

Standalone

(Not on crates.io, but on github) The code source of the very beginning of a standalone exec can be found in cli/src/bin.rs.

WebAssembly

(Not on crates.io, but on github) To build and use the WebAssembly (and Javascript) files, the libwasmbingen directory. We rely on wasm-bingen.

Python

(Not on crates.io, but on github) See the libpython directory containing a very first integration in python using CFFI.

For a clean Python wrapper and associated Wheels, see Matthieu Baumann's project cds-healpix-python. To use the library in python, install it through pip (examples are provided on github cds-healpix-python): bash pip install cdshealpix

ToDo list

License

Like most projects in Rust, this project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Disclaimer

It a first code in Rust, feel free to give some advice/feedback.