Crate fitrs

source ·
Expand description

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[2];
// Get HDU by EXTNAME
let hdu_flux = &fits["FLUX"];

match hdu_flux.read_data() {
    &FitsData::FloatingPoint32(FitsDataArray { ref shape, ref 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.

Structs

Represent an open FITS file.
Actual array data inside the Hdu
An iterator over Hdus. Obtained from a consumed Fits object.
An iterator over references to Hdus.
An iterator over mutable references to Hdus.
Represent an HDU as defined in FITS standard 4.1.
Iterator over the header of an HDU
World Coordinates

Enums

Represent a data array inside an Hdu.
Value stored inside the Hdu header.

Traits

A type that can be stored in a FITS data array implements this trait.