Skip to content

Commit

Permalink
Add option to store data header instead
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen committed Jul 1, 2024
1 parent 68a7ef3 commit e5407b2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions specutils/io/default_loaders/tabular_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def identify_tabular_fits(origin, *args, **kwargs):

@data_loader("tabular-fits", identifier=identify_tabular_fits,
dtype=Spectrum1D, extensions=['fits', 'fit'], priority=6)
def tabular_fits_loader(file_obj, column_mapping=None, hdu=1, **kwargs):
def tabular_fits_loader(file_obj, column_mapping=None, hdu=1, store_data_header=False, **kwargs):
"""
Load spectrum from a FITS file.
Expand All @@ -52,6 +52,9 @@ def tabular_fits_loader(file_obj, column_mapping=None, hdu=1, **kwargs):
or HDUList (as resulting from astropy.io.fits.open()).
hdu: int
The HDU of the fits file (default: 1st extension) to read from
store_data_header: bool
Defaults to False, which stores the primary header in the Spectrum1D.meta attribute.
Set to True to instead store the header from the specified data HDU.
column_mapping : dict
A dictionary describing the relation between the FITS file columns
and the arguments of the `Spectrum1D` class, along with unit
Expand All @@ -74,7 +77,10 @@ def tabular_fits_loader(file_obj, column_mapping=None, hdu=1, **kwargs):
primary_header = hdulist[0].header
tab = Table.read(hdulist[hdu])

tab.meta = primary_header
if store_data_header:
tab.meta = hdulist[hdu].header
else:
tab.meta = primary_header

# Minimal checks for wcs consistency with table data -
# assume 1D spectral axis (having shape (0, NAXIS1),
Expand Down

0 comments on commit e5407b2

Please sign in to comment.