code: def test_find_bads_maxwell_flat():
      """Test find_bads_maxwell when there are flat channels."""
      # See gh-9479
      raw = mne.io.read_raw_fif(raw_small_fname).load_data()
      assert_allclose(raw.times[-1], 23.97, atol=1e-2)
      noisy, flat = find_bad_channels_maxwell(raw, min_count=1)
      assert noisy == ["MEG 1032", "MEG 2313", "MEG 2443"]
      assert flat == []
      n = int(round(raw.info["sfreq"] * 10))
      assert (len(raw.times) - n) / raw.info[
          "sfreq"
      ] > 10  # at least 10 s
      with catch_logging() as log:
          want_noisy, want_flat = find_bad_channels_maxwell(
              raw.copy().crop(n / raw.info["sfreq"], None),
              min_count=1,
              verbose="debug",
          )
      log = log.getvalue()
      assert "in 2 intervals " in log
      assert want_noisy == ["MEG 2313", "MEG 2443"]
      assert want_flat == []
      raw._data[:, :n] = 0
      with pytest.warns(
          RuntimeWarning, match="All-flat segment detected"
      ):
          with catch_logging() as log:
              noisy, flat = find_bad_channels_maxwell(
                  raw, min_count=1, verbose="debug"
              )
      log = log.getvalue()
      assert " in 4 intervals " in log
      assert flat == raw.ch_names[:306]
      assert noisy == []  # none found because all flat
      # now do what we suggest in the warning
      annot, _ = annotate_amplitude(
          raw, flat=0.0, bad_percent=100, min_duration=1.0
      )
      assert_allclose(
          annot.duration, 10.0, atol=1e-2
      )  # not even divisor sfreq
      raw.info["bads"] = []
      raw.set_annotations(annot)
      data_good = raw.get_data(reject_by_annotation="omit")
      assert (
          data_good.shape[1] / raw.info["sfreq"] / 5.0 > 2
      )  # at least 10 s
      with catch_logging() as log:
          noisy, flat = find_bad_channels_maxwell(
              raw,
              min_count=1,
              skip_by_annotation="bad_flat",
              verbose="debug",
          )
      log = log.getvalue()
      assert " in 2 intervals " in log, log
      assert flat == want_flat
      assert noisy == want_noisy
  
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 27 for calling a global function with example usage: test_find_bads_maxwell_flat() without return types