code: def test_plot_ica_properties():
      """Test plotting of ICA properties."""
      raw = _get_raw(preload=True).crop(0, 5)
      raw.add_proj([], remove_existing=True)
      with raw.info._unlock():
          raw.info["highpass"] = 1.0  # fake high-pass filtering
      events = make_fixed_length_events(raw)
      picks = _get_picks(raw)[:6]
      pick_names = [raw.ch_names[k] for k in picks]
      raw.pick(pick_names)
      reject = dict(grad=4000e-13, mag=4e-12)
  
      epochs = Epochs(
          raw,
          events[:3],
          event_id,
          tmin,
          tmax,
          baseline=(None, 0),
          preload=True,
      )
  
      ica = ICA(
          noise_cov=read_cov(cov_fname),
          n_components=2,
          max_iter=1,
          random_state=0,
      )
      with pytest.warns(RuntimeWarning, match="projection"):
          ica.fit(raw)
  
      # test _create_properties_layout
      fig, ax = _create_properties_layout()
      assert_equal(len(ax), 5)
      with pytest.raises(
          ValueError, match="specify both fig and figsize"
      ):
          _create_properties_layout(figsize=(2, 2), fig=fig)
  
      topoargs = dict(
          topomap_args={"res": 4, "contours": 0, "sensors": False}
      )
      with catch_logging() as log:
          ica.plot_properties(raw, picks=0, verbose="debug", **topoargs)
      log = log.getvalue()
      assert raw.ch_names[0] == "MEG 0113"
      assert "extrapolation mode local to mean" in log, log
      ica.plot_properties(
          epochs, picks=1, dB=False, plot_std=1.5, **topoargs
      )
      fig = ica.plot_properties(
          epochs,
          picks=1,
          image_args={"sigma": 1.5},
          topomap_args=dict(res=4, colorbar=True),
          psd_args={"fmax": 65.0},
          plot_std=False,
          log_scale=True,
          figsize=[4.5, 4.5],
          reject=reject,
      )[0]
  
      # test keypresses
      ax_labels = [ax.get_label() for ax in fig.axes]
  
      # test topomap change type
      ax = fig.axes[ax_labels.index("topomap")]
      assert ax.get_title() == "ICA001 (mag)"
      _fake_keypress(fig, "t")
      assert ax.get_title() == "ICA001 (grad)"
      _fake_keypress(fig, "t")
      assert ax.get_title() == "ICA001 (mag)"
  
      # test log scale
      ax = fig.axes[ax_labels.index("spectrum")]
      assert ax.get_xscale() == "log"
      _fake_keypress(fig, "l")
      assert ax.get_xscale() == "linear"
      _fake_keypress(fig, "l")
      assert ax.get_xscale() == "log"
  
      plt.close("all")
  
      with pytest.raises(TypeError, match="must be an instance"):
          ica.plot_properties(epochs, dB=list("abc"))
      with pytest.raises(TypeError, match="must be an instance"):
          ica.plot_properties(ica)
      with pytest.raises(TypeError, match="must be an instance"):
          ica.plot_properties([0.2])
      with pytest.raises(TypeError, match="must be an instance"):
          plot_ica_properties(epochs, epochs)
      with pytest.raises(TypeError, match="must be an instance"):
          ica.plot_properties(epochs, psd_args="not dict")
      with pytest.raises(TypeError, match="must be an instance"):
          ica.plot_properties(epochs, plot_std=[])
  
      fig, ax = plt.subplots(2, 3)
      ax = ax.ravel()[:-1]
      ica.plot_properties(epochs, picks=1, axes=ax, **topoargs)
      pytest.raises(
          TypeError,
          plot_ica_properties,
          epochs,
          ica,
          picks=[0, 1],
          axes=ax,
      )
      pytest.raises(
          ValueError, ica.plot_properties, epochs, axes="not axes"
      )
      plt.close("all")
  
      # Test merging grads.
      pick_names = raw.ch_names[:15:2] + raw.ch_names[1:15:2]
      raw = _get_raw(preload=True).pick(pick_names)
      raw.crop(0, 5)
      raw.info.normalize_proj()
      ica = ICA(random_state=0, max_iter=1)
      with pytest.warns(UserWarning, match="did not converge"):
          ica.fit(raw)
      ica.plot_properties(raw)
      plt.close("all")
  
      # Test handling of zeros
      ica = ICA(random_state=0, max_iter=1)
      epochs.pick(pick_names)
      with pytest.warns(UserWarning, match="did not converge"):
          ica.fit(epochs)
      epochs._data[0] = 0
      # Usually UserWarning: Infinite value .* for epo
      with _record_warnings():
          ica.plot_properties(epochs, **topoargs)
      plt.close("all")
  
      # Test Raw with annotations
      annot = Annotations(onset=[1], duration=[1], description=["BAD"])
      raw_annot = (
          _get_raw(preload=True).set_annotations(annot).crop(0, 8)
      )
      raw_annot.pick(np.arange(10))
      raw_annot.del_proj()
  
      with pytest.warns(UserWarning, match="did not converge"):
          ica.fit(raw_annot)
      # drop bad data segments
      fig = ica.plot_properties(raw_annot, picks=[0, 1], **topoargs)
      assert_equal(len(fig), 2)
      # don't drop
      ica.plot_properties(
          raw_annot, reject_by_annotation=False, **topoargs
      )
  
imports: import sys
  from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_equal
  from mne import Annotations, Epochs, make_fixed_length_events, pick_types, read_cov, read_events
  from mne.io import read_raw_fif
  from mne.preprocessing import ICA, create_ecg_epochs, create_eog_epochs
  from mne.utils import _record_warnings, catch_logging
  from mne.viz.ica import _create_properties_layout, plot_ica_properties
  from mne.viz.utils import _fake_click, _fake_keypress
label_desc: Use image node_id 6 for calling a global function with example usage: test_plot_ica_properties() without return types