Skip to content

Commit

Permalink
Add 6dFGS loader
Browse files Browse the repository at this point in the history
  • Loading branch information
aragilar committed Apr 1, 2020
1 parent 60f2c6c commit 490f31b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
63 changes: 63 additions & 0 deletions specutils/io/default_loaders/sixdfgs_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import astropy.io.fits as fits
from astropy.table import Table
from astropy.units import Quantity, Unit
from specutils.io.registers import data_loader
from specutils import Spectrum1D

SIXDFGS_PRIMARY_HDU_KEYWORDS = ["OBSRA", "OBSDEC", "Z", "Z_HELIO", "QUALITY"]
COUNTS_PER_SECOND = Unit("counts/s", parse_strict="silent")


def identify_6dfgs_tabular_fits(origin, *args, **kwargs):
"""
Identify if the current file is a 6dFGS file (stored as a table)
"""
with fits.open(args[0]) as hdulist:
if len(hdulist) != 2:
return False
primary_hdu = hdulist[0]
if primary_hdu.header["NAXIS"] != 0:
return False
for keyword in SIXDFGS_PRIMARY_HDU_KEYWORDS:
if keyword not in primary_hdu.header:
return False
return True


@data_loader("6dFGS-tabular",
identifier=identify_6dfgs_tabular_fits,dtype=Spectrum1D,
extensions=["fit", "fits"])
def sixdfgs_tabular_fits_loader(filename, **kwargs):
"""
Load the tabular variant of a 6dF Galaxy Survey (6dFGS) file.
6dFGS used the Six-degree Field instrument on the UK Schmidt Telescope
(UKST) at the Siding Spring Observatory (SSO) near Coonabarabran,
Australia. Further details can be found at http://www.6dfgs.net/, or
https://docs.datacentral.org.au/6dfgs/. Catalogues and spectra were
produced, with the spectra being provided as both fits tables and as fits
images. This loads the tabular variant of the spectra. Note that this does
not include uncertainties - uncertainties are only provided in the image
variants.
Parameters
----------
file_name: str
The path to the FITS file
Returns
-------
data: Spectrum1D
The 6dF spectrum that is represented by the data in this table.
"""
with fits.open(filename) as hdulist:
header = hdulist[0].header
table = Table.read(hdulist)
flux = Quantity(table["FLUX"])
wavelength = Quantity(table["WAVE"])

if flux.unit == COUNTS_PER_SECOND:
flux._unit = Unit("count/s")
meta = {"header": header}

return Spectrum1D(flux=flux, spectral_axis=wavelength, meta=meta)
8 changes: 8 additions & 0 deletions specutils/tests/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,11 @@ def test_subaru_pfs_loader(tmpdir):
assert len(spec.flux) == len(spec.spectral_axis) > 10000
assert spec.spectral_axis.unit == u.nm
assert spec.flux.unit == u.nJy


@remote_access([{'id': '3733958', 'filename': '1D-c0022498-344732.fits'}])
def test_spectrum1d_6dfgs_tabular(remote_data_path):
spec = Spectrum1D.read(remote_data_path)

assert spec.spectral_axis.unit == u.Unit("Angstrom")
assert spec.flux.unit == u.Unit("count/s")

0 comments on commit 490f31b

Please sign in to comment.