code: def test_fine_calibration():
      """Test Maxwell filter fine calibration."""
      # Load testing data (raw, SSS std origin, SSS non-standard origin)
      raw = read_crop(raw_fname, (0.0, 1.0))
      sss_fine_cal = read_crop(sss_fine_cal_fname)
  
      # Test 1D SSS fine calibration
      with use_coil_def(elekta_def_fname):
          with catch_logging() as log:
              raw_sss = maxwell_filter(
                  raw,
                  calibration=fine_cal_fname,
                  origin=mf_head_origin,
                  regularize=None,
                  bad_condition="ignore",
                  verbose=True,
              )
      log = log.getvalue()
      assert "Using fine calibration" in log
      assert fine_cal_fname.stem in log
      assert_meg_snr(
          raw_sss, sss_fine_cal, 1.3, 180
      )  # similar to MaxFilter
      py_cal = raw_sss.info["proc_history"][0]["max_info"]["sss_cal"]
      assert py_cal is not None
      assert len(py_cal) > 0
      mf_cal = sss_fine_cal.info["proc_history"][0]["max_info"][
          "sss_cal"
      ]
      # we identify these differently
      mf_cal["cal_chans"][mf_cal["cal_chans"][:, 1] == 3022, 1] = 3024
      assert_allclose(py_cal["cal_chans"], mf_cal["cal_chans"])
      assert_allclose(
          py_cal["cal_corrs"], mf_cal["cal_corrs"], rtol=1e-3, atol=1e-3
      )
      # with missing channels
      raw_missing = raw.copy().load_data()
      raw_missing.info["bads"] = ["MEG0111", "MEG0943"]  # 1 mag, 1 grad
      raw_missing.info._check_consistency()
      raw_sss_bad = maxwell_filter(
          raw_missing,
          calibration=fine_cal_fname,
          origin=mf_head_origin,
          regularize=None,
          bad_condition="ignore",
      )
      raw_missing.pick("meg", exclude="bads")  # actually remove bads
      raw_sss_bad.pick(raw_missing.ch_names)  # remove them here, too
      with pytest.warns(
          RuntimeWarning, match="cal channels not in data"
      ):
          raw_sss_missing = maxwell_filter(
              raw_missing,
              calibration=fine_cal_fname,
              origin=mf_head_origin,
              regularize=None,
              bad_condition="ignore",
          )
      assert_meg_snr(raw_sss_missing, raw_sss_bad, 1000.0, 10000.0)
  
      # Test 3D SSS fine calibration (no equivalent func in MaxFilter yet!)
      # very low SNR as proc differs, eventually we should add a better test
      raw_sss_3D = maxwell_filter(
          raw,
          calibration=fine_cal_fname_3d,
          origin=mf_head_origin,
          regularize=None,
          bad_condition="ignore",
      )
      assert_meg_snr(raw_sss_3D, sss_fine_cal, 0.9, 6.0)
      assert_meg_snr(
          raw_sss_3D, raw_sss, 1.1, 6.0
      )  # slightly better than 1D
      raw_ctf = read_crop(fname_ctf_raw).apply_gradient_compensation(0)
      with pytest.raises(RuntimeError, match="Not all MEG channels"):
          maxwell_filter(
              raw_ctf,
              origin=(0.0, 0.0, 0.04),
              calibration=fine_cal_fname,
          )
  
imports: import pathlib
  import re
  from contextlib import contextmanager
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from scipy import sparse
  from scipy.special import sph_harm
  import mne
  from mne import compute_raw_covariance, concatenate_raws, pick_info, pick_types
  from mne._fiff.constants import FIFF
  from mne.annotations import _annotations_starts_stops
  from mne.chpi import filter_chpi, read_head_pos
  from mne.datasets import testing
  from mne.forward import _prep_meg_channels, use_coil_def
  from mne.io import BaseRaw, read_info, read_raw_bti, read_raw_ctf, read_raw_fif, read_raw_kit
  from mne.preprocessing import annotate_amplitude, annotate_movement, compute_maxwell_basis, find_bad_channels_maxwell, maxwell_filter, maxwell_filter_prepare_emptyroom
  from mne.preprocessing.maxwell import _bases_complex_to_real, _bases_real_to_complex, _get_n_moments, _prep_mf_coils, _sh_complex_to_real, _sh_negate, _sh_real_to_complex, _sss_basis_basic, _trans_sss_basis
  from mne.rank import _compute_rank_int, _get_rank_sss, compute_rank
  from mne.utils import _record_warnings, assert_meg_snr, buggy_mkl_svd, catch_logging, object_diff, use_log_level
label_desc: Use image node_id 13 for calling a global function with example usage: test_fine_calibration() without return types