Skip to main content

FitsReader

Struct FitsReader 

Source
pub struct FitsReader<S> { /* private fields */ }
Expand description

A FITS file opened over a seekable byte source. Opening scans HDU boundaries from headers alone (no data is read); data units are fetched on demand.

Implementations§

Source§

impl<R: Read + Seek> FitsReader<StreamSource<R>>

Source

pub fn open(source: R) -> Result<StreamReader<R>>

Open a seekable byte source (file, cursor). Data units are copied into the reader’s scratch on demand; for an in-memory file prefer FitsReader::from_bytes, which decodes straight from the bytes.

Source§

impl<'a> FitsReader<SliceSource<'a>>

Source

pub fn from_bytes(bytes: &'a [u8]) -> Result<SliceReader<'a>>

Open an in-memory FITS file — the whole thing as a byte slice (e.g. an mmap, or bytes already in RAM). Data units decode straight from the borrowed bytes with no staging copy, and no scratch allocation.

Source§

impl FitsReader<MmapSource>

Source

pub fn open_mmap(path: impl AsRef<Path>) -> Result<MmapReader>

Available on crate feature mmap only.

Memory-map a FITS file and read it zero-copy: data units decode straight from the mapped pages (no staging copy, no read syscalls). Best for large files and random HDU access. Requires the mmap feature.

Source§

impl<S: Source> FitsReader<S>

Source

pub fn hdus(&self) -> &[Hdu]

The scanned HDU records, read-only and in file order — each carrying its parsed Header and HduKind. Index, iterate, or .len() the slice; pick an index for a read_* method (or use FitsReader::image_indices / FitsReader::hdu_index to find one).

Source

pub fn hdu_index(&self, name: &str, version: Option<i64>) -> Option<usize>

Index of the extension named name by its EXTNAME keyword (compared case-insensitively, as EXTNAME is conventionally matched), or None. When version is Some, also require a matching EXTVER (which defaults to 1 where the card is absent, §4.4.1) — the way duplicate extensions like ('SCI', 1) and ('SCI', 2) are told apart. The primary array has no EXTNAME. Pair the returned index with a read_* method.

Source

pub fn image_indices(&self) -> Vec<usize>

The indices of every HDU FitsReader::read_image can read as an image: image extensions, tiled-compressed images, and a non-empty primary array (an empty NAXIS = 0 primary is a container, not an image, and is skipped). A FITS file may hold any number of images — pick an index from this list to pass to FitsReader::read_image without inspecting HduKind yourself.

Source

pub fn read_data_raw(&mut self, index: usize) -> Result<DataUnit>

Read the raw, still-encoded (big-endian, unscaled) data unit into a fresh, caller-owned buffer. The returned DataUnit carries the full block-padded bytes plus the range of actual data within them, so a decoder consumes DataUnit::data and the block fill is never mistaken for samples.

This is the owned form, backing the table readers (which keep the bytes as the parsed table’s storage). Image and random-groups reads instead stage through the reader’s reused internal scratch — see FitsReader::read_image.

Source

pub fn read_image(&mut self, index: usize) -> Result<RawImage<'_>>

Read an HDU’s image as a RawImage, transparently handling both plain and tiled-compressed (ZIMAGE) images — the caller doesn’t need to know which. Errors with FitsError::NotAnImage for tables, random groups, and unmodelled extensions.

A plain image is zero-copy: its big-endian bytes are viewed in place over the source (or the reader’s reused scratch for a seeking source), decoded only when you ask. A compressed image is decompressed into an owned buffer (with the compression feature; without it a ZIMAGE HDU reads as a plain BINTABLE, so this returns FitsError::NotAnImage). Either way, reach for the samples via RawImage::u8 (zero-copy BITPIX = 8), RawImage::decode (host-endian), or RawImage::physical (scaled). The result borrows the reader, so handle one image before reading the next.

Source

pub fn read_image_view<'a>( &'a mut self, index: usize, scratch: &'a mut Vec<u64>, ) -> Result<ImageView<'a>>

Read an image as a borrowed, host-endian ImageView, byte-swapping into the caller-owned scratch — the fast, low-copy path for a loop that processes each image and moves on. Where read_image.decode() allocates a fresh owned buffer per call (page-fault-bound — profiling found that dominates a plain typed read), this reuses scratch, so a hot loop pays the output allocation once and reuses it across reads — even across differing BITPIX. The caller owns scratch, so the reader retains nothing image-sized; pass the same Vec each call and drop it when the loop ends.

scratch is Vec<u64> so the swapped samples stay 8-byte aligned for the typed views. A BITPIX = 8 image needs no swap and the view borrows the source bytes directly (zero-copy, scratch untouched); a compressed image is decompressed and copied into scratch. The view borrows the reader and scratch, so handle one image before reading the next. For samples you need to keep, use RawImage::decode.

Source

pub fn read_table(&mut self, index: usize) -> Result<BinTable>

Read a BINTABLE extension and parse its column structure. Decode individual columns lazily with BinTable::column_by_idx. Errors with FitsError::NotABinTable for any other HDU kind.

Source

pub fn read_ascii_table(&mut self, index: usize) -> Result<AsciiTable>

Read an TABLE (ASCII table) extension and parse its column structure. Errors with FitsError::NotAnAsciiTable for any other HDU.

Source

pub fn read_groups(&mut self, index: usize) -> Result<RandomGroups>

Read and decode a random-groups primary array (§6). Errors with FitsError::NotRandomGroups for any other HDU.

Source

pub fn read_compressed_table(&mut self, index: usize) -> Result<BinTable>

Available on crate feature compression only.

Read a tiled-compressed table (§10.3) — a BINTABLE with ZTABLE = T — and uncompress it into the original BinTable. Fixed-width columns only (GZIP_1/GZIP_2/RICE_1). Requires the compression feature.

Source

pub fn verify_checksum(&mut self, index: usize) -> Result<ChecksumReport>

Verify the DATASUM/CHECKSUM integrity keywords of an HDU (§J). Each field of the report is None if that keyword is absent, else Some(true) when it matches the recomputed checksum.

Trait Implementations§

Source§

impl<S: Debug> Debug for FitsReader<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for FitsReader<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for FitsReader<S>
where S: RefUnwindSafe,

§

impl<S> Send for FitsReader<S>
where S: Send,

§

impl<S> Sync for FitsReader<S>
where S: Sync,

§

impl<S> Unpin for FitsReader<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for FitsReader<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for FitsReader<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.