Move spex prism loader to specutils
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the shown _identify_spex, identify_spex_prism, and spex_prism_loader entry points, then read the related specutils issue 1259 for the destination context. Done means the SpeX loader and its identification behavior have been moved to specutils and the existing FITS, unit, uncertainty, and metadata behavior is preserved.
Written by the indexing model from the issue text.
Description
Move Spex loader to specutils. Related issue https://github.com/astropy/specutils/issues/1259
def _identify_spex(filename):
"""
Check whether the given file is a SpeX data product.
"""
try:
with fits.open(filename, memmap=False) as hdulist:
return "spex" in hdulist[0].header["INSTRUME"].lower() and "irtf" in hdulist[0].header["TELESCOP"].lower()
except Exception: # pylint: disable=broad-except,
return False
def identify_spex_prism(origin, *args, **kwargs):
"""
Confirm this is a SpeX Prism FITS file.
See FITS keyword reference at http://irtfweb.ifa.hawaii.edu/~spex/observer/
Notes: GRAT has values of: ShortXD, Prism, LXD_long, LXD_short, SO_long, SO_short
"""
is_spex = _identify_spex(args[0])
if is_spex:
with fits.open(args[0], memmap=False) as hdulist:
return (
isinstance(args[0], str)
and os.path.splitext(args[0].lower())[1] == ".fits"
and is_spex
and ("lowres" in hdulist[0].header["GRAT"].lower() or "prism" in hdulist[0].header["GRAT"].lower())
)
else:
return is_spex
@data_loader("Spex Prism", identifier=identify_spex_prism, extensions=["fits"], dtype=Spectrum)
def spex_prism_loader(filename, **kwargs):
"""Open a SpeX Prism file and convert it to a Spectrum1D object"""
with fits.open(filename, **kwargs) as hdulist:
header = hdulist[0].header
tab = hdulist[0].data
# Handle missing/incorrect units
try:
flux_unit = header["YUNITS"].replace("ergs", "erg ").strip()
wave_unit = header["XUNITS"].replace("Microns", "um")
except (KeyError, ValueError):
# For now, assume some default units
flux_unit = "erg"
wave_unit = "um"
wave, data = tab[0] * Unit(wave_unit), tab[1] * Unit(flux_unit)
if tab.shape[0] == 3:
uncertainty = StdDevUncertainty(tab[2])
else:
uncertainty = None
meta = {"header": header}
return Spectrum(flux=data, spectral_axis=wave, uncertainty=uncertainty, meta=meta)
- Dominant language
- Python
- Stars
- 12
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from astrodbtoolkit/AstrodbKit
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
astrodbtoolkit/AstrodbKit#110 ·
-
Nulls and load_table Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
astrodbtoolkit/AstrodbKit#109 ·
-
astrodbtoolkit/AstrodbKit#105 · 1 assignee ·
-
bug
astrodbtoolkit/AstrodbKit#103 · 1 assignee ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
astrodbtoolkit/AstrodbKit#101 · 1 comment ·
All issues in astrodbtoolkit/AstrodbKit
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
canonical/paas-charm#368 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
tech debt
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
StevenBlack/hosts#3256 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
qualcomm/qai-appbuilder#275 ·