Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Move spex prism loader to specutils

Open
#104 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from astrodbtoolkit/AstrodbKit

All issues in astrodbtoolkit/AstrodbKit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.