simonrw / rust-fitsio

FFI wrapper around cfitsio in Rust
Apache License 2.0
37 stars 12 forks source link

Implement reading binary columns #339

Closed d3v-null closed 4 months ago

d3v-null commented 4 months ago

Hi there, I have a fits file (attached) with a binary column.

> fitsheader 1096952256.fits
# HDU 1 in 1096952256.fits:
TTYPE21 = 'Whitening_Filter'                                                    
TFORM21 = 'L       ' 

I can read it with python

from astropy.io import fits

with fits.open('1096952256.fits') as hdul:
    print(hdul[1].data['Whitening_Filter'])
[ True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True False False
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True False False
  True  True  True  True  True  True False False False False False False
 False False  True  True  True  True  True  True  True  True  True  True

but I can't read it with fitsio on the main branch. fitsio/examples/binary.rs

use fitsio::FitsFile;
use std::error::Error;
use std::path::PathBuf;

fn run() -> Result<(), Box<dyn Error>> {
    let mut fitsfile = FitsFile::edit(PathBuf::from("1096952256.fits"))?;
    fitsfile.pretty_print().expect("printing fits file");
    let ant_hdu = fitsfile.hdu(1)?;
    for value in ant_hdu.read_col::<u16>(&mut fitsfile, "Whitening_Filter")? {
        println!("{:?}", value);
    }
    Ok(())
}

fn main() {
    run().unwrap();
}

cargo run --example binary

  file: "1096952256.fits"
  mode: READWRITE
  extnum hdutype      hduname    details
  0      IMAGE_HDU               dimensions: [], type: UnsignedByte
  1      BINARY_TBL   TILEDATA   num_cols: 21, num_rows: 256
thread 'main' panicked at fitsio/examples/binary.rs:16:11:
called `Result::unwrap()` on an `Err` value: Fits(FitsError { status: 312, message: "bad binary table datatype" })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
d3v-null commented 4 months ago

here's the file: https://curtin-my.sharepoint.com/:f:/g/personal/285446d_curtin_edu_au/Eje9ZdeI9NRDlgwlvrpxswEBNR_fAnREluRCOGDRqo5krw