code: def detrend(x, deg=1):
      
      t=range(len(x))
      p = np.polyfit(t, x, deg)
      residual = x - np.polyval(p, t)
      return residual
docs: remove polynomial from data.
      used by autocorr_noise_id()
      
      Parameters
      ----------
      x: numpy.array
          time-series
      deg: int
          degree of polynomial to remove from x
          
      Returns
      -------
      x_detrended: numpy.array
          detrended time-series