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>>
impl<R: Read + Seek> FitsReader<StreamSource<R>>
Sourcepub fn open(source: R) -> Result<StreamReader<R>>
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>>
impl<'a> FitsReader<SliceSource<'a>>
Sourcepub fn from_bytes(bytes: &'a [u8]) -> Result<SliceReader<'a>>
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>
impl FitsReader<MmapSource>
Sourcepub fn open_mmap(path: impl AsRef<Path>) -> Result<MmapReader>
Available on crate feature mmap only.
pub fn open_mmap(path: impl AsRef<Path>) -> Result<MmapReader>
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>
impl<S: Source> FitsReader<S>
Sourcepub fn hdus(&self) -> &[Hdu]
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).
Sourcepub fn hdu_index(&self, name: &str, version: Option<i64>) -> Option<usize>
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.
Sourcepub fn image_indices(&self) -> Vec<usize>
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.
Sourcepub fn read_data_raw(&mut self, index: usize) -> Result<DataUnit>
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.
Sourcepub fn read_image(&mut self, index: usize) -> Result<RawImage<'_>>
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.
Sourcepub fn read_image_view<'a>(
&'a mut self,
index: usize,
scratch: &'a mut Vec<u64>,
) -> Result<ImageView<'a>>
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.
Sourcepub fn read_table(&mut self, index: usize) -> Result<BinTable>
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.
Sourcepub fn read_ascii_table(&mut self, index: usize) -> Result<AsciiTable>
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.
Sourcepub fn read_groups(&mut self, index: usize) -> Result<RandomGroups>
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.
Sourcepub fn read_compressed_table(&mut self, index: usize) -> Result<BinTable>
Available on crate feature compression only.
pub fn read_compressed_table(&mut self, index: usize) -> Result<BinTable>
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.
Sourcepub fn verify_checksum(&mut self, index: usize) -> Result<ChecksumReport>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
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
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
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
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.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
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.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
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.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
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.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
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.