code: def test_cov_estimation_with_triggers(rank, tmp_path):
      """Test estimation from raw with triggers."""
      raw = read_raw_fif(raw_fname)
      raw.set_eeg_reference(projection=True).load_data()
      events = find_events(raw, stim_channel="STI 014")
      event_ids = [1, 2, 3, 4]
      reject = dict(grad=10000e-13, mag=4e-12, eeg=80e-6, eog=150e-6)
  
      # cov with merged events and keep_sample_mean=True
      events_merged = merge_events(events, event_ids, 1234)
      epochs = Epochs(
          raw,
          events_merged,
          1234,
          tmin=-0.2,
          tmax=0,
          baseline=(-0.2, -0.1),
          proj=True,
          reject=reject,
          preload=True,
      )
  
      cov = compute_covariance(epochs, keep_sample_mean=True)
      cov_km = read_cov(cov_km_fname)
      # adjust for nfree bug
      cov_km["nfree"] -= 1
      _assert_cov(cov, cov_km)
  
      # Test with tmin and tmax (different but not too much)
      cov_tmin_tmax = compute_covariance(epochs, tmin=-0.19, tmax=-0.01)
      assert np.all(cov.data != cov_tmin_tmax.data)
      err = np.linalg.norm(
          cov.data - cov_tmin_tmax.data
      ) / np.linalg.norm(cov_tmin_tmax.data)
      assert err < 0.05
  
      # cov using a list of epochs and keep_sample_mean=True
      epochs = [
          Epochs(
              raw,
              events,
              ev_id,
              tmin=-0.2,
              tmax=0,
              baseline=(-0.2, -0.1),
              proj=True,
              reject=reject,
          )
          for ev_id in event_ids
      ]
      cov2 = compute_covariance(epochs, keep_sample_mean=True)
      assert_array_almost_equal(cov.data, cov2.data)
      assert cov.ch_names == cov2.ch_names
  
      # cov with keep_sample_mean=False using a list of epochs
      cov = compute_covariance(epochs, keep_sample_mean=False)
      assert cov_km.nfree == cov.nfree
      _assert_cov(cov, read_cov(cov_fname), nfree=False)
  
      method_params = {"empirical": {"assume_centered": False}}
      pytest.raises(
          ValueError,
          compute_covariance,
          epochs,
          keep_sample_mean=False,
          method_params=method_params,
      )
      pytest.raises(
          ValueError,
          compute_covariance,
          epochs,
          keep_sample_mean=False,
          method="shrunk",
          rank=rank,
      )
  
      # test IO when computation done in Python
      cov.save(tmp_path / "test-cov.fif")  # test saving
      cov_read = read_cov(tmp_path / "test-cov.fif")
      _assert_cov(cov, cov_read, 1e-5)
  
      # cov with list of epochs with different projectors
      epochs = [
          Epochs(
              raw,
              events[:1],
              None,
              tmin=-0.2,
              tmax=0,
              baseline=(-0.2, -0.1),
              proj=True,
          ),
          Epochs(
              raw,
              events[:1],
              None,
              tmin=-0.2,
              tmax=0,
              baseline=(-0.2, -0.1),
              proj=False,
          ),
      ]
      # these should fail
      pytest.raises(ValueError, compute_covariance, epochs)
      pytest.raises(ValueError, compute_covariance, epochs, projs=None)
      # these should work, but won't be equal to above
      with pytest.warns(RuntimeWarning, match="Too few samples"):
          cov = compute_covariance(
              epochs, projs=epochs[0].info["projs"]
          )
      with pytest.warns(RuntimeWarning, match="Too few samples"):
          cov = compute_covariance(epochs, projs=[])
  
      # test new dict support
      epochs = Epochs(
          raw,
          events,
          dict(a=1, b=2, c=3, d=4),
          tmin=-0.01,
          tmax=0,
          proj=True,
          reject=reject,
          preload=True,
      )
      with pytest.warns(RuntimeWarning, match="Too few samples"):
          compute_covariance(epochs)
      with pytest.warns(RuntimeWarning, match="Too few samples"):
          compute_covariance(epochs, projs=[])
      pytest.raises(TypeError, compute_covariance, epochs, projs="foo")
      pytest.raises(
          TypeError, compute_covariance, epochs, projs=["foo"]
      )
  
imports: import itertools
  import sys
  from inspect import signature
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from mne import Epochs, compute_covariance, compute_proj_raw, compute_rank, compute_raw_covariance, create_info, find_events, make_ad_hoc_cov, make_fixed_length_events, merge_events, pick_channels_cov, pick_info, pick_types, read_cov, read_evokeds, write_cov
  from mne._fiff.pick import _DATA_CH_TYPES_SPLIT
  from mne.channels import equalize_channels
  from mne.cov import _auto_low_rank_model, _regularized_covariance, compute_whitener, prepare_noise_cov, regularize, whiten_evoked
  from mne.datasets import testing
  from mne.fixes import _safe_svd
  from mne.io import RawArray, read_info, read_raw_ctf, read_raw_fif
  from mne.preprocessing import maxwell_filter
  from mne.rank import _compute_rank_int
  from mne.utils import _record_warnings, assert_snr, catch_logging
label_desc: Use image node_id 10 for calling a global function with example usage: test_cov_estimation_with_triggers(rank, tmp_path) without return types