code: def make_xyz_image(data, xyz_affine, world, metadata=None):
      """Create 3D+ image embedded in space named in `world`
  
      Parameters
      ----------
      data : object
          Object returning array from ``np.asarray(obj)``, and having ``shape``
          attribute.  Should have at least 3 dimensions (``len(shape) >= 3``), and
          these three first 3 dimensions should be spatial
      xyz_affine : (4, 4) array-like or tuple
          if (4, 4) array-like (the usual case), then an affine relating spatial
          dimensions in data (dimensions 0:3) to mm in XYZ space given in `world`.
          If a tuple, then contains two values: the (4, 4) array-like, and a
          sequence of scalings for the dimensions greater than 3.  See examples.
      world : str or XYZSpace or CoordSysMaker or CoordinateSystem
          World 3D space to which affine refers.  See ``spaces.get_world_cs()``
      metadata : None or mapping, optional
          metadata for created image.  Defaults to None, giving empty metadata.
  
      Returns
      -------
      img : Image
          image containing `data`, with coordmap constructed from `affine` and
          `world`, and with default voxel input coordinates.  If the data has more
          than 3 dimensions, and you didn't specify the added zooms with a tuple
          `xyz_affine` parameter, the coordmap affine gets filled out with extra
          ones on the diagonal to give an (N+1, N+1) affine, with ``N =
          len(data.shape)``
  
      Examples
      --------
      >>> data = np.arange(24).reshape((2, 3, 4))
      >>> aff = np.diag([4, 5, 6, 1])
      >>> img = make_xyz_image(data, aff, 'mni')
      >>> img
      Image(
        data=array([[[ 0,  1,  2,  3],
                     [ 4,  5,  6,  7],
                     [ 8,  9, 10, 11]],
      <BLANKLINE>
                    [[12, 13, 14, 15],
                     [16, 17, 18, 19],
                     [20, 21, 22, 23]]]),
        coordmap=AffineTransform(
                  function_domain=CoordinateSystem(coord_names=('i', 'j', 'k'), name='voxels', coord_dtype=float64),
                  function_range=CoordinateSystem(coord_names=('mni-x=L->R', 'mni-y=P->A', 'mni-z=I->S'), name='mni', coord_dtype=float64),
                  affine=array([[ 4.,  0.,  0.,  0.],
                                [ 0.,  5.,  0.,  0.],
                                [ 0.,  0.,  6.,  0.],
                                [ 0.,  0.,  0.,  1.]])
               ))
  
      Now make data 4D; we just add 1. to the diagonal for the new dimension
  
      >>> data4 = data[..., None]
      >>> img = make_xyz_image(data4, aff, 'mni')
      >>> img.coordmap
      AffineTransform(
         function_domain=CoordinateSystem(coord_names=('i', 'j', 'k', 'l'), name='voxels', coord_dtype=float64),
         function_range=CoordinateSystem(coord_names=('mni-x=L->R', 'mni-y=P->A', 'mni-z=I->S', 't'), name='mni', coord_dtype=float64),
         affine=array([[ 4.,  0.,  0.,  0.,  0.],
                       [ 0.,  5.,  0.,  0.,  0.],
                       [ 0.,  0.,  6.,  0.,  0.],
                       [ 0.,  0.,  0.,  1.,  0.],
                       [ 0.,  0.,  0.,  0.,  1.]])
      )
  
      We can pass in a scalar or tuple to specify scaling for the extra dimension
  
      >>> img = make_xyz_image(data4, (aff, 2.0), 'mni')
      >>> img.coordmap.affine
      array([[ 4.,  0.,  0.,  0.,  0.],
             [ 0.,  5.,  0.,  0.,  0.],
             [ 0.,  0.,  6.,  0.,  0.],
             [ 0.,  0.,  0.,  2.,  0.],
             [ 0.,  0.,  0.,  0.,  1.]])
      >>> data5 = data4[..., None]
      >>> img = make_xyz_image(data5, (aff, (2.0, 3.0)), 'mni')
      >>> img.coordmap.affine
      array([[ 4.,  0.,  0.,  0.,  0.,  0.],
             [ 0.,  5.,  0.,  0.,  0.,  0.],
             [ 0.,  0.,  6.,  0.,  0.,  0.],
             [ 0.,  0.,  0.,  2.,  0.,  0.],
             [ 0.,  0.,  0.,  0.,  3.,  0.],
             [ 0.,  0.,  0.,  0.,  0.,  1.]])
      """
      N = len(data.shape)
      if N < 3:
          raise ValueError("Need data with at least 3 dimensions")
      if type(xyz_affine) is tuple:
          xyz_affine, added_zooms = xyz_affine
          # Could be scalar added zooms
          try:
              len(added_zooms)
          except TypeError:
              added_zooms = (added_zooms,)
          if len(added_zooms) != (N - 3):
              raise ValueError("Wrong number of added zooms")
      else:
          added_zooms = (1,) * (N - 3)
      xyz_affine = np.asarray(xyz_affine)
      if not xyz_affine.shape == (4, 4):
          raise ValueError("Expecting 4 x 4 affine")
      # Make coordinate map
      world_cm = rsp.get_world_cs(world, N)
      voxel_cm = rsp.voxel_csm(N)
      if N > 3:
          affine = np.diag((1.0, 1, 1) + added_zooms + (1,))
          affine[:3, :3] = xyz_affine[:3, :3]
          affine[:3, -1] = xyz_affine[:3, 3]
      else:
          affine = xyz_affine
      cmap = AffineTransform(voxel_cm, world_cm, affine)
      return Image(data, cmap, metadata)
  
file_path: nipy/nipy/core/image/image_spaces.py
imports: import sys
  import numpy
  from nibabel import io_orientation
  from ...io import nibcompat
  from ..image.image import Image
  from ..reference import spaces
  from ..reference.coordinate_map import AffineTransform
label_desc: Use image node_id 4 for calling a global function with example usage: make_xyz_image(data, xyz_affine, world, metadata) and returns: Image