code: def _read_annotations_edf(
      annotations, ch_names=None, encoding="utf8"
  ):
      """Annotation File Reader.
  
      Parameters
      ----------
      annotations : ndarray (n_chans, n_samples) | str
          Channel data in EDF+ TAL format or path to annotation file.
      ch_names : list of string
          List of channels' names.
      %(encoding_edf)s
  
      Returns
      -------
      annot : instance of Annotations
          The annotations.
      """
      pat = "([+-]\\d+\\.?\\d*)(\x15(\\d+\\.?\\d*))?(\x14.*?)\x14\x00"
      if isinstance(annotations, str):
          with open(annotations, "rb") as annot_file:
              triggers = re.findall(pat.encode(), annot_file.read())
              triggers = [
                  tuple(map(lambda x: x.decode(encoding), t))
                  for t in triggers
              ]
      else:
          tals = bytearray()
          annotations = np.atleast_2d(annotations)
          for chan in annotations:
              this_chan = chan.ravel()
              if this_chan.dtype == INT32:  # BDF
                  this_chan = this_chan.view(dtype=UINT8)
                  this_chan = this_chan.reshape(-1, 4)
                  # Why only keep the first 3 bytes as BDF values
                  # are stored with 24 bits (not 32)
                  this_chan = this_chan[:, :3].ravel()
                  # As ravel() returns a 1D array we can add all values at once
                  tals.extend(this_chan)
              else:
                  this_chan = chan.astype(np.int64)
                  # Exploit np vectorized processing
                  tals.extend(
                      np.uint8(
                          [this_chan % 256, this_chan // 256]
                      ).flatten("F")
                  )
          try:
              triggers = re.findall(pat, tals.decode(encoding))
          except UnicodeDecodeError as e:
              raise Exception(
                  "Encountered invalid byte in at least one annotations channel."
                  " You might want to try setting \"encoding='latin1'\"."
              ) from e
  
      events = {}
      offset = 0.0
      for k, ev in enumerate(triggers):
          onset = float(ev[0]) + offset
          duration = float(ev[2]) if ev[2] else 0
          for description in ev[3].split("\x14")[1:]:
              if description:
                  if (
                      "@@" in description
                      and ch_names is not None
                      and description.split("@@")[1] in ch_names
                  ):
                      description, ch_name = description.split("@@")
                      key = f"{onset}_{duration}_{description}"
                  else:
                      ch_name = None
                      key = f"{onset}_{duration}_{description}"
                      if key in events:
                          key += f"_{k}"  # make key unique
                  if key in events and ch_name:
                      events[key][3] += (ch_name,)
                  else:
                      events[key] = [
                          onset,
                          duration,
                          description,
                          (ch_name,) if ch_name else (),
                      ]
  
              elif k == 0:
                  # The startdate/time of a file is specified in the EDF+ header
                  # fields 'startdate of recording' and 'starttime of recording'.
                  # These fields must indicate the absolute second in which the
                  # start of the first data record falls. So, the first TAL in
                  # the first data record always starts with +0.X, indicating
                  # that the first data record starts a fraction, X, of a second
                  # after the startdate/time that is specified in the EDF+
                  # header. If X=0, then the .X may be omitted.
                  offset = -onset
  
      if events:
          onset, duration, description, annot_ch_names = zip(
              *events.values()
          )
      else:
          onset, duration, description, annot_ch_names = (
              list(),
              list(),
              list(),
              list(),
          )
  
      assert (
          len(onset)
          == len(duration)
          == len(description)
          == len(annot_ch_names)
      )
  
      return Annotations(
          onset=onset,
          duration=duration,
          description=description,
          orig_time=None,
          ch_names=annot_ch_names,
      )
  
imports: import os
  import re
  from datetime import datetime, timedelta, timezone
  import numpy
  from scipy.interpolate import interp1d
  from ..._fiff.constants import FIFF
  from ..._fiff.meas_info import _empty_info, _unique_channel_names
  from ..._fiff.utils import _blk_read_lims, _mult_cal_one
  from ...annotations import Annotations
  from ...filter import resample
  from ...utils import _validate_type, fill_doc, logger, verbose, warn
  from ..base import BaseRaw, _get_scaling
label_desc: Use image node_id 17 for calling a global function with example usage: _read_annotations_edf(annotations, ch_names, encoding) and returns: Annotations