code: def test_compute_proj_epochs(tmp_path):
      """Test SSP computation on epochs."""
      event_id, tmin, tmax = 1, -0.2, 0.3
  
      raw = read_raw_fif(raw_fname, preload=True)
      events = read_events(event_fname)
      bad_ch = "MEG 2443"
      picks = pick_types(
          raw.info,
          meg=True,
          eeg=False,
          stim=False,
          eog=False,
          exclude=[],
      )
      epochs = Epochs(
          raw,
          events,
          event_id,
          tmin,
          tmax,
          picks=picks,
          baseline=None,
          proj=False,
      )
  
      evoked = epochs.average()
      projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0)
      write_proj(tmp_path / "test-proj.fif.gz", projs)
      for p_fname in [
          proj_fname,
          proj_gz_fname,
          tmp_path / "test-proj.fif.gz",
      ]:
          projs2 = read_proj(p_fname)
          assert len(projs) == len(projs2)
  
          for p1, p2 in zip(projs, projs2):
              assert p1["desc"] == p2["desc"]
              assert p1["data"]["col_names"] == p2["data"]["col_names"]
              assert p1["active"] == p2["active"]
              # compare with sign invariance
              p1_data = p1["data"]["data"] * np.sign(
                  p1["data"]["data"][0, 0]
              )
              p2_data = p2["data"]["data"] * np.sign(
                  p2["data"]["data"][0, 0]
              )
              if bad_ch in p1["data"]["col_names"]:
                  bad = p1["data"]["col_names"].index("MEG 2443")
                  mask = np.ones(p1_data.size, dtype=bool)
                  mask[bad] = False
                  p1_data = p1_data[:, mask]
                  p2_data = p2_data[:, mask]
              corr = np.corrcoef(p1_data, p2_data)[0, 1]
              assert_array_almost_equal(corr, 1.0, 5)
              if p2["explained_var"]:
                  assert isinstance(p2["explained_var"], float)
                  assert_array_almost_equal(
                      p1["explained_var"], p2["explained_var"]
                  )
  
      # test that you can compute the projection matrix
      projs = activate_proj(projs)
      proj, nproj, U = make_projector(projs, epochs.ch_names, bads=[])
  
      assert nproj == 2
      assert U.shape[1] == 2
  
      # test that you can save them
      with epochs.info._unlock():
          epochs.info["projs"] += projs
      evoked = epochs.average()
      evoked.save(tmp_path / "foo-ave.fif")
  
      projs = read_proj(proj_fname)
  
      projs_evoked = compute_proj_evoked(
          evoked, n_grad=1, n_mag=1, n_eeg=0
      )
      assert len(projs_evoked) == 2
      # XXX : test something
  
      # test parallelization
      projs = compute_proj_epochs(
          epochs, n_grad=1, n_mag=1, n_eeg=0, desc_prefix="foobar"
      )
      assert all("foobar" in x["desc"] for x in projs)
      projs = activate_proj(projs)
      proj_par, _, _ = make_projector(projs, epochs.ch_names, bads=[])
      assert_allclose(proj, proj_par, rtol=1e-8, atol=1e-16)
  
      # test warnings on bad filenames
      proj_badname = tmp_path / "test-bad-name.fif.gz"
      with pytest.warns(RuntimeWarning, match="-proj.fif"):
          write_proj(proj_badname, projs)
      with pytest.warns(RuntimeWarning, match="-proj.fif"):
          read_proj(proj_badname)
  
      # bad inputs
      fname = tmp_path / "out-proj.fif"
      with pytest.raises(TypeError, match="projs"):
          write_proj(fname, "foo")
      with pytest.raises(TypeError, match=r"projs\[0\] must be .*"):
          write_proj(fname, ["foo"], overwrite=True)
  
imports: import copy
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_equal
  from scipy import linalg
  from mne import Epochs, compute_proj_epochs, compute_proj_evoked, compute_proj_raw, compute_raw_covariance, convert_forward_solution, create_info, pick_types, read_events, read_forward_solution, read_source_estimate, sensitivity_map
  from mne._fiff.proj import _EEG_AVREF_PICK_DICT, _needs_eeg_average_ref_proj, activate_proj, make_projector, setup_proj
  from mne.cov import compute_whitener, regularize
  from mne.datasets import testing
  from mne.io import RawArray, read_raw_fif
  from mne.preprocessing import maxwell_filter
  from mne.proj import _has_eeg_average_ref_proj, make_eeg_average_ref_proj, read_proj, write_proj
  from mne.rank import _compute_rank_int
  from mne.utils import _record_warnings
label_desc: Use image node_id 4 for calling a global function with example usage: test_compute_proj_epochs(tmp_path) without return types