astrodbtoolkit / astrodbtoolkit/AstrodbKit
Move spex prism loader to specutils
- Langage dominant
- Python
- Étoiles
- 12
- Forks
- 5
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Move Spex loader to specutils. Related issue https://github.com/astropy/specutils/issues/1259
```Python
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)
```
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par les points d’entrée affichés _identify_spex, identify_spex_prism et spex_prism_loader, puis consultez le specutils issue 1259 associé pour le contexte de destination. Le travail est terminé lorsque le loader SpeX et son comportement d’identification ont été déplacés vers specutils et que le comportement existant de FITS, des unités, des incertitudes et des métadonnées est préservé.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- data
- Type d'issue
- Refactorisation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100