def calculate_bin_edges(centers):
    """
    Calculate the edges of wavelength bins given the centers.

    The algorithm calculates bin edges as the midpoints between bin centers
    and treats the first and last bins as symmetric about their centers.

    Parameters
    ----------
    centers : array_like
        Sequence of bin centers. Must be 1D and have at least two values.

    Returns
    -------
    edges : ndarray
        Array of bin edges. Will be 1D and have one more value
        than ``centers``.

    """
    centers = np.asanyarray(centers)

    if centers.ndim != 1:
        raise ValueError('centers input array must be 1D.')

    if centers.size < 2:
        raise ValueError('centers input must have at least two values.')

    edges = np.empty(centers.size + 1)

    edges[1:-1] = (centers[1:] + centers[:-1]) / 2.

    #compute the first and last by making them symmetric
    edges[0] = centers[0] - (edges[1] - centers[0])
    edges[-1] = centers[-1] + (centers[-1] - edges[-2])

    return edges