code: def test_prepare_emptyroom_annot_first_samp(
      set_annot_when, raw_meas_date, raw_er_meas_date
  ):
      """Test prepare_emptyroom."""
      raw = read_raw_fif(
          raw_fname, allow_maxshield="yes", verbose=False
      )
      raw_er = read_raw_fif(
          erm_fname, allow_maxshield="yes", verbose=False
      )
      names = raw.ch_names[:3]  # make it faster
      raw.pick(names)
      raw_er.pick(names)
      assert raw.ch_names == raw_er.ch_names
      assert raw.info["meas_date"] != raw_er.info["meas_date"]
      if raw_meas_date is None:
          raw.set_meas_date(None)
      if raw_er_meas_date is None:
          raw_er.set_meas_date(None)
      # to make life easier, make it the same duration
      n_rep = max(int(np.ceil(len(raw.times) / len(raw_er.times))), 1)
      raw_er = mne.concatenate_raws([raw_er] * n_rep).crop(
          0, raw.times[-1]
      )
      assert_allclose(raw.times, raw_er.times)
      raw_er_first_samp_orig = raw_er.first_samp
      assert len(raw.annotations) == 0
      pos = mne.chpi.read_head_pos(pos_fname)
      annot, _ = annotate_movement(raw, pos, 1.0)
      # Add an annotation right at the beginning and end to make sure nothing
      # gets cropped
      onset = raw.times[[0, -1]]
      duration = 1.0 / raw.info["sfreq"]
      annot.append(
          onset + raw.first_time * (raw.info["meas_date"] is not None),
          duration,
          ["BAD_CUSTOM"],
      )
      want_annot = (
          7  # 5 from annotate_movement plus our first and last samps
      )
      if set_annot_when == "before":
          raw.set_annotations(annot)
          meas_date = "keep"
          want_date = raw_er.info["meas_date"]
      else:
          assert set_annot_when == "after"
          meas_date = "from_raw"
          want_date = raw.info["meas_date"]
      raw_er_prepared = maxwell_filter_prepare_emptyroom(
          raw_er=raw_er, raw=raw, meas_date=meas_date, emit_warning=True
      )
      assert raw_er.first_samp == raw_er_first_samp_orig
      assert raw_er_prepared.info["meas_date"] == want_date
      assert raw_er_prepared.first_samp == raw.first_samp
  
      # Ensure (movement) annotations carry over regardless of whether they're
      # set before or after preparation
      assert len(annot) == want_annot
      if set_annot_when == "after":
          raw.set_annotations(annot)
          raw_er_prepared.set_annotations(annot)
      assert len(raw.annotations) == want_annot
      prop_bad = np.isnan(
          raw.get_data([0], reject_by_annotation="nan")
      ).mean()
      assert 0.3 < prop_bad < 0.4
      assert len(raw_er_prepared.annotations) == want_annot
      prop_bad_er = np.isnan(
          raw_er_prepared.get_data([0], reject_by_annotation="nan")
      ).mean()
      assert_allclose(prop_bad, prop_bad_er)
  
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 30 for calling a global function with example usage: test_prepare_emptyroom_annot_first_samp(set_annot_when, raw_meas_date, raw_er_meas_date) without return types