code: def test_raw_rank_estimation(fname, ref_meg, scalings, tol_kind, tol):
      """Test raw rank estimation."""
      if ref_meg and scalings != "norm":
          # Adjust for CTF data (scale factors are quite different)
          if tol_kind == "relative":
              scalings = dict(mag=1.0)
          else:
              scalings = dict(mag=1e31)
      raw = read_raw_fif(fname)
      raw.crop(0, min(4.0, raw.times[-1])).load_data()
      out = _picks_by_type(raw.info, ref_meg=ref_meg, meg_combined=True)
      has_eeg = "eeg" in raw
      if has_eeg:
          (_, picks_meg), (_, picks_eeg) = out
      else:
          ((_, picks_meg),) = out
          picks_eeg = []
      n_meg = len(picks_meg)
      n_eeg = len(picks_eeg)
  
      if len(raw.info["proc_history"]) == 0:
          expected_rank = n_meg + n_eeg
      else:
          expected_rank = _get_rank_sss(raw.info) + n_eeg
      got_rank = _estimate_rank_raw(
          raw,
          scalings=scalings,
          with_ref_meg=ref_meg,
          tol=tol,
          tol_kind=tol_kind,
      )
      assert got_rank == expected_rank
      if "sss" in fname.name:
          raw.add_proj(compute_proj_raw(raw))
      raw.apply_proj()
      n_proj = len(raw.info["projs"])
      want_rank = expected_rank - (0 if "sss" in fname.name else n_proj)
      got_rank = _estimate_rank_raw(
          raw,
          scalings=scalings,
          with_ref_meg=ref_meg,
          tol=tol,
          tol_kind=tol_kind,
      )
      assert got_rank == want_rank
  
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 2 for calling a global function with example usage: test_raw_rank_estimation(fname, ref_meg, scalings, tol_kind, tol) without return types