All Projects → GregoireHENRY → rust-spice

GregoireHENRY / rust-spice

Licence: Apache-2.0 license
WOW! The complete NASA/NAIF Spice toolkit is actually usable on Rust

Programming Languages

rust
11053 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to rust-spice

Open Notify Api
Source code for api.open-notify.org
Stars: ✭ 272 (+777.42%)
Mutual labels:  nasa, space
NASSP
Project Apollo - NASSP
Stars: ✭ 110 (+254.84%)
Mutual labels:  nasa, space
Nasa-And-Spacex-Cooperation
Theme Outer Space
Stars: ✭ 41 (+32.26%)
Mutual labels:  nasa, space
Apod Api
Astronomy Picture of the Day API service
Stars: ✭ 290 (+835.48%)
Mutual labels:  nasa, space
Spacex Api
🚀 Open Source REST API for SpaceX launch, rocket, core, capsule, starlink, launchpad, and landing pad data.
Stars: ✭ 8,973 (+28845.16%)
Mutual labels:  nasa, space
Moonwalk
🚀 React-Native App for rocket launches 🛰
Stars: ✭ 169 (+445.16%)
Mutual labels:  nasa, space
Pysat
Generalized satellite and space science data processing and file management.
Stars: ✭ 72 (+132.26%)
Mutual labels:  nasa, space
Spiceypy
SpiceyPy: a Pythonic Wrapper for the SPICE Toolkit.
Stars: ✭ 218 (+603.23%)
Mutual labels:  nasa, space
GuneyOzsanOutThereMusicVideo
Procedurally generated, real-time, demoscene style, open source music video made with Unity 3D for Out There by Guney Ozsan.
Stars: ✭ 26 (-16.13%)
Mutual labels:  space
mudrod
Mining and Utilizing Dataset Relevancy from Oceanographic Datasets to Improve Data Discovery and Access, online demo: https://mudrod.jpl.nasa.gov/#/
Stars: ✭ 15 (-51.61%)
Mutual labels:  nasa
nuu
SciFi-MMORPG-2d-Scrolling-Action-Trade-Adventure
Stars: ✭ 17 (-45.16%)
Mutual labels:  space
slimarray
SlimArray compresses uint32 into several bits, by using a polynomial to describe overall trend of an array.
Stars: ✭ 39 (+25.81%)
Mutual labels:  space
TerraGov-Marine-Corps
TGMC: TerraGov Marine Corps, a SS13 mod
Stars: ✭ 109 (+251.61%)
Mutual labels:  space
stellarstation-api
The API definition for StellarStation.
Stars: ✭ 22 (-29.03%)
Mutual labels:  space
instructions
https://github.com/nasa/nasa.github.io/blob/master/docs/INSTRUCTIONS.md
Stars: ✭ 302 (+874.19%)
Mutual labels:  nasa
SpaceX
PowerShell module to interact with api.spacexdata.com
Stars: ✭ 25 (-19.35%)
Mutual labels:  space
awesome-spacehackers
A curated list of aerospace/space related data and code resources for a community of independent hackers dedicated to furthering humanity's knowledge of the universe through open collaboration.
Stars: ✭ 36 (+16.13%)
Mutual labels:  space
SimpleKeplerOrbits
Unity3d static 2-body orbits simulation
Stars: ✭ 76 (+145.16%)
Mutual labels:  space
kepler
Consuming NASA API to visualize exoplanets data in a Flutter app
Stars: ✭ 33 (+6.45%)
Mutual labels:  nasa
agroclimatology
Ruby client for interacting with the NASA (POWER) Agroclimatology Web Resource
Stars: ✭ 16 (-48.39%)
Mutual labels:  nasa

rust-spice

logo image

crate badge doc badge license badge pre-commit badge coverage doc badge coverage test badge

WOW! The complete NASA/NAIF Spice toolkit is actually usable on Rust


Intro | Requirements | In action | In development | Usage | Roadmap | Contributors | License


Intro

SPICE is An Observation Geometry System for Space Science Missions. Visit their website.

