code: def test_maxfilter_get_rank(
      n_proj, fname, rank_orig, meg, tol_kind, tol
  ):
      """Test maxfilter rank lookup."""
      raw = read_raw_fif(fname).crop(0, 5).load_data().pick("meg")
      assert raw.info["projs"] == []
      mf = raw.info["proc_history"][0]["max_info"]
      assert mf["sss_info"]["nfree"] == rank_orig
  
      assert compute_rank(raw, "info")["meg"] == rank_orig
      assert (
          compute_rank(raw.copy().pick("grad"), "info")["grad"]
          == rank_orig
      )
      assert (
          compute_rank(raw.copy().pick("mag"), "info")["mag"]
          == rank_orig
      )
  
      mult = 1 + (meg == "separate")
      rank = rank_orig - mult * n_proj
      if n_proj > 0:
          # Let's do some projection
          raw.add_proj(
              compute_proj_raw(
                  raw,
                  n_mag=n_proj,
                  n_grad=n_proj,
                  meg=meg,
                  verbose=True,
              )
          )
      raw.apply_proj()
      data_orig = raw[:][0]
  
      # degenerate cases
      with pytest.raises(ValueError, match="tol must be"):
          _estimate_rank_raw(raw, tol="foo")
      with pytest.raises(TypeError, match="must be a string or a"):
          _estimate_rank_raw(raw, tol=None)
  
      allowed_rank = [rank_orig if meg == "separate" else rank]
      if fname == mf_fif_fname:
          # Here we permit a -1 because for mf_fif_fname we miss by 1, which is
          # probably acceptable. If we use the entire duration instead of 5 s
          # this problem goes away, but the test is much slower.
          allowed_rank.append(allowed_rank[0] - 1)
  
      # multiple ways of hopefully getting the same thing
      # default tol=1e-4, scalings='norm'
      rank_new = _estimate_rank_raw(raw, tol_kind=tol_kind)
      assert rank_new in allowed_rank
  
      rank_new = _estimate_rank_raw(raw, tol=tol, tol_kind=tol_kind)
      if (
          fname == mf_fif_fname
          and tol_kind == "relative"
          and tol != "auto"
      ):
          pass  # does not play nicely with row norms of _estimate_rank_raw
      else:
          assert rank_new in allowed_rank
      rank_new = _estimate_rank_raw(
          raw, scalings=dict(), tol=tol, tol_kind=tol_kind
      )
      assert rank_new in allowed_rank
      scalings = dict(grad=1e13, mag=1e15)
      rank_new = _compute_rank_int(
          raw,
          None,
          scalings=scalings,
          tol=tol,
          tol_kind=tol_kind,
          verbose="debug",
      )
      assert rank_new in allowed_rank
      # XXX default scalings mis-estimate sometimes :(
      if fname == hp_fif_fname:
          allowed_rank.append(allowed_rank[0] - 2)
      rank_new = _compute_rank_int(
          raw, None, tol=tol, tol_kind=tol_kind, verbose="debug"
      )
      assert rank_new in allowed_rank
      del allowed_rank
  
      rank_new = _compute_rank_int(raw, "info")
      assert rank_new == rank
      assert_array_equal(raw[:][0], data_orig)
  
file_path: mne-python/mne/tests/test_rank.py
imports: import itertools
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from mne import compute_raw_covariance, make_fixed_length_epochs, pick_info, pick_types, read_cov, read_evokeds
  from mne._fiff.pick import _picks_by_type
  from mne._fiff.proj import _has_eeg_average_ref_proj
  from mne.cov import prepare_noise_cov
  from mne.datasets import testing
  from mne.io import read_raw_fif
  from mne.proj import compute_proj_raw
  from mne.rank import _compute_rank_int, _estimate_rank_raw, _get_rank_sss, compute_rank, estimate_rank
label_desc: Use image node_id 5 for calling a global function with example usage: test_maxfilter_get_rank(n_proj, fname, rank_orig, meg, tol_kind, tol) without return types