def get_average_fluxden(input_spec, dispersion, width=10, redshift=0):
    """
    Calculate the average flux density of a spectrum in a window centered at
    the specified dispersion and with a given width.

    The central dispersion and width can be specified in the rest-frame and
    then are redshifted to the observed frame using the redsh keyword argument.

    Warning: this function currently only works for spectra in wavelength
    units. For spectra in frequency units the conversion to rest-frame will
    be incorrect.

    :param input_spec: Input spectrum
    :type input_spec: sculptor.speconed.SpecOneD
    :param dispersion: Central dispersion
    :type dispersion: float
    :param width: Width of the dispersion window
    :type width: float
    :param redshift: Redshift argument to redshift the dispersion window into
        the observed frame.
    :type redshift: float
    :return: Average flux density
    :rtype: astropy.units.Quantity

    """

    disp_range = [(dispersion - width / 2.)*(1.+redshift),
                  (dispersion + width / 2.)*(1.+redshift)]

    unit = input_spec.fluxden_unit

    return input_spec.average_fluxden(dispersion_range=disp_range) * unit