code: def average_spectrogram(timeseries, method_func, stride, *args, **kwargs):
      
      # unpack CSD TimeSeries pair, or single timeseries
      try:
          timeseries, other = timeseries
      except ValueError:
          timeseries = timeseries
          other = None
  
      from ...spectrogram import Spectrogram
  
      nproc = kwargs.pop('nproc', 1)
  
      # get params
      epoch = timeseries.t0.value
      nstride = seconds_to_samples(stride, timeseries.sample_rate)
      kwargs['fftlength'] = kwargs.pop('fftlength', stride) or stride
      normalize_fft_params(timeseries, kwargs=kwargs, func=method_func)
      nfft = kwargs['nfft']
      noverlap = kwargs['noverlap']
  
      # sanity check parameters
      if nstride > timeseries.size:
          raise ValueError("stride cannot be greater than the duration of "
                           "this TimeSeries")
      if nfft > nstride:
          raise ValueError("fftlength cannot be greater than stride")
      if noverlap >= nfft:
          raise ValueError("overlap must be less than fftlength")
  
      # set up single process Spectrogram method
      def _psd(series):
          """Calculate a single PSD for a spectrogram
          """
          psd_ = _psdn(series, method_func, *args, **kwargs)
          del psd_.epoch  # fixes Segmentation fault (no idea why it faults)
          return psd_
  
      # define chunks
      tschunks = _chunk_timeseries(timeseries, nstride, noverlap)
      if other is not None:
          otherchunks = _chunk_timeseries(other, nstride, noverlap)
          tschunks = zip(tschunks, otherchunks)
  
      # calculate PSDs
      psds = mp_utils.multiprocess_with_queues(nproc, _psd, tschunks)
  
      # recombobulate PSDs into a spectrogram
      return Spectrogram.from_spectra(*psds, epoch=epoch, dt=stride)
docs: Generate an average spectrogram using a method function
  
      Each time bin of the resulting spectrogram is a PSD generated using
      the method_func