atfits-rs 1.2.0

cfitsio helpers (pixel I/O, header editing, image creation) shared by the at*-rs FITS tools
Documentation

atfits-rs

CI crates.io docs.rs

cfitsio helpers shared by fitscube-rs and convolve-rs:

  • PixelType, CubeElem, read_plane, write_plane: f32/f64 pixel I/O, with BLANK read as NaN and NaN written as BLANK.
  • raw: pixel I/O in any FITS type, rectangular subsets, stored values with scaling off, and big-endian helpers for raw data-unit writes.
  • keys: keyword updates that replace the existing card (fitsio's write_key appends a duplicate), and readers that tell a missing keyword from a malformed one.
  • header: image geometry, WCS axis lookup, unit factors and pixel scale.
  • image: image creation, resizing and header-only copies, including from an image extension.
  • mem_header: build a cube header in memory and write the data unit with plain file I/O.
  • output_path: output file names.

Install

[dependencies]
atfits-rs = "1"

The fitsio-src feature compiles cfitsio from source, which needs only a C compiler. Without it the system cfitsio is linked.

atfits-rs = { version = "1", features = ["fitsio-src"] }

Example

Create a cube from a 2D template, write each plane, then read the cube back:

use atfits_rs::{CubeElem, create_cube_open, update_key_f64, write_plane};
use fitsio::FitsFile;

let dims = [size, size, nchan]; // NAXIS1, NAXIS2, NAXIS3
let mut out = create_cube_open(&template, &cube_path, -32, &dims)?;
update_key_f64(&mut out, "CRVAL3", 1.0e9)?;
for c in 0..nchan {
    write_plane(&mut out, c, &vec![c as f32; size * size])?;
}
drop(out);

let mut f = FitsFile::open(&cube_path)?;
let all = f32::read_full(&mut f)?;

Threads

A FitsFile must stay on the thread that opened it. Threads may each open their own handle when cfitsio is reentrant, which the fitsio-src build is; is_reentrant() checks a system library. Write a given file from one handle only.

Development

cargo test --features fitsio-src
prek run --all-files     # or: pre-commit run --all-files
cargo doc --no-deps --features fitsio-src --open

CI runs the same hooks (cargo fmt, cargo clippy, generic checks) with prek.

License

BSD-3-Clause.