code: def test_read_write_annot():
      """Test generating .annot file and reading it back."""
      # This annot file will store a LUT for a mesh made of 10 vertices, with
      # 3 colours in the LUT.
      nvertices = 10
      nlabels = 3
      names = [f"label {l}" for l in range(1, nlabels + 1)]
      # randomly generate a label for each vertex, making sure
      # that at least one of each label value is present. Label
      # values are in the range (0, nlabels-1) - they are used
      # as indices into the lookup table (generated below).
      labels = list(range(nlabels)) + list(
          np.random.randint(0, nlabels, nvertices - nlabels)
      )
      labels = np.array(labels, dtype=np.int32)
      np.random.shuffle(labels)
      # Generate some random colours for the LUT
      rgbal = np.zeros((nlabels, 5), dtype=np.int32)
      rgbal[:, :4] = np.random.randint(0, 255, (nlabels, 4))
      # But make sure we have at least one large alpha, to make sure that when
      # it is packed into a signed 32 bit int, it results in a negative value
      # for the annotation value.
      rgbal[0, 3] = 255
      # Generate the annotation values for each LUT entry
      rgbal[:, 4] = (
          rgbal[:, 0] + rgbal[:, 1] * (2**8) + rgbal[:, 2] * (2**16)
      )
      annot_path = "c.annot"
      with InTemporaryDirectory():
          write_annot(annot_path, labels, rgbal, names, fill_ctab=False)
          labels2, rgbal2, names2 = read_annot(annot_path)
          names2 = [n.decode("ascii") for n in names2]
          assert np.all(np.isclose(rgbal2, rgbal))
          assert np.all(np.isclose(labels2, labels))
          assert names2 == names
  
imports: import getpass
  import hashlib
  import os
  import struct
  import time
  import unittest
  from os.path import isdir
  from os.path import join
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  from ...fileslice import strided_scalar
  from ...testing import clear_and_catch_warnings
  from ...tests.nibabel_data import get_nibabel_data, needs_nibabel_data
  from ...tmpdirs import InTemporaryDirectory
  from ..None import read_annot, read_geometry, read_label, read_morph_data, write_annot, write_geometry, write_morph_data
  from ..io import _pack_rgb
label_desc: Use image node_id 6 for calling a global function with example usage: test_read_write_annot() without return types