def pixel_range(bins, waverange, round='round'):
    """Returns the number of wavelength bins within ``waverange``.

    Parameters
    ----------
    bins : ndarray
        Wavelengths of pixel centers.
        Must be in the same units as ``waverange``.

    waverange : array_like
        A sequence containing the wavelength range of interest. Only the
        first and last elements are used. Assumed to be in increasing order.
        Must be in the same units as ``bins``.

    round : {'round', 'min', 'max', `None`}, optional
        How to deal with pixels at the edges of the wavelength range. All
        of the options, except `None`, will return an integer number of pixels.
        Defaults to ``'round'``.

            * ``'round'`` - Wavelength ends that fall in the middle of a
              pixel are counted if more than half of the pixel is within
              ``waverange``. Ends that fall in the center of a pixel are
              rounded up to the nearest pixel edge.
            * ``'min'`` - Only pixels wholly within ``waverange`` are counted.
            * ``'max'`` - End pixels that are within ``waverange`` by any
              margin are counted.
            * `None` - The exact number of encompassed pixels, including
              fractional pixels, is returned.

    Returns
    -------
    num : int or float
        Number of wavelength bins within ``waverange``.

    Raises
    ------
    ValueError
        If ``round`` is not an allowed value.

    pysynphot.exceptions.OverlapError
        If ``waverange`` exceeds the bounds of ``bins``.

    """
    # make sure that the round keyword is valid
    if round not in ('round','min','max',None):
        raise ValueError("round keyword must be one of ('round','ciel','floor',None)")

    wave1 = waverange[0]
    wave2 = waverange[-1]

    # make sure the specified waverange is within our .binset
    minwave = bins[0] - (bins[0:2].mean() - bins[0])
    if wave1 < minwave:
        raise exceptions.OverlapError("Lower bound of waverange is outside of binset. Min = %f" % minwave)

    maxwave = bins[-1] + (bins[-1] - bins[-2:].mean())
    if wave2 > maxwave:
        raise exceptions.OverlapError("Upper bound of waverange is outside of binset. Max = %f" % maxwave)

    # if the wavelength ends are the same return 0
    if wave1 == wave2:
        return 0

    # find where the wavelength endpoints fall.
    if round == 'round':
        ind1 = bins.searchsorted(wave1, side='right')
        ind2 = bins.searchsorted(wave2, side='right')

        num = ind2 - ind1

    elif round == 'min':
        ind1 = bins.searchsorted(wave1, side='left')
        ind2 = bins.searchsorted(wave2, side='left')

        # for ind1, figure out if pixel ind1 is wholly included or not.
        # do this by figuring out where wave1 is between ind1 and ind1-1.
        frac = (bins[ind1] - wave1) / (bins[ind1] - bins[ind1-1])

        if frac < 0.5:
            # ind1 is only partially included
            ind1 += 1

        # similar but reversed procedure for ind2
        frac = (wave2 - bins[ind2-1]) / (bins[ind2] - bins[ind2-1])

        if frac < 0.5:
            # ind2 is only partially included
            ind2 -= 1

        num = ind2 - ind1

    elif round == 'max':
        ind1 = bins.searchsorted(wave1, side='left')
        ind2 = bins.searchsorted(wave2, side='left')

        # for ind1, figure out if pixel ind1-1 is partially included or not.
        # do this by figuring out where wave1 is between ind1 and ind1-1.
        frac = (wave1 - bins[ind1-1]) / (bins[ind1] - bins[ind1-1])

        if frac < 0.5:
            # ind1 is partially included
            ind1 -= 1

        # similar but reversed procedure for ind2
        frac = (bins[ind2] - wave2) / (bins[ind2] - bins[ind2-1])

        if frac < 0.5:
            # ind2 is partially included
            ind2 += 1

        num = ind2 - ind1

    elif round is None:
        ind1 = bins.searchsorted(wave1, side='left')
        ind2 = bins.searchsorted(wave2, side='left')

        # calculate fractional indices
        frac1 = ind1 - (bins[ind1] - wave1) / (bins[ind1] - bins[ind1-1])

        frac2 = ind2 - (bins[ind2] - wave2) / (bins[ind2] - bins[ind2-1])

        num = frac2 - frac1

    return num
Returns the number of wavelength bins within ``waverange``.

    Parameters
    ----------
    bins : ndarray
        Wavelengths of pixel centers.
        Must be in the same units as ``waverange``.

    waverange : array_like
        A sequence containing the wavelength range of interest. Only the
        first and last elements are used. Assumed to be in increasing order.
        Must be in the same units as ``bins``.

    round : {'round', 'min', 'max', `None`}, optional
        How to deal with pixels at the edges of the wavelength range. All
        of the options, except `None`, will return an integer number of pixels.
        Defaults to ``'round'``.

            * ``'round'`` - Wavelength ends that fall in the middle of a
              pixel are counted if more than half of the pixel is within
              ``waverange``. Ends that fall in the center of a pixel are
              rounded up to the nearest pixel edge.
            * ``'min'`` - Only pixels wholly within ``waverange`` are counted.
            * ``'max'`` - End pixels that are within ``waverange`` by any
              margin are counted.
            * `None` - The exact number of encompassed pixels, including
              fractional pixels, is returned.

    Returns
    -------
    num : int or float
        Number of wavelength bins within ``waverange``.

    Raises
    ------
    ValueError
        If ``round`` is not an allowed value.

    pysynphot.exceptions.OverlapError
        If ``waverange`` exceeds the bounds of ``bins``.