# 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
    def bandflux(self, band):
        """Perform synthentic photometry in a given bandpass.

        The bandpass transmission is interpolated onto the wavelength grid
        of the spectrum. The result is a weighted sum of the spectral flux
        density values (weighted by transmission values).

        Parameters
        ----------
        band : Bandpass or str
            Bandpass object or name of registered bandpass.

        Returns
        -------
        float
            Total flux in ph/s/cm^2.
        """
        band = get_bandpass(band)

        # Check that bandpass wavelength range is fully contained in spectrum
        # wavelength range.
        if (band.minwave() < self.wave[0] or band.maxwave() > self.wave[-1]):
            raise ValueError('bandpass {0!r:s} [{1:.6g}, .., {2:.6g}] '
                             'outside spectral range [{3:.6g}, .., {4:.6g}]'
                             .format(band.name, band.minwave(), band.maxwave(),
                                     self.wave[0], self.wave[-1]))

        # Set up wavelength grid. Spacing (dwave) evenly divides the bandpass,
        # closest to 5 angstroms without going over.
        wave, dwave = integration_grid(band.minwave(), band.maxwave(),

# 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

    def bandflux(self, band):
        """Perform synthentic photometry in a given bandpass.

        The bandpass transmission is interpolated onto the wavelength grid
        of the spectrum. The result is a weighted sum of the spectral flux
        density values (weighted by transmission values).

        Parameters
        ----------
        band : Bandpass or str
            Bandpass object or name of registered bandpass.

        Returns
        -------
        float
            Total flux in ph/s/cm^2.
        """
        band = get_bandpass(band)

        # Check that bandpass wavelength range is fully contained in spectrum
        # wavelength range.
        if (band.minwave() < self.wave[0] or band.maxwave() > self.wave[-1]):
            raise ValueError('bandpass {0!r:s} [{1:.6g}, .., {2:.6g}] '
                             'outside spectral range [{3:.6g}, .., {4:.6g}]'
                             .format(band.name, band.minwave(), band.maxwave(),
                                     self.wave[0], self.wave[-1]))

        # Set up wavelength grid. Spacing (dwave) evenly divides the bandpass,
        # closest to 5 angstroms without going over.
        wave, dwave = integration_grid(band.minwave(), band.maxwave(),

                                       SPECTRUM_BANDFLUX_SPACING)