HDU (base class)¶
Every HDU type subclasses rustfits.HDU and inherits its
shared accessors (header, index, extname,
extver, has_data). Image and table subclasses add
their own data-access surface.
- class rustfits.HDU¶
Bases:
objectBase class for every FITS Header-Data Unit (HDU).
All HDU types —
ImageHDU,TableHDU,CompressedImageHDU,CompressedTableHDU,AsciiTableHDU— inherit from this class and share the header access, identity, and “do you have data?” surface defined here.HDU instances are produced by indexing a
FITSobject (hdu = fits[1]) or iterating it (for hdu in fits: ...). They cannot be constructed directly from Python; the file object owns the on-disk layout.The shared inherited surface is small on purpose — most of the useful methods live on the subclasses, where the data layout is known.
- extname¶
EXTNAMEheader value, orNonewhen the keyword is absent.EXTNAME is the user-visible name of the HDU (e.g.
'SCI','CATALOG'). Combined withextverit’s the standard way to identify HDUs without relying on position-by-index.
- extver¶
EXTVERheader value, defaulting to1when absent.Per the FITS standard, multiple HDUs may share an
EXTNAMEand are distinguished byEXTVER. Returns1rather thanNonefor the absent case so callers can compare/select without handlingOptional[int].
- has_data¶
Trueiff this HDU has a non-empty data section.Works uniformly across image and table HDUs: the test is
NAXIS > 0AND everyNAXISn > 0. For images that means “at least one pixel”; for tables it means “at least one row of at least one column”.Useful for picking the first HDU worth reading in a file (primary HDUs are often empty stubs):
hdu = next(h for h in fits if h.has_data) arr = hdu.read()
Edge case: a VLA table with
NAXIS2=0butPCOUNT>0(heap-only) returnsFalse— no main rows means there’s nothing to interpret the heap through, which is the right answer for the “is this HDU worth reading?” question.
- header¶
The HDU’s
FITSHeader.Returns a live view of this HDU’s header cards. Mutations via the header object (
__setitem__,__delitem__,update,add_comment,add_history,add_blank) write through to disk immediately, following the disk-write-before-commit ordering documented onFITSHeader.Reads are cheap; mutations may grow the reserved header blocks in place if the new card list exceeds the current allotment.