code: def affine_img_src(
      data, affine, scale=1, name="AffineImage", reverse_x=False
  ):
      """Make a Mayavi source defined by a 3D array and an affine, for
      which the voxel of the 3D array are mapped by the affine.
  
      Parameters
      -----------
      data: 3D ndarray
          The data arrays
      affine: (4 x 4) ndarray
          The (4 x 4) affine matrix relating voxels to world
          coordinates.
      scale: float, optional
          An optional addition scaling factor.
      name: string, optional
          The name of the Mayavi source created.
      reverse_x: boolean, optional
          Reverse the x (lateral) axis. Useful to compared with
          images in radiologic convention.
  
      Notes
      ------
      The affine should be diagonal.
      """
      # Late import to avoid triggering wx imports before needed.
      try:
          from mayavi.sources.api import ArraySource
      except ImportError:
          # Try out old install of Mayavi, with namespace packages
          from enthought.mayavi.sources.api import ArraySource
      center = np.r_[0, 0, 0, 1]
      spacing = np.diag(affine)[:3].copy()
      origin = np.dot(affine, center)[:3]
      if reverse_x:
          # Radiologic convention
          spacing[0] *= -1
          origin[0] *= -1
      src = ArraySource(
          scalar_data=np.asarray(data, dtype=np.float64),
          name=name,
          spacing=scale * spacing,
          origin=scale * origin,
      )
      return src
  
file_path: nipy/nipy/labs/viz_tools/maps_3d.py
imports: import os
  import tempfile
  import numpy
  from scipy import stats
  from .anat_cache import _AnatCache, mni_sform, mni_sform_inv
  from .coord_tools import coord_transform
label_desc: Use image node_id 1 for calling a global function with example usage: affine_img_src(data, affine, scale, name, reverse_x) and returns: src