Giter Site home page Giter Site logo

cazou / rust-spice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gregoirehenry/rust-spice

0.0 0.0 0.0 9.58 MB

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

License: Apache License 2.0

Ruby 0.15% Rust 93.90% Tcl 5.95%

rust-spice's Introduction

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. In your folder /path/to/cspice/lib, rename the static libraries to match standards:
    1. cspice.a -> libcspice.a
    2. csupport.a -> libcsupport.a
  3. Tell Cargo where to look for the CSPICE library. This is done by adding some lines to $HOME/.cargo/config.toml. If the file doesn't exist, create it (read Configuration doc). You need to write:
[target.YOUR_PLATFORM.cspice]
rustc-link-lib = ["cspice"]
rustc-link-search = ["/path/to/cspice/lib"]
rustc-cdylib-link-arg = ["-I/path/to/cspice/include"]

replace YOUR_PLATFORM by either:

  • for linux: x86_64-unknown-linux-gnu
  • for mac: x86_64-apple-darwin
  • for windows: x86_64-pc-windows-msvc

and replace /path/to/cspice with the absolute path to your CSPICE installation.

Usage

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

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

In action

A nice and idiomatic interface to Spice,

use spice;

let mut kernel = spice::furnsh("rsc/krn/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("rsc/krn/hera_study_PO_EMA_2024.tm");

You can look for some inspirations in the 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("/path/to/metakernel.mk").unwrap().into_raw();
    spice::c::furnsh_c(kernel);

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

    let target_c = CString::new("TARGET_NAME").unwrap().into_raw();
    let frame_c = CString::new("FRAME_NAME").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,
        ephemeris_time,
        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.

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.

rust-spice's People

Contributors

s-rah avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.