code: def test_basic():
      """Test Maxwell filter basic version."""
      # Load testing data (raw, SSS std origin, SSS non-standard origin)
      raw = read_crop(raw_fname, (0.0, 1.0))
      raw_err = read_crop(raw_fname).apply_proj()
      raw_erm = read_crop(erm_fname)
      with pytest.raises(RuntimeError, match="cannot be applied"):
          maxwell_filter(raw_err)
      with pytest.raises(TypeError, match="instance of BaseRaw"):
          maxwell_filter(1.0)
      with pytest.raises(ValueError, match="Number of requested bases"):
          maxwell_filter(raw, int_order=20)  # too many
  
      n_int_bases = int_order**2 + 2 * int_order
      n_ext_bases = ext_order**2 + 2 * ext_order
      nbases = n_int_bases + n_ext_bases
  
      # Check number of bases computed correctly
      assert _get_n_moments([int_order, ext_order]).sum() == nbases
  
      # Test SSS computation at the standard head origin
      assert len(raw.info["projs"]) == 12  # 11 MEG projs + 1 AVG EEG
      with use_coil_def(elekta_def_fname):
          raw_sss = maxwell_filter(
              raw,
              origin=mf_head_origin,
              regularize=None,
              bad_condition="ignore",
          )
      assert len(raw_sss.info["projs"]) == 1  # avg EEG
      assert raw_sss.info["projs"][0]["desc"] == "Average EEG reference"
      assert_meg_snr(raw_sss, read_crop(sss_std_fname), 200.0, 1000.0)
      py_cal = raw_sss.info["proc_history"][0]["max_info"]["sss_cal"]
      assert len(py_cal) == 0
      py_ctc = raw_sss.info["proc_history"][0]["max_info"]["sss_ctc"]
      assert len(py_ctc) == 0
      py_st = raw_sss.info["proc_history"][0]["max_info"]["max_st"]
      assert len(py_st) == 0
      with pytest.raises(RuntimeError, match="cannot reapply"):
          maxwell_filter(raw_sss)
  
      # Test SSS computation at non-standard head origin
      with use_coil_def(elekta_def_fname):
          raw_sss = maxwell_filter(
              raw,
              origin=[0.0, 0.02, 0.02],
              regularize=None,
              bad_condition="ignore",
          )
      assert_meg_snr(raw_sss, read_crop(sss_nonstd_fname), 250.0, 700.0)
  
      # Test SSS computation at device origin
      sss_erm_std = read_crop(sss_erm_std_fname)
      raw_sss = maxwell_filter(
          raw_erm,
          coord_frame="meg",
          origin=mf_meg_origin,
          regularize=None,
          bad_condition="ignore",
      )
      assert_meg_snr(raw_sss, sss_erm_std, 70.0, 260.0)
      for key in ("job", "frame"):
          vals = [
              x.info["proc_history"][0]["max_info"]["sss_info"][key]
              for x in [raw_sss, sss_erm_std]
          ]
          assert vals[0] == vals[1]
  
      # Two equivalent things: at device origin in device coords (0., 0., 0.)
      # and at device origin at head coords info['dev_head_t'][:3, 3]
      raw_sss_meg = maxwell_filter(
          raw, coord_frame="meg", origin=(0.0, 0.0, 0.0)
      )
      raw_sss_head = maxwell_filter(
          raw, origin=raw.info["dev_head_t"]["trans"][:3, 3]
      )
      assert_meg_snr(raw_sss_meg, raw_sss_head, 100.0, 900.0)
  
      # Check against SSS functions from proc_history
      assert _get_n_moments(int_order) == _get_rank_sss(raw_sss)
  
      # Degenerate cases
      with pytest.raises(ValueError, match="Invalid value"):
          maxwell_filter(raw, coord_frame="foo")
      with pytest.raises(ValueError, match="numerical array"):
          maxwell_filter(raw, origin="foo")
      with pytest.raises(ValueError, match="3-element array"):
          maxwell_filter(raw, origin=[0] * 4)
      with pytest.raises(ValueError, match="must be a float"):
          maxwell_filter(raw, mag_scale="foo")
      raw_missing = raw.copy().load_data()
      raw_missing.info["bads"] = ["MEG0111"]
      raw_missing.pick("meg", exclude="bads")  # will be missing the bad
      maxwell_filter(raw_missing)
      with pytest.warns(RuntimeWarning, match="not in data"):
          maxwell_filter(raw_missing, 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 8 for calling a global function with example usage: test_basic() without return types