17 releases

Uses old Rust 2015

0.5.0 Oct 31, 2019
0.4.2 Dec 2, 2018
0.4.0 Nov 18, 2018
0.1.2 Jul 2, 2018

#1383 in Parser implementations

Download history 62/week @ 2024-08-04 97/week @ 2024-08-11 38/week @ 2024-08-18 57/week @ 2024-08-25 29/week @ 2024-09-01 27/week @ 2024-09-08 4/week @ 2024-09-15 146/week @ 2024-09-22 67/week @ 2024-09-29 106/week @ 2024-10-06 25/week @ 2024-10-13 2/week @ 2024-10-20 19/week @ 2024-10-27 22/week @ 2024-11-03 35/week @ 2024-11-10 25/week @ 2024-11-17

101 downloads per month
Used in 5 crates (4 directly)

GPL-3.0 license

64KB
1.5K SLoC

FITRS

Build Status Documentation on docs.rs

DISCLAIMER: This lib is experimental and unstable. API changes will most probably occur.

Read/Write FITS file for astronomical use. Not all the features of the FITS standard are supported, but the basic features are there.

The objective is to make a lib to manage FITS files in pure rust, with as few dependencies as possible multi-threading in mind.

Documentation

You can refer to the online doc.

See the tests and benchmarks in the repository for more examples how to use.


lib.rs:

Library to parse FITS file written in pure rust.

Uses only one dependency, byteorder, to deal with endianness.

Uses intelligent cache to parse big FITS files. Developed for use in multi-threaded environments.

How to use

Read FITS

extern crate fitrs;
use fitrs::{Fits, FitsData, FitsDataArray};

let fits = Fits::open("path/to/fits/file.fits").expect("Failed to open");
// Iterate over HDUs
for hdu in fits.iter() {
    println!("{:?}", hdu.value("EXTNAME"));
    println!("{:?}", hdu.read_data());
}

// Get HDU by ID
let hdu_2 = fits.get(2);
// Get HDU by EXTNAME
if let Some(hdu_flux) = fits.get_by_name("FLUX") {
    match hdu_flux.read_data() {
        FitsData::FloatingPoint32(FitsDataArray { shape, data }) => {
            println!("{:?}", shape);
            println!("{:?}", data);
        }
        _ => { /* ... */ }
    }
}

Write FITS

The FITS files written by fitrs are verified by astropy.io.fits for standard compliance. If fitrs outputs a non-compliant FITS file, please file a bug.

extern crate fitrs;
use fitrs::{Fits, Hdu};

// Make example dummy data array
let shape = [20, 20];
let data = (0..shape[0])
    .map(|i| (0..shape[1]).map(move |j| i + j))
    .flatten()
    .collect();
let mut primary_hdu = Hdu::new(&[20, 20], data);
// Insert values in header
primary_hdu.insert("KEYSTR", "My string");
primary_hdu.insert("KEYSTR2", "Whatever value you want to save in this FITS files. Continued (long) strings are supported, if you happen to care.");
primary_hdu.insert("KEYFLOAT", 3.14);
primary_hdu.insert("KEYINT", 42);

// Save file
Fits::create("new_file.fits", primary_hdu).expect("Failed to create");

A lot of possibly desirable functionalities are still missing. PR are welcome.

Dependencies