code: def _mt_spectrum_remove(
      x,
      sfreq,
      line_freqs,
      notch_widths,
      window_fun,
      threshold,
      get_thresh,
  ):
      """Use MT-spectrum to remove line frequencies.
  
      Based on Chronux. If line_freqs is specified, all freqs within notch_width
      of each line_freq is set to zero.
      """
      from .time_frequency.multitaper import _mt_spectra
  
      assert x.ndim == 1
      if x.shape[-1] != window_fun.shape[-1]:
          window_fun, threshold = get_thresh(x.shape[-1])
      # drop the even tapers
      n_tapers = len(window_fun)
      tapers_odd = np.arange(0, n_tapers, 2)
      tapers_even = np.arange(1, n_tapers, 2)
      tapers_use = window_fun[tapers_odd]
  
      # sum tapers for (used) odd prolates across time (n_tapers, 1)
      H0 = np.sum(tapers_use, axis=1)
  
      # sum of squares across tapers (1, )
      H0_sq = sum_squared(H0)
  
      # make "time" vector
      rads = 2 * np.pi * (np.arange(x.size) / float(sfreq))
  
      # compute mt_spectrum (returning n_ch, n_tapers, n_freq)
      x_p, freqs = _mt_spectra(x[np.newaxis, :], window_fun, sfreq)
  
      # sum of the product of x_p and H0 across tapers (1, n_freqs)
      x_p_H0 = np.sum(
          x_p[:, tapers_odd, :] * H0[np.newaxis, :, np.newaxis], axis=1
      )
  
      # resulting calculated amplitudes for all freqs
      A = x_p_H0 / H0_sq
  
      if line_freqs is None:
          # figure out which freqs to remove using F stat
  
          # estimated coefficient
          x_hat = A * H0[:, np.newaxis]
  
          # numerator for F-statistic
          num = (n_tapers - 1) * (A * A.conj()).real * H0_sq
          # denominator for F-statistic
          den = np.sum(
              np.abs(x_p[:, tapers_odd, :] - x_hat) ** 2, 1
          ) + np.sum(np.abs(x_p[:, tapers_even, :]) ** 2, 1)
          den[den == 0] = np.inf
          f_stat = num / den
  
          # find frequencies to remove
          indices = np.where(f_stat > threshold)[1]
          rm_freqs = freqs[indices]
      else:
          # specify frequencies
          indices_1 = np.unique(
              [np.argmin(np.abs(freqs - lf)) for lf in line_freqs]
          )
          indices_2 = [
              np.logical_and(
                  freqs > lf - nw / 2.0, freqs < lf + nw / 2.0
              )
              for lf, nw in zip(line_freqs, notch_widths)
          ]
          indices_2 = np.where(np.any(np.array(indices_2), axis=0))[0]
          indices = np.unique(np.r_[indices_1, indices_2])
          rm_freqs = freqs[indices]
  
      fits = list()
      for ind in indices:
          c = 2 * A[0, ind]
          fit = np.abs(c) * np.cos(freqs[ind] * rads + np.angle(c))
          fits.append(fit)
  
      if len(fits) == 0:
          datafit = 0.0
      else:
          # fitted sinusoids are summed, and subtracted from data
          datafit = np.sum(fits, axis=0)
  
      return x - datafit, rm_freqs
  
imports: from collections import Counter
  from copy import deepcopy
  from functools import partial
  from math import gcd
  import numpy
  from scipy import fft, signal
  from scipy.stats import f
  from ._fiff.pick import _picks_to_idx
  from ._ola import _COLA
  from .cuda import _fft_multiply_repeated, _fft_resample, _setup_cuda_fft_multiply_repeated, _setup_cuda_fft_resample, _smart_pad
  from .parallel import parallel_func
  from .utils import _check_option, _check_preload, _ensure_int, _pl, _validate_type, logger, sum_squared, verbose, warn
label_desc: Use image node_id 21 for calling a global function with example usage: _mt_spectrum_remove(x, sfreq, line_freqs, notch_widths, window_fun, threshold, get_thresh) and returns: unknown,  rm_freqs