def average_spectrogram(timeseries, method_func, stride, *args, **kwargs):
<EOL>try:<EOL><INDENT>timeseries, other = timeseries<EOL><DEDENT>except ValueError:<EOL><INDENT>timeseries = timeseries<EOL>other = None<EOL><DEDENT>from ...spectrogram import Spectrogram<EOL>nproc = kwargs.pop('<STR_LIT>', <NUM_LIT:1>)<EOL>epoch = timeseries.t0.value<EOL>nstride = seconds_to_samples(stride, timeseries.sample_rate)<EOL>kwargs['<STR_LIT>'] = kwargs.pop('<STR_LIT>', stride) or stride<EOL>normalize_fft_params(timeseries, kwargs=kwargs, func=method_func)<EOL>nfft = kwargs['<STR_LIT>']<EOL>noverlap = kwargs['<STR_LIT>']<EOL>if nstride > timeseries.size:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if nfft > nstride:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if noverlap >= nfft:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>def _psd(series):<EOL><INDENT>"""<STR_LIT>"""<EOL>psd_ = _psdn(series, method_func, *args, **kwargs)<EOL>del psd_.epoch  <EOL>return psd_<EOL><DEDENT>tschunks = _chunk_timeseries(timeseries, nstride, noverlap)<EOL>if other is not None:<EOL><INDENT>otherchunks = _chunk_timeseries(other, nstride, noverlap)<EOL>tschunks = zip(tschunks, otherchunks)<EOL><DEDENT>psds = mp_utils.multiprocess_with_queues(nproc, _psd, tschunks)<EOL>return Spectrogram.from_spectra(*psds, epoch=epoch, dt=stride)<EOL>
Generate an average spectrogram using a method function

    Each time bin of the resulting spectrogram is a PSD generated using
    the method_func