code: def test_multipolar_bases():
      """Test multipolar moment basis calculation using sensor information."""
      from scipy.io import loadmat
  
      # Test our basis calculations
      info = read_info(raw_fname)
      with use_coil_def(elekta_def_fname):
          coils = _prep_meg_channels(info, do_es=True)["defs"]
      # Check against a known benchmark
      sss_data = loadmat(bases_fname)
      exp = dict(int_order=int_order, ext_order=ext_order)
      for origin in ((0, 0, 0.04), (0, 0.02, 0.02)):
          o_str = "".join("%d" % (1000 * n) for n in origin)
          exp.update(origin=origin)
          S_tot = _sss_basis_basic(exp, coils, method="alternative")
          # Test our real<->complex conversion functions
          S_tot_complex = _bases_real_to_complex(
              S_tot, int_order, ext_order
          )
          S_tot_round = _bases_complex_to_real(
              S_tot_complex, int_order, ext_order
          )
          assert_allclose(S_tot, S_tot_round, atol=1e-7)
  
          S_tot_mat = np.concatenate(
              [sss_data["Sin" + o_str], sss_data["Sout" + o_str]],
              axis=1,
          )
          S_tot_mat_real = _bases_complex_to_real(
              S_tot_mat, int_order, ext_order
          )
          S_tot_mat_round = _bases_real_to_complex(
              S_tot_mat_real, int_order, ext_order
          )
          assert_allclose(S_tot_mat, S_tot_mat_round, atol=1e-7)
          assert_allclose(
              S_tot_complex, S_tot_mat, rtol=1e-4, atol=1e-8
          )
          assert_allclose(S_tot, S_tot_mat_real, rtol=1e-4, atol=1e-8)
  
          # Now normalize our columns
          S_tot /= np.sqrt(np.sum(S_tot * S_tot, axis=0))[np.newaxis]
          S_tot_complex /= np.sqrt(
              np.sum(
                  (S_tot_complex * S_tot_complex.conj()).real, axis=0
              )
          )[np.newaxis]
          # Check against a known benchmark
          S_tot_mat = np.concatenate(
              [sss_data["SNin" + o_str], sss_data["SNout" + o_str]],
              axis=1,
          )
          # Check this roundtrip
          S_tot_mat_real = _bases_complex_to_real(
              S_tot_mat, int_order, ext_order
          )
          S_tot_mat_round = _bases_real_to_complex(
              S_tot_mat_real, int_order, ext_order
          )
          assert_allclose(S_tot_mat, S_tot_mat_round, atol=1e-7)
          assert_allclose(
              S_tot_complex, S_tot_mat, rtol=1e-4, atol=1e-8
          )
  
          # Now test our optimized version
          S_tot = _sss_basis_basic(exp, coils)
          with use_coil_def(elekta_def_fname):
              S_tot_fast = _trans_sss_basis(
                  exp,
                  all_coils=_prep_mf_coils(info),
                  trans=info["dev_head_t"],
              )
          # there are some sign differences for columns (order/degrees)
          # in here, likely due to Condon-Shortley. Here we use a
          # Magnetometer channel to figure out the flips because the
          # gradiometer channels have effectively zero values for first three
          # external components (i.e., S_tot[grad_picks, 80:83])
          flips = np.sign(S_tot_fast[2]) != np.sign(S_tot[2])
          flips = 1 - 2 * flips
          assert_allclose(S_tot, S_tot_fast * flips, atol=1e-16)
  
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 7 for calling a global function with example usage: test_multipolar_bases() without return types