code: def nifti2nipy(ni_img):
      """Return NIPY image from NIFTI image `ni_image`
  
      Parameters
      ----------
      ni_img : nibabel.Nifti1Image
          NIFTI image
  
      Returns
      -------
      img : :class:`Image`
          nipy image
  
      Raises
      ------
      NiftiError : if image is < 3D
  
      Notes
      -----
      Lacking any other information, we take the input coordinate names for
      axes 0:7 to be  ('i', 'j', 'k', 't', 'u', 'v', 'w').
  
      If the image is 1D or 2D then we have a problem.  If there's a defined
      (sform, qform) affine, this has 3 input dimensions, and we have to guess
      what the extra input dimensions are.  If we don't have a defined affine, we
      don't know what the output dimensions are.  For example, if the image is 2D,
      and we don't have an affine, are these X and Y or X and Z or Y and Z?
      In the presence of ambiguity, resist the temptation to guess - raise a
      NiftiError.
  
      If there is a time-like axis, name the input and corresponding output axis
      for the type of axis ('t', 'hz', 'ppm', 'rads').
  
      Otherwise remove the 't' axis from both input and output names, and squeeze
      the length 1 dimension from the input data.
  
      If there's a 't' axis get ``toffset`` and put into affine at position [3,
      -1].
  
      If ``dim_info`` is set coherently, set input axis names to 'slice', 'freq',
      'phase' from ``dim_info``.
  
      Get the output spatial coordinate names from the 'scanner', 'aligned',
      'talairach', 'mni' XYZ spaces (see :mod:`nipy.core.reference.spaces`).
  
      We construct the N-D affine by taking the XYZ affine and adding scaling
      diagonal elements from ``pixdim``.
  
      If the space units in NIFTI ``xyzt_units`` are 'microns' or 'meters' we
      adjust the affine to mm units, but warn because this might be a mistake.
  
      If the time units in NIFTI `xyzt_units` are 'msec' or 'usec', scale the time
      axis ``pixdim`` values accordingly.
  
      Ignore the intent-related fields for now, but warn that we are doing so if
      there appears to be specific information in there.
      """
      hdr = get_header(ni_img)
      affine = get_affine(ni_img)
      # Affine will not be None from a loaded image, but just in case
      if affine is None:
          affine = hdr.get_best_affine()
      else:
          affine = affine.copy()
      data = ni_img.get_fdata()
      shape = list(ni_img.shape)
      ndim = len(shape)
      if ndim < 3:
          raise NiftiError(
              "With less than 3 dimensions we cannot be sure "
              "which input and output dimensions you intend for "
              "the coordinate map.  Please fix this image with "
              "nibabel or some other tool"
          )
      # For now we only warn if intent is set to an unexpected value
      intent, _, _ = hdr.get_intent()
      if intent != "none":
          warnings.warn(
              f'Ignoring intent field meaning "{intent}"', UserWarning
          )
      # Which space?
      world_label = hdr.get_value_label("sform_code")
      if world_label == "unknown":
          world_label = hdr.get_value_label("qform_code")
      world_space = XFORM2SPACE.get(world_label, ncrs.unknown_space)
      # Get information from dim_info
      input_names3 = list("ijk")
      freq, phase, slice = hdr.get_dim_info()
      if freq is not None:
          input_names3[freq] = "freq"
      if phase is not None:
          input_names3[phase] = "phase"
      if slice is not None:
          input_names3[slice] = "slice"
      # Add to mm scaling, with warning
      space_units, time_like_units = hdr.get_xyzt_units()
      if space_units in ("micron", "meter"):
          warnings.warn(
              '"%s" space scaling in NIFTI ``xyt_units field; '
              "applying scaling to affine, but this may not be what "
              "you want" % space_units,
              UserWarning,
          )
          if space_units == "micron":
              affine[:3] /= 1000.0
          elif space_units == "meter":
              affine[:3] *= 1000.0
      input_cs3 = CS(input_names3, name="voxels")
      output_cs3 = world_space.to_coordsys_maker()(3)
      cmap3 = AT(input_cs3, output_cs3, affine)
      if ndim == 3:
          return Image(data, cmap3, {"header": hdr})
      space_units, time_like_units = hdr.get_xyzt_units()
      units_info = TIME_LIKE_UNITS.get(time_like_units, None)
      n_ns = ndim - 3
      ns_zooms = list(hdr.get_zooms()[3:])
      ns_trans = [0] * n_ns
      ns_names = tuple("uvw")
      # Have we got a time axis?
      if shape[3] == 1 and ndim > 4 and units_info is None:
          # Squeeze length 1 no-time axis
          shape.pop(3)
          ns_zooms.pop(0)
          ns_trans.pop(0)
          data = data.reshape(shape)
          n_ns -= 1
      else:  # have time-like
          if units_info is None:
              units_info = TIME_LIKE_UNITS["sec"]
          time_name = units_info["name"]
          if units_info["scaling"] != 1:
              ns_zooms[0] *= units_info["scaling"]
          if time_name == "t":
              # Get time offset
              ns_trans[0] = hdr["toffset"]
          ns_names = (time_name,) + ns_names
      output_cs = CS(ns_names[:n_ns])
      input_cs = CS(ns_names[:n_ns])
      aff = from_matvec(np.diag(ns_zooms), ns_trans)
      ns_cmap = AT(input_cs, output_cs, aff)
      cmap = cm_product(
          cmap3,
          ns_cmap,
          input_name=cmap3.function_domain.name,
          output_name=cmap3.function_range.name,
      )
      return Image(data, cmap, {"header": hdr})
  
file_path: nipy/nipy/io/nifti_ref.py
imports: import sys
  import warnings
  from copy import copy
  import nibabel
  import numpy
  from nibabel.affines import from_matvec, to_matvec
  from ..core.image.image import Image
  from ..core.image.image_spaces import as_xyz_image
  from ..core.reference import spaces
  from ..core.reference.coordinate_map import AffineTransform
  from ..core.reference.coordinate_map import axmap
  from ..core.reference.coordinate_map import product
  from ..core.reference.coordinate_system import CoordinateSystem
  from .nibcompat import get_affine, get_header
label_desc: Use image node_id 3 for calling a global function with example usage: nifti2nipy(ni_img) and returns: Image, Image