code: def test_make_dics_rank(_load_forward, idx, whiten):
      """Test making DICS beamformer filters with rank param."""
      _, fwd_surf, fwd_fixed, _ = _load_forward
      epochs, _, csd, _, label, _, _ = _simulate_data(fwd_fixed, idx)
      if whiten:
          noise_csd, want_rank = _make_rand_csd(epochs.info, csd)
          kind = "mag + grad"
      else:
          noise_csd = None
          epochs.pick(picks="grad")
          want_rank = len(epochs.ch_names)
          assert want_rank == 41
          kind = "grad"
  
      with catch_logging() as log:
          filters = make_dics(
              epochs.info,
              fwd_surf,
              csd,
              label=label,
              noise_csd=noise_csd,
              verbose=True,
          )
      log = log.getvalue()
      assert f"Estimated rank ({kind}): {want_rank}" in log, log
      stc, _ = apply_dics_csd(csd, filters)
      other_rank = want_rank - 1  # shouldn't make a huge difference
      use_rank = dict(meg=other_rank)
      if not whiten:
          # XXX it's a bug that our rank functions don't treat "meg"
          # properly here...
          use_rank["grad"] = use_rank.pop("meg")
      with catch_logging() as log:
          filters_2 = make_dics(
              epochs.info,
              fwd_surf,
              csd,
              label=label,
              noise_csd=noise_csd,
              rank=use_rank,
              verbose=True,
          )
      log = log.getvalue()
      assert (
          f"Computing rank from covariance with rank={use_rank}" in log
      ), log
      stc_2, _ = apply_dics_csd(csd, filters_2)
      corr = np.corrcoef(stc_2.data.ravel(), stc.data.ravel())[0, 1]
      assert 0.8 < corr < 0.999999
  
      # degenerate conditions
      if whiten:
          # make rank deficient
          data = noise_csd.get_data(0.0)
          data[0] = data[:0] = 0
          noise_csd._data[:, 0] = _sym_mat_to_vector(data)
          with pytest.raises(
              ValueError, match="meg data rank.*the noise rank"
          ):
              filters = make_dics(
                  epochs.info,
                  fwd_surf,
                  csd,
                  label=label,
                  noise_csd=noise_csd,
                  verbose=True,
              )
  
imports: import copy
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less
  import mne
  from mne import pick_types
  from mne._fiff.constants import FIFF
  from mne._fiff.pick import pick_info
  from mne.beamformer import Beamformer, apply_dics, apply_dics_csd, apply_dics_epochs, apply_dics_tfr_epochs, make_dics, read_beamformer
  from mne.beamformer._compute_beamformer import _prepare_beamformer_input
  from mne.beamformer._dics import _prepare_noise_csd
  from mne.beamformer.tests.test_lcmv import _assert_weight_norm
  from mne.datasets import testing
  from mne.io import read_info
  from mne.proj import compute_proj_evoked, make_projector
  from mne.surface import _compute_nearest
  from mne.time_frequency import CrossSpectralDensity, EpochsTFR, csd_morlet, csd_tfr
  from mne.time_frequency.csd import _sym_mat_to_vector
  from mne.transforms import apply_trans, invert_transform
  from mne.utils import catch_logging, object_diff
label_desc: Use image node_id 16 for calling a global function with example usage: test_make_dics_rank(_load_forward, idx, whiten) without return types