code: def axmap(coordmap, direction="in2out", fix0=True):
      """Return mapping between input and output axes
  
      Parameters
      ----------
      coordmap : Affine
          Affine coordinate map instance for which to get axis mappings
      direction : {'in2out', 'out2in', 'both'}
          direction to find mapping.  If 'in2out', returned mapping will have keys
          from the input axis (names and indices) and values of corresponding
          output axes.  If 'out2in' the keys will be output axis names, indices
          and the values will be input axis indices.  If both, return both
          mappings.
      fix0: bool, optional
          Whether to fix potential 0 TR in affine
  
      Returns
      -------
      map : dict or tuple
          * if `direction` == 'in2out' - mapping with keys of input names and
            input indices, values of output indices. Mapping is to closest
            matching axis.  None means there appears to be no matching axis
          * if `direction` == 'out2in' - mapping with keys of output names and
            input indices, values of input indices, as above.
          * if `direction` == 'both' - tuple of (input to output mapping, output
            to input mapping)
      """
      in2out = direction in ("in2out", "both")
      out2in = direction in ("out2in", "both")
      if True not in (in2out, out2in):
          raise ValueError(
              'Direction must be one of "in2out", "out2in", "both"'
          )
      affine = coordmap.affine
      affine = _fix0(affine) if fix0 else affine
      ornts = io_orientation(affine)
      ornts = [None if np.isnan(R) else int(R) for R in ornts[:, 0]]
      if in2out:
          in2out_map = {}
          for i, name in enumerate(
              coordmap.function_domain.coord_names
          ):
              in2out_map[i] = ornts[i]
              in2out_map[name] = ornts[i]
          if not out2in:
              return in2out_map
      if out2in:
          out2in_map = {}
          for i, name in enumerate(coordmap.function_range.coord_names):
              in_i = ornts.index(i) if i in ornts else None
              out2in_map[i] = in_i
              out2in_map[name] = in_i
          if not in2out:
              return out2in_map
      return in2out_map, out2in_map
  
imports: import warnings
  import numpy
  import numpy.linalg
  from nibabel import io_orientation
  from nibabel.affines import from_matvec, to_matvec
  from .coordinate_system import CoordinateSystem, is_coordsys, safe_dtype
  from .coordinate_system import product
label_desc: Use image node_id 18 for calling a global function with example usage: axmap(coordmap, direction, fix0) and returns: in2out_map,  out2in_map, in2out_map, out2in_map