use fitsio::FitsFile;
use crate::error::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PixelType {
F32,
F64,
}
impl PixelType {
pub fn from_bitpix(bitpix: i64) -> Self {
if bitpix == -64 {
PixelType::F64
} else {
PixelType::F32
}
}
}
pub trait CubeElem: Copy + Send + Sync + 'static {
const BITPIX: i64;
fn read_full(fptr: &mut FitsFile) -> Result<Vec<Self>>;
fn read_section(fptr: &mut FitsFile, start: usize, end: usize) -> Result<Vec<Self>>;
fn write_section(fptr: &mut FitsFile, start: usize, end: usize, data: &[Self]) -> Result<()>;
}
macro_rules! impl_cube_elem {
($t:ty, $bitpix:expr) => {
impl CubeElem for $t {
const BITPIX: i64 = $bitpix;
fn read_full(fptr: &mut FitsFile) -> Result<Vec<Self>> {
let hdu = fptr.primary_hdu()?;
Ok(hdu.read_image(fptr)?)
}
fn read_section(fptr: &mut FitsFile, start: usize, end: usize) -> Result<Vec<Self>> {
let hdu = fptr.primary_hdu()?;
Ok(hdu.read_section(fptr, start, end)?)
}
fn write_section(
fptr: &mut FitsFile,
start: usize,
end: usize,
data: &[Self],
) -> Result<()> {
let hdu = fptr.primary_hdu()?;
hdu.write_section(fptr, start, end, data)?;
Ok(())
}
}
};
}
impl_cube_elem!(f32, -32);
impl_cube_elem!(f64, -64);