code: def test_bad_proj():
      """Test dealing with bad projection application."""
      raw = read_raw_fif(raw_fname, preload=True)
      events = read_events(event_fname)
      picks = pick_types(
          raw.info,
          meg=True,
          stim=False,
          ecg=False,
          eog=False,
          exclude="bads",
      )
      picks = picks[2:18:3]
      _check_warnings(raw, events, picks)
      # still bad
      raw.pick([raw.ch_names[ii] for ii in picks])
      _check_warnings(raw, events)
      # "fixed"
      raw.info.normalize_proj()  # avoid projection warnings
      _check_warnings(raw, events, count=0)
      # eeg avg ref is okay
      raw = read_raw_fif(raw_fname, preload=True).pick(picks="eeg")
      raw.set_eeg_reference(projection=True)
      _check_warnings(raw, events, count=0)
      raw.info["bads"] = raw.ch_names[:10]
      _check_warnings(raw, events, count=0)
  
      raw = read_raw_fif(raw_fname)
      pytest.raises(ValueError, raw.del_proj, "foo")
      n_proj = len(raw.info["projs"])
      raw.del_proj(0)
      assert_equal(len(raw.info["projs"]), n_proj - 1)
      raw.del_proj()
      assert_equal(len(raw.info["projs"]), 0)
  
      # Ensure we deal with newer-style Neuromag projs properly, were getting:
      #
      #     Projection vector "PCA-v2" has magnitude 1.00 (should be unity),
      #     applying projector with 101/306 of the original channels available
      #     may be dangerous.
      raw = read_raw_fif(raw_fname).crop(0, 1)
      raw.set_eeg_reference(projection=True)
      raw.info["bads"] = ["MEG 0111"]
      meg_picks = pick_types(raw.info, meg=True, exclude=())
      ch_names = [raw.ch_names[pick] for pick in meg_picks]
      for p in raw.info["projs"][:-1]:
          data = np.zeros((1, len(ch_names)))
          idx = [
              ch_names.index(ch_name)
              for ch_name in p["data"]["col_names"]
          ]
          data[:, idx] = p["data"]["data"]
          p["data"].update(
              ncol=len(meg_picks), col_names=ch_names, data=data
          )
      # smoke test for no warnings during reg
      regularize(compute_raw_covariance(raw, verbose="error"), raw.info)
  
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 1 for calling a global function with example usage: test_bad_proj() without return types