code: def _annotations_starts_stops(
      raw, kinds, name="skip_by_annotation", invert=False
  ):
      """Get starts and stops from given kinds.
  
      onsets and ends are inclusive.
      """
      _validate_type(kinds, (str, list, tuple), name)
      if isinstance(kinds, str):
          kinds = [kinds]
      else:
          for kind in kinds:
              _validate_type(kind, "str", "All entries")
  
      if len(raw.annotations) == 0:
          onsets, ends = np.array([], int), np.array([], int)
      else:
          idxs = [
              idx
              for idx, desc in enumerate(raw.annotations.description)
              if any(
                  desc.upper().startswith(kind.upper())
                  for kind in kinds
              )
          ]
          # onsets are already sorted
          onsets = raw.annotations.onset[idxs]
          onsets = _sync_onset(raw, onsets)
          ends = onsets + raw.annotations.duration[idxs]
          onsets = raw.time_as_index(onsets, use_rounding=True)
          ends = raw.time_as_index(ends, use_rounding=True)
      assert (onsets <= ends).all()  # all durations >= 0
      if invert:
          # We need to eliminate overlaps here, otherwise wacky things happen,
          # so we carefully invert the relationship
          mask = np.zeros(len(raw.times), bool)
          for onset, end in zip(onsets, ends):
              mask[onset:end] = True
          mask = ~mask
          extras = onsets == ends
          extra_onsets, extra_ends = onsets[extras], ends[extras]
          onsets, ends = _mask_to_onsets_offsets(mask)
          # Keep ones where things were exactly equal
          del extras
          # we could do this with a np.insert+np.searchsorted, but our
          # ordered-ness should get us it for free
          onsets = np.sort(np.concatenate([onsets, extra_onsets]))
          ends = np.sort(np.concatenate([ends, extra_ends]))
          assert (onsets <= ends).all()
      return onsets, ends
  
imports: import json
  import os.path
  import re
  import warnings
  from collections import Counter, OrderedDict
  from collections.abc import Iterable
  from copy import deepcopy
  from datetime import datetime, timedelta, timezone
  from itertools import takewhile
  from textwrap import shorten
  import numpy
  from scipy.io import loadmat
  from ._fiff.constants import FIFF
  from ._fiff.open import fiff_open
  from ._fiff.tag import read_tag
  from ._fiff.tree import dir_tree_find
  from ._fiff.write import _safe_name_list, end_block, start_and_end_file, start_block, write_double, write_float, write_name_list_sanitized, write_string
  from .utils import _check_dict_keys, _check_dt, _check_fname, _check_option, _check_pandas_installed, _check_time_format, _convert_times, _DefaultEventParser, _dt_to_stamp, _is_numeric, _mask_to_onsets_offsets, _on_missing, _pl, _stamp_to_dt, _validate_type, check_fname, fill_doc, int_like, logger, verbose, warn
label_desc: Use image node_id 6 for calling a global function with example usage: _annotations_starts_stops(raw, kinds, name, invert) and returns: onsets,  ends