/fits-rs

FITS encoder and decoder in Rust

Primary LanguageRustMIT LicenseMIT

fits-rs Build Status Coverage Status Crate

FITS encoder and decoder in Rust.

Make sure to check out the documentation of this crate. The build can be followed as well. The coverage report is provided by coveralls.

FITS

The Flexible Image Transport System (FITS) is

an open standard defining a digital file format useful for storage, transmission and processing of scientific and other images.

The reference documentation on the FITS standard can be found an NASA's FITS pages. You can get a copy by executing the following command:

wget --output-document=fits-reference.pdf "https://www.aanda.org/articles/aa/pdf/2010/16/aa15362-10.pdf"

Reading Primary Header

Even though the headers of FITS files are in ASCII, you can use this crate to read the primary header.

    let args: Vec<String> = env::args().collect();
    let filename = &args[1];
    let header_index = u64::from_str(&args[2]).expect("should be a non-negative number");

    let mut f = File::open(filename).expect("file not found");
    let mut buffer: Vec<u8> = vec!();
    let _ = f.read_to_end(&mut buffer);

    let result = fits(&buffer);

    match result {
        IResult::Done(_, trappist1) => {
            let header: &Header = if header_index = 0 {
                &trappist1.primary_hdu.header
            } else {
                &trappist1.extensions[header_index].header
            }

            for record in header.keyword_records {
                println!("{:?}", record);
            }
        },
        _ => panic!("Whoops, something went wrong")
    }

You can find this binary in src/bin/headers.rs.

Unfortunately, some extensions are in binary.