code: def test_compute_proj_ecg(short_raw, average):
      """Test computation of ECG SSP projectors."""
      raw = short_raw
  
      # For speed, let's not filter here (must also not reject then)
      with pytest.warns(RuntimeWarning, match="Attenuation"):
          projs, events = compute_proj_ecg(
              raw,
              n_mag=2,
              n_grad=2,
              n_eeg=2,
              ch_name="MEG 1531",
              bads=["MEG 2443"],
              average=average,
              avg_ref=True,
              no_proj=True,
              l_freq=None,
              h_freq=None,
              reject=None,
              tmax=dur_use,
              qrs_threshold=0.5,
              filter_length=1000,
          )
      assert len(projs) == 7
      # heart rate at least 0.5 Hz, but less than 3 Hz
      assert (
          events.shape[0] > 0.5 * dur_use
          and events.shape[0] < 3 * dur_use
      )
      ssp_ecg = [
          proj for proj in projs if proj["desc"].startswith("ECG")
      ]
      # check that the first principal component have a certain minimum
      ssp_ecg = [proj for proj in ssp_ecg if "PCA-01" in proj["desc"]]
      thresh_eeg, thresh_axial, thresh_planar = 0.9, 0.3, 0.1
      for proj in ssp_ecg:
          if "planar" in proj["desc"]:
              assert proj["explained_var"] > thresh_planar
          elif "axial" in proj["desc"]:
              assert proj["explained_var"] > thresh_axial
          elif "eeg" in proj["desc"]:
              assert proj["explained_var"] > thresh_eeg
      # XXX: better tests
  
      # without setting a bad channel, this should throw a warning
      with pytest.warns(RuntimeWarning, match="No good epochs found"):
          projs, events, drop_log = compute_proj_ecg(
              raw,
              n_mag=2,
              n_grad=2,
              n_eeg=2,
              ch_name="MEG 1531",
              bads=[],
              average=average,
              avg_ref=True,
              no_proj=True,
              l_freq=None,
              h_freq=None,
              tmax=dur_use,
              return_drop_log=True,
              # XXX can be removed once
              # XXX https://github.com/mne-tools/mne-python/issues/9273
              # XXX has been resolved:
              qrs_threshold=1e-15,
          )
      assert projs == []
      assert len(events) == len(drop_log)
  
file_path: mne-python/mne/preprocessing/tests/test_ssp.py
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal
  from mne import pick_types
  from mne._fiff.proj import activate_proj, make_projector
  from mne.datasets import testing
  from mne.io import read_raw_ctf, read_raw_fif
  from mne.preprocessing.ssp import compute_proj_ecg, compute_proj_eog
label_desc: Use image node_id 2 for calling a global function with example usage: test_compute_proj_ecg(short_raw, average) without return types