# Path: sncosmo/bandpasses.py
# def get_bandpass(name, *args):
#     """Get a Bandpass from the registry by name."""
#     if isinstance(name, Bandpass):
#         return name
#     if len(args) == 0:
#         return _BANDPASSES.retrieve(name)
#     else:
#         interp = _BANDPASS_INTERPOLATORS.retrieve(name)
#         return interp.at(*args)
# 
# Path: sncosmo/constants.py
# HC_ERG_AA = H_ERG_S * C_AA_PER_S
# 
# SPECTRUM_BANDFLUX_SPACING = 1.0
# 
# FLAMBDA_UNIT = u.erg / u.s / u.cm**2 / u.AA
# 
# Path: sncosmo/utils.py
# def integration_grid(low, high, target_spacing):
#     """Divide the range between `start` and `stop` into uniform bins
#     with spacing less than or equal to `target_spacing` and return the
#     bin midpoints and the actual spacing."""
# 
#     range_diff = high - low
#     spacing = range_diff / int(math.ceil(range_diff / target_spacing))
#     grid = np.arange(low + 0.5 * spacing, high, spacing)
# 
#     return grid, spacing


import astropy.units as u
import numpy as np
from scipy.interpolate import splev, splrep
from .bandpasses import get_bandpass
from .constants import HC_ERG_AA, SPECTRUM_BANDFLUX_SPACING, FLAMBDA_UNIT
from .utils import integration_grid
    """A model spectrum, representing wavelength and spectral density values.

    Parameters
    ----------
    wave : list_like
        Wavelength values.
    flux : list_like
        Spectral flux density values.
    wave_unit : `~astropy.units.Unit`
        Unit on wavelength.
    unit : `~astropy.units.BaseUnit`
        For now, only units with flux density in energy (not photon counts).
    """

    def __init__(self, wave, flux, wave_unit=u.AA,
                 unit=(u.erg / u.s / u.cm**2 / u.AA)):
        self.wave = np.asarray(wave, dtype=np.float64)
        self.flux = np.asarray(flux, dtype=np.float64)
        if self.wave.shape != self.flux.shape:
            raise ValueError('shape of wavelength and flux must match')
        if self.wave.ndim != 1:
            raise ValueError('only 1-d arrays supported')

        # internally, wavelength is in Angstroms:
        if wave_unit != u.AA:
            self.wave = wave_unit.to(u.AA, self.wave, u.spectral())
        self._wave_unit = u.AA

        # internally, flux is in F_lambda:
        if unit != FLAMBDA_UNIT:

# Path: sncosmo/bandpasses.py
# def get_bandpass(name, *args):
#     """Get a Bandpass from the registry by name."""
#     if isinstance(name, Bandpass):
#         return name
#     if len(args) == 0:
#         return _BANDPASSES.retrieve(name)
#     else:
#         interp = _BANDPASS_INTERPOLATORS.retrieve(name)
#         return interp.at(*args)
# 
# Path: sncosmo/constants.py
# HC_ERG_AA = H_ERG_S * C_AA_PER_S
# 
# SPECTRUM_BANDFLUX_SPACING = 1.0
# 
# FLAMBDA_UNIT = u.erg / u.s / u.cm**2 / u.AA
# 
# Path: sncosmo/utils.py
# def integration_grid(low, high, target_spacing):
#     """Divide the range between `start` and `stop` into uniform bins
#     with spacing less than or equal to `target_spacing` and return the
#     bin midpoints and the actual spacing."""
# 
#     range_diff = high - low
#     spacing = range_diff / int(math.ceil(range_diff / target_spacing))
#     grid = np.arange(low + 0.5 * spacing, high, spacing)
# 
#     return grid, spacing


# Path: sncosmo/specmodel.py
import astropy.units as u
import numpy as np
from scipy.interpolate import splev, splrep
from .bandpasses import get_bandpass
from .constants import HC_ERG_AA, SPECTRUM_BANDFLUX_SPACING, FLAMBDA_UNIT
from .utils import integration_grid

    """A model spectrum, representing wavelength and spectral density values.

    Parameters
    ----------
    wave : list_like
        Wavelength values.
    flux : list_like
        Spectral flux density values.
    wave_unit : `~astropy.units.Unit`
        Unit on wavelength.
    unit : `~astropy.units.BaseUnit`
        For now, only units with flux density in energy (not photon counts).
    """

    def __init__(self, wave, flux, wave_unit=u.AA,
                 unit=(u.erg / u.s / u.cm**2 / u.AA)):
        self.wave = np.asarray(wave, dtype=np.float64)
        self.flux = np.asarray(flux, dtype=np.float64)
        if self.wave.shape != self.flux.shape:
            raise ValueError('shape of wavelength and flux must match')
        if self.wave.ndim != 1:
            raise ValueError('only 1-d arrays supported')

        # internally, wavelength is in Angstroms:
        if wave_unit != u.AA:
            self.wave = wave_unit.to(u.AA, self.wave, u.spectral())
        self._wave_unit = u.AA

        # internally, flux is in F_lambda:
        if unit != FLAMBDA_UNIT:

            self.flux = unit.to(FLAMBDA_UNIT, self.flux,