code: def get_affine_trackvis_to_rasmm(header):
      """Get affine mapping trackvis voxelmm space to RAS+ mm space
  
      The streamlines in a trackvis file are in 'voxelmm' space, where the
      coordinates refer to the corner of the voxel.
  
      Compute the affine matrix that will bring them back to RAS+ mm space, where
      the coordinates refer to the center of the voxel.
  
      Parameters
      ----------
      header : dict or ndarray
          Dict or numpy structured array containing trackvis header.
  
      Returns
      -------
      aff_tv2ras : shape (4, 4) array
          Affine array mapping coordinates in 'voxelmm' space to RAS+ mm space.
      """
      # TRK's streamlines are in 'voxelmm' space, we will compute the
      # affine matrix that will bring them back to RAS+ and mm space.
      affine = np.eye(4)
  
      # The affine matrix found in the TRK header requires the points to
      # be in the voxel space.
      # voxelmm -> voxel
      scale = np.eye(4)
      scale[range(3), range(3)] /= header[Field.VOXEL_SIZES]
      affine = np.dot(scale, affine)
  
      # TrackVis considers coordinate (0,0,0) to be the corner of the
      # voxel whereas streamlines returned assumes (0,0,0) to be the
      # center of the voxel. Thus, streamlines are shifted by half a voxel.
      offset = np.eye(4)
      offset[:-1, -1] -= 0.5
      affine = np.dot(offset, affine)
  
      # If the voxel order implied by the affine does not match the voxel
      # order in the TRK header, change the orientation.
      # voxel (header) -> voxel (affine)
      vox_order = header[Field.VOXEL_ORDER]
      # Input header can be dict or structured array
      if hasattr(vox_order, "item"):  # structured array
          vox_order = header[Field.VOXEL_ORDER].item()
      affine_ornt = "".join(aff2axcodes(header[Field.VOXEL_TO_RASMM]))
      header_ornt = axcodes2ornt(vox_order.decode("latin1").upper())
      affine_ornt = axcodes2ornt(affine_ornt)
      ornt = nib.orientations.ornt_transform(header_ornt, affine_ornt)
      M = nib.orientations.inv_ornt_aff(ornt, header[Field.DIMENSIONS])
      affine = np.dot(M, affine)
  
      # Applied the affine found in the TRK header.
      # voxel -> rasmm
      voxel_to_rasmm = header[Field.VOXEL_TO_RASMM]
      affine_voxmm_to_rasmm = np.dot(voxel_to_rasmm, affine)
      return affine_voxmm_to_rasmm.astype(np.float32)
  
imports: import os
  import string
  import struct
  import warnings
  import numpy
  import nibabel
  from nibabel.openers import Opener
  from nibabel.orientations import aff2axcodes, axcodes2ornt
  from nibabel.volumeutils import endian_codes, native_code, swapped_code
  from .array_sequence import create_arraysequences_from_generator
  from .header import Field
  from .tractogram import LazyTractogram, Tractogram, TractogramItem
  from .tractogram_file import DataError, HeaderError, HeaderWarning, TractogramFile
  from .utils import peek_next
label_desc: Use image node_id 1 for calling a global function with example usage: get_affine_trackvis_to_rasmm(header) and returns: affine_voxmm_to_rasmm