code: def band_power(data, freq, scaling='power', n_fft=None, detrend=None,
                 array_out=False):
      if not array_out:
          power = {}
          peakf = {}
      else:
          power = zeros((data.number_of('chan')[0], 1))
          peakf = zeros((data.number_of('chan')[0], 1))
      if isinstance(data, ChanFreq):
          Sxx = data
      elif isinstance(data, ChanTime):
          Sxx = frequency(data, scaling=scaling, n_fft=n_fft, detrend=detrend)
      else:
          raise ValueError('Invalid data type')
      if detrend is None:
          if 'power' == scaling:
              detrend = 'linear'
          elif 'energy' == scaling:
              detrend = None
      sf = Sxx.axis['freq'][0]
      f_res = sf[1] - sf[0]
      if freq[0] is not None:
          idx_f1 = asarray([abs(x - freq[0]) for x in sf]).argmin()
      else:
          idx_f1 = 0
      if freq[1] is not None:
          idx_f2 = min(asarray([abs(x - freq[1]) for x in sf]).argmin() + 1,
                       len(sf) - 1)
      else:
          idx_f2 = len(sf) - 1
      for i, chan in enumerate(Sxx.axis['chan'][0]):
          s = Sxx(chan=chan)[0]
          pw = sum(s[idx_f1:idx_f2]) * f_res
          idx_peak = s[idx_f1:idx_f2].argmax()
          pf = sf[idx_f1:idx_f2][idx_peak]
          if array_out:
              power[i, 0] = pw
              peakf[i, 0] = pf
          else:
              power[chan] = pw
              peakf[chan] = pf
      return power, peakf