Requirements

  1. Install CSPICE library for your platform.
  2. Set the environment variable CSPICE_DIR to your CSPICE installation folder (where CSPICE subfolders include and lib are located. You can do that in the Cargo configuration).
  3. In the cspice/lib folder you might need for Unix systems to rename the static library to match standards: cspice.a -> libcspice.a

See other requirements at cspice-sys library which provides unsafe bindings to CSPICE.

Usage

Add the dependency rust-spice to your Cargo.toml:

[dependencies]
rust-spice = "*" # replace * by the latest version of the crate

cspice-sys library depends on Clang which might not be available to your system. In this case, you can use the feature noclang:

[dependencies]
rust-spice = {version = "*", default-features = false, features = ["noclang"] }

In action

A nice and idiomatic interface to Spice,

use spice;

let mut kernel = spice::furnsh("hera/kernels/mk/hera_study_PO_EMA_2024.tm");

let et = spice::str2et("2027-MAR-23 16:00:00");
let (position, light_time) = spice::spkpos("DIMORPHOS", et, "J2000", "NONE", "SUN");

// position -> 18.62640405424448, 21.054373008357004, -7.136291402940499
// light time -> 0.00009674257074746383

spice::unload("hera/kernels/mk/hera_study_PO_EMA_2024.tm");

You can look for some inspirations in the core tests.

In development

Developing an idiomatic interface for Spice in Rust takes time, and not all functions are implemented yet. In the documentation online, a complete guide details which functions are available. If yours is not, you can always use the unsafe API which contains all cspice functions.

For instance, with the unsafe API, the example above would be,

use spice;
use std::ffi::CString;

unsafe {
    let kernel = CString::new("hera/kernels/mk/hera_study_PO_EMA_2024.tm").unwrap().into_raw();
    spice::c::furnsh_c(kernel);

    let mut et = 0.0;
    let date = CString::new("2027-MAR-23 16:00:00").unwrap().into_raw();
    spice::c::str2et_c(date, &mut et);

    let target_c = CString::new("DIMORPHOS").unwrap().into_raw();
    let frame_c = CString::new("J2000").unwrap().into_raw();
    let abcorr_c = CString::new("NONE").unwrap().into_raw();
    let observer_c = CString::new("SUN").unwrap().into_raw();
    let mut light_time = 0.0;
    let mut position = [0.0, 0.0, 0.0];
    spice::c::spkpos_c(
        target_c,
        et,
        frame_c,
        abcorr_c,
        observer_c,
        &mut position[0],
        &mut light_time,
    );

    spice::c::unload_c(kernel);
}

Much less friendly.. yet it is available. I would love some help in order to complete the idiomatic development. You can raise an issue or propose a pull request for the implementation of a specific function.

Multi-threaded usage

CSPICE itself contains massive amounts of shared mutable state and is thus not thread-safe - concurrent calls to any SPICE functions will almost always lead to crashes. To prevent this, if you need to call SPICE functions from multiple threads, this crate provides a thread-safe API with the lock feature. When enabled, the API is exposed in the form of associated functions on a guard singleton SpiceLock, which is !Sync + Send. You can then only share this singleton and thus the methods it provides between threads using a Mutex, preventing concurrent API usage.

The lock exposes the neat versions of functions where available, and the raw versions for the rest. For functions which have neither, you will have to use the unsafe (and unguarded) direct C bindings. Just make sure you have the lock before calling them.

use spice::SpiceLock;

// `try_acquire` will return `Err` if a lock already exists
let sl = SpiceLock::try_acquire().unwrap();

// SPICE functions are now associated functions of the lock with a `&self` arg
let mut kernel = sl.furnsh("hera/kernels/mk/hera_study_PO_EMA_2024.tm");

let et = sl.str2et("2027-MAR-23 16:00:00");
let (position, light_time) = sl.spkpos("DIMORPHOS", et, "J2000", "NONE", "SUN");

sl.unload("hera/kernels/mk/hera_study_PO_EMA_2024.tm");

Roadmap

  • provide a packaging of the test assets
  • complete most-used API
  • complete whole API
  • refactoring of the procedural macros
  • refactoring of Cell

Contributors

Hall of fame:

A huge thanks for their contributions!!

License

Licensed under the Apache License, Version 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].