How to use the specutils.spectra.SpectrumList function in specutils

To help you get started, we’ve selected a few specutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github astropy / specutils / specutils / io / registers.py View on Github external
def load_spectrum_list(*args, **kwargs):
                return SpectrumList([ func(*args, **kwargs) ])
github astropy / specutils / specutils / io / asdf / tags / spectra.py View on Github external
"""
        assert allclose(old.flux, new.flux)
        assert allclose(old.spectral_axis, new.spectral_axis)
        if old.uncertainty is None:
            assert new.uncertainty is None
        else:
            assert old.uncertainty.uncertainty_type == new.uncertainty.uncertainty_type
            assert_allclose(old.uncertainty.array, new.uncertainty.array)


class SpectrumListType(SpecutilsType):
    """
    ASDF tag implementation used to serialize/deserialize SpectrumList objects
    """
    name = 'spectra/spectrum_list'
    types = [SpectrumList]
    version = '1.0.0'

    @classmethod
    def to_tree(cls, obj, ctx):
        """
        Converts SpectrumList object into tree used for YAML representation
        """
        return [custom_tree_to_tagged_tree(spectrum, ctx) for spectrum in obj]

    @classmethod
    def from_tree(cls, tree, ctx):
        """
        Converts tree representation back into SpectrumList object
        """
        spectra = [tagged_tree_to_custom_tree(node, ctx) for node in tree]
        return SpectrumList(spectra)
github astropy / specutils / specutils / io / default_loaders / jwst_reader.py View on Github external
if np.min(uncertainty.array) <= 0.:
                warnings.warn("Standard Deviation has values of 0 or less",
                    AstropyUserWarning)

            # Merge primary and slit headers and dump into meta
            slit_header = hdu.header
            header = primary_header.copy()
            header.extend(slit_header, strip=True, update=True)
            meta = {k: v for k,v in header.items()}

            spec = Spectrum1D(flux=flux, spectral_axis=wavelength,
                uncertainty=uncertainty, meta=meta)
            spectra.append(spec)

    return SpectrumList(spectra)
github astropy / specutils / specutils / io / default_loaders / jwst_reader.py View on Github external
            dtype=SpectrumList, extensions=['fits'])
def jwst_x1d_multi_loader(filename, **kwargs):
    """
    Loader for JWST x1d 1-D spectral data in FITS format

    Parameters
    ----------
    filename: str
        The path to the FITS file

    Returns
    -------
    SpectrumList
        A list of the spectra that are contained in the file.
    """
    return _jwst_x1d_loader(filename, **kwargs)
github astropy / specutils / specutils / io / registers.py View on Github external
io_registry._readers.update(sorted_loaders)

        logging.debug("Successfully loaded reader \"{}\".".format(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:
            def load_spectrum_list(*args, **kwargs):
                return SpectrumList([ func(*args, **kwargs) ])

            # Add these attributes to the SpectrumList reader as well
            load_spectrum_list.extensions = extensions
            load_spectrum_list.priority = priority

            io_registry.register_reader(label, SpectrumList, load_spectrum_list)
            io_registry.register_identifier(label, SpectrumList, id_func)
            logging.debug("Created SpectrumList reader for \"{}\".".format(label))

        @wraps(func)
        def wrapper(*args, **kwargs):
            return func(*args, **kwargs)
        return wrapper
    return decorator
github astropy / specutils / specutils / io / asdf / tags / spectra.py View on Github external
def from_tree(cls, tree, ctx):
        """
        Converts tree representation back into SpectrumList object
        """
        spectra = [tagged_tree_to_custom_tree(node, ctx) for node in tree]
        return SpectrumList(spectra)