Skip to content

Commit

Permalink
Convert an automatic registration into an option
Browse files Browse the repository at this point in the history
Make registering a SpectrumList reader for any `data_loader` that reads
Spectrum1D objects optional, per the TODO in `specutils/io/registers.py`.
  • Loading branch information
tbowers7 committed Jun 23, 2023
1 parent bea93e7 commit 634f01d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions specutils/io/registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _astropy_has_priorities():


def data_loader(label, identifier=None, dtype=Spectrum1D, extensions=None,
priority=0, force=False, verbose=False):
priority=0, force=False, opt_in_spectrumlist=True, verbose=False):
"""
Wraps a function that can be added to an `~astropy.io.registry` for custom
file reading.
Expand All @@ -51,6 +51,9 @@ def data_loader(label, identifier=None, dtype=Spectrum1D, extensions=None,
force : bool, optional
Whether to override any existing function if already present.
Default is ``False``. Passed down to astropy registry.
opt_in_spectrumlist : bool, optional
Whether to register a SpectrumList reader for any data_loader that
reads Spectrum1D objects. Default is ``True``.
verbose : bool
Print extra info.
Expand Down Expand Up @@ -105,10 +108,9 @@ def decorator(func):
if verbose:
print(f"Successfully loaded reader \"{label}\".")

# Automatically register a SpectrumList reader for any data_loader that
# reads Spectrum1D objects. TODO: it's possible that this
# functionality should be opt-in rather than automatic.
if dtype is Spectrum1D:
# Optionally register a SpectrumList reader for any data_loader that
# reads Spectrum1D objects.
if dtype is Spectrum1D and opt_in_spectrumlist:
def load_spectrum_list(*args, **kwargs):
return SpectrumList([ func(*args, **kwargs) ])

Expand Down

0 comments on commit 634f01d

Please sign in to comment.