code: def test_otp_array():
      """Test the OTP algorithm on artificial data."""
      n_channels, n_time, sfreq = 10, 2000, 1000.0
      signal_f = 2.0
      rng = np.random.RandomState(0)
      data = rng.randn(n_channels, n_time)
      raw = RawArray(data, create_info(n_channels, sfreq, "eeg"))
      raw.info["bads"] = [raw.ch_names[0]]
      signal = np.sin(2 * np.pi * signal_f * raw.times)
      raw._data += signal
  
      # Check SNR
      def snr(data):
          """Check SNR according to the simulation model."""
          data_fft = rfft(data)
          freqs = rfftfreq(n_time, 1.0 / 1000.0)
          sidx = np.where(freqs == signal_f)[0][0]
          oidx = list(range(sidx)) + list(range(sidx + 1, len(freqs)))
          snr = (
              data_fft[:, sidx] * data_fft[:, sidx].conj()
          ).real.sum() / (
              data_fft[:, oidx] * data_fft[:, oidx].conj()
          ).real.sum()
          return snr
  
      orig_snr = snr(raw[:][0])
      with catch_logging() as log:
          raw_otp = oversampled_temporal_projection(
              raw, duration=2.0, verbose=True
          )
          otp_2_snr = snr(raw_otp[:][0])
          assert otp_2_snr > 3 + orig_snr
          assert "1 data chunk" in log.getvalue()
      with catch_logging() as log:
          raw_otp = oversampled_temporal_projection(
              raw, duration=1.2, verbose=True
          )
          otp_1p5_snr = snr(raw_otp[:][0])
          assert otp_1p5_snr > 3 + orig_snr
          assert "2 data chunks" in log.getvalue()
      with catch_logging() as log:
          raw_otp = oversampled_temporal_projection(
              raw, duration=1.0, verbose=True
          )
          otp_1_snr = snr(raw_otp[:][0])
          assert otp_1_snr > 2 + orig_snr
          assert "3 data chunks" in log.getvalue()
  
      # Pure-noise test
      raw._data -= signal
      raw_otp = oversampled_temporal_projection(raw, 2.0)
      reduction = np.linalg.norm(raw[:][0], axis=-1) / np.linalg.norm(
          raw_otp[:][0], axis=-1
      )
      assert reduction.min() > 9.0
  
      # Degenerate conditions
      raw = RawArray(
          np.zeros((200, 1000)), create_info(200, sfreq, "eeg")
      )
      with pytest.raises(ValueError):  # too short
          oversampled_temporal_projection(raw, duration=198.0 / sfreq)
      with pytest.raises(ValueError):  # duration invalid
          oversampled_temporal_projection(
              raw,
              duration=raw.times[-1] + 2.0 / raw.info["sfreq"],
              verbose=True,
          )
      raw._data[0, 0] = np.inf
      with pytest.raises(RuntimeError):  # too short
          oversampled_temporal_projection(raw, duration=1.0)
  
file_path: mne-python/mne/preprocessing/tests/test_otp.py
imports: import numpy
  import pytest
  from numpy.fft import rfft, rfftfreq
  from mne import create_info
  from mne._fiff.pick import _pick_data_channels
  from mne.datasets import testing
  from mne.io import RawArray, read_raw_fif
  from mne.preprocessing import oversampled_temporal_projection
  from mne.utils import catch_logging
label_desc: Use image node_id 1 for calling a global function with example usage: test_otp_array() and returns: snr