code: def test_annot_concat_crop(
      meas_date, first_samp_1, first_samp_2, setting
  ):
      """Test that annotation and cropping works properly."""
      n_ch = 2
      sfreq = 160
      duration = 0.1
      meas_date_1 = meas_date_2 = None
      assert meas_date in (None, "first", "second", "both")
      if meas_date in ("first", "both"):
          meas_date_1 = datetime(
              2022, 1, 1, 0, 0, 0, tzinfo=timezone.utc
          )
      if meas_date in ("second", "both"):
          meas_date_2 = datetime(
              2022, 1, 1, 0, 0, 0, tzinfo=timezone.utc
          )
      del meas_date
  
      def _create_raw(
          eeg, sfreq, onset, description, meas_date, first_samp, setting
      ):
          info = mne.create_info(
              eeg.shape[0], ch_types="eeg", sfreq=sfreq
          )
          raw = mne.io.RawArray(eeg, info, first_samp=first_samp)
          if setting == "before":
              annot = mne.Annotations(onset, duration, description)
              raw = raw.set_annotations(annot)
              raw.set_meas_date(meas_date)
          else:
              assert setting == "after"
              raw.set_meas_date(meas_date)
              delta = first_samp / sfreq if meas_date is not None else 0
              annot = mne.Annotations(
                  onset + delta,
                  duration,
                  description,
                  orig_time=meas_date,
              )
              raw = raw.set_annotations(annot)
          return raw
  
      data_1 = np.array([list(range(40)) * 4 * 10] * n_ch) * 5 * 1e-7
      onset_1 = np.array([2.5, 5, 6, 7, 8])
      description_1 = [12, "on", 1, 2, "off"]
      raw_1 = _create_raw(
          data_1,
          sfreq,
          onset_1,
          description_1,
          meas_date_1,
          first_samp_1,
          setting,
      )
      assert_allclose(
          raw_1.annotations.onset, onset_1 + first_samp_1 / sfreq
      )
  
      data_2 = np.array(
          [([1e-5] * int(sfreq / 2) + [0] * int(sfreq / 2)) * 10] * n_ch
      )
      onset_2 = np.array([1.5, 2, 2.7, 5])
      description_2 = ["on", 3, 4, "off"]
      raw_2 = _create_raw(
          data_2,
          sfreq,
          onset_2,
          description_2,
          meas_date_2,
          first_samp_2,
          setting,
      )
      assert_allclose(
          raw_2.annotations.onset, onset_2 + first_samp_2 / sfreq
      )
  
      onset = np.concatenate(
          [onset_1, np.round(onset_2 + len(raw_1.times) / sfreq, 6)]
      )
      assert onset[0] == 2.5
      assert_allclose(
          raw_1.annotations.onset[0], 2.5 + first_samp_1 / sfreq
      )
      onset = np.round(onset + first_samp_1 / sfreq, 6)
      want_annot = mne.Annotations(
          onset=onset,
          duration=duration,
          description=description_1 + description_2,
          orig_time=meas_date_1,
      )
      raw_copy = concatenate_raws([raw_1.copy()])
      assert_allclose(
          raw_copy.annotations.onset[0], 2.5 + first_samp_1 / sfreq
      )
      raw = concatenate_raws([raw_1, raw_2])
      assert raw.first_samp == raw_1.first_samp == first_samp_1
      del raw_1, raw_2
      assert_allclose(
          raw.annotations.onset[0], 2.5 + first_samp_1 / sfreq
      )
      assert raw.info["meas_date"] == meas_date_1
      gap_idx = len(description_1)
      assert list(
          raw.annotations.description[gap_idx : gap_idx + 2]
      ) == [
          "BAD boundary",
          "EDGE boundary",
      ]
      raw.annotations.delete([gap_idx, gap_idx + 1])
      start_idx = np.where(raw.annotations.description == "on")[0]
      end_idx = np.where(raw.annotations.description == "off")[0]
      tmins = raw.annotations.onset[start_idx]
      tmaxs = raw.annotations.onset[end_idx]
      tmins -= raw.first_time
      tmaxs -= raw.first_time
      assert len(tmins) == len(tmaxs) == 2
      assert raw.info["meas_date"] == meas_date_1
      _assert_annotations_equal(raw.annotations, want_annot)
      # test a round-trip set -- see test_annot_noop for why we need conditional
      if meas_date_1 is None:
          want_annot.onset -= first_samp_1 / sfreq
      raw.set_annotations(want_annot)
      if meas_date_1 is None:  # put it back to what it was before
          want_annot.onset += first_samp_1 / sfreq
      _assert_annotations_equal(raw.annotations, want_annot)
      want_descs = list()
      for start, stop in zip(start_idx, end_idx):
          want_descs.append(
              list(raw.annotations.description[start : stop + 1])
          )
  
      for tmin, tmax, descs in zip(tmins, tmaxs, want_descs):
          sess = raw.copy()
          _assert_annotations_equal(sess.annotations, raw.annotations)
          _assert_annotations_equal(sess.annotations, want_annot)
          # let's manually print what the logger.debug should say if it's
          # doing something correctly
          if meas_date_1 is not None:
              md = raw.info["meas_date"]
              print(f"\nmeas_info set to         {md}")
              md = md + timedelta(seconds=raw._first_time)
              print(f"Data starts at           {md}")
              md = md + timedelta(seconds=tmin)
              print(f"Cropping data to         {md}")
              md = raw.info["meas_date"] + timedelta(
                  seconds=raw.annotations.onset[1]
              )
              print(f"Second annot at          {md}")
          assert sess.first_samp == first_samp_1
          sess.crop(tmin, tmax, verbose="debug")
          want_first_samp = first_samp_1 + int(round(tmin * sfreq))
          assert sess.first_samp == want_first_samp
          assert sess.annotations.orig_time == meas_date_1
          assert list(sess.annotations.description) == descs
  
imports: import sys
  from collections import OrderedDict
  from datetime import datetime, timedelta, timezone
  from itertools import repeat
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from pytest import approx
  import mne
  from mne import Annotations, Epochs, annotations_from_events, count_annotations, create_info, events_from_annotations, read_annotations
  from mne.annotations import _handle_meas_date, _read_annotations_txt_parse_header, _sync_onset
  from mne.datasets import testing
  from mne.io import RawArray, concatenate_raws, read_raw_fif
  from mne.utils import _dt_to_stamp, _raw_annot, _record_warnings, _stamp_to_dt, assert_and_remove_boundary_annot, catch_logging, check_version
label_desc: Use image node_id 48 for calling a global function with example usage: test_annot_concat_crop(meas_date, first_samp_1, first_samp_2, setting) and returns: raw