code: def test_mm_scaling():
      # Test the micron and meter scale the affine right
      data = np.random.normal(size=list(range(4)))
      xyz_aff = from_matvec(np.diag([2, 3, 4]), [11, 12, 13])
      exp_aff = from_matvec(np.diag([2, 3, 4, 1]), [11, 12, 13, 0])
      in_cs = CS("ijkt", name="voxels")
      out_cs = aligned_csm(4)
      # No space scaling
      ni_img = nib.Nifti1Image(data, xyz_aff)
      hdr = get_header(ni_img)
      assert hdr.get_xyzt_units() == ("unknown", "unknown")
      assert nifti2nipy(ni_img).coordmap == AT(in_cs, out_cs, exp_aff)
      # mm is assumed
      hdr.set_xyzt_units("mm")
      assert nifti2nipy(ni_img).coordmap == AT(in_cs, out_cs, exp_aff)
      # microns !
      hdr.set_xyzt_units("micron")
      scaler = np.diag([1 / 1000.0, 1 / 1000.0, 1 / 1000.0, 1, 1])
      with pytest.warns(UserWarning, match='"micron" space scaling'):
          out_img = nifti2nipy(ni_img)
      assert out_img.coordmap == AT(
          in_cs, out_cs, np.dot(scaler, exp_aff)
      )
      # mm again !  This test implicitly asserts that the nifti image affine is
      # not being changed by the conversion routine, otherwise we'd pick up the
      # microns scaling above.
      hdr.set_xyzt_units("mm")
      out_img = nifti2nipy(ni_img)
      assert out_img.coordmap == AT(in_cs, out_cs, exp_aff)
      # meters !
      hdr.set_xyzt_units("meter")
      scaler = np.diag([1000.0, 1000.0, 1000.0, 1, 1])
      with pytest.warns(UserWarning, match='"meter" space scaling'):
          out_img = nifti2nipy(ni_img)
      assert out_img.coordmap == AT(
          in_cs, out_cs, np.dot(scaler, exp_aff)
      )
  
imports: import warnings
  from copy import copy
  import nibabel
  import numpy
  import pytest
  from nibabel.affines import from_matvec
  from nibabel.spatialimages import HeaderDataError
  from numpy.testing import assert_array_equal
  from ...core.api import AffineTransform
  from ...core.api import CoordinateSystem
  from ...core.api import Image
  from ...core.reference.spaces import aligned_csm, mni_csm, scanner_csm, talairach_csm, unknown_csm, unknown_space, vox2mni
  from ...testing import anatfile, funcfile
  from ..files import load
  from ..nibcompat import get_affine, get_header
  from ..nifti_ref import NiftiError, nifti2nipy, nipy2nifti
label_desc: Use image node_id 22 for calling a global function with example usage: test_mm_scaling() without return types