code: def test_time_like_matching():
      # Check checks for matching time-like axes
      shape = (2, 3, 4, 5, 6)
      shape_shifted = (2, 3, 4, 6, 5)
      data = np.random.normal(size=shape)
      aff = np.diag([3, 4, 5, 6, 7, 1])
      mni_names = mni_csm(3).coord_names
      time_cans = ("t", "hz", "ppm", "rads")
      aliases = {
          "t": "time",
          "hz": "frequency-hz",
          "ppm": "concentration-ppm",
          "rads": "radians/s",
      }
      all_names = set(time_cans + tuple(v for v in aliases.values()))
      for time_like in time_cans:
          alias = aliases[time_like]
          for name in (time_like, alias):
              # Names match
              cmap = AT(
                  CS(("i", "j", "k", name, "u")),
                  CS(mni_names + (name, "u")),
                  aff,
              )
              assert nipy2nifti(Image(data, cmap)).shape == shape
              cmap = AT(
                  CS(("i", "j", "k", "u", name)),
                  CS(mni_names + ("u", name)),
                  aff,
              )
              assert (
                  nipy2nifti(Image(data, cmap)).shape == shape_shifted
              )
              # No time-like in output is OK
              cmap = AT(
                  CS(("i", "j", "k", "u", name)),
                  CS(mni_names + ("u", "v")),
                  aff,
              )
              assert (
                  nipy2nifti(Image(data, cmap)).shape == shape_shifted
              )
              # No time-like in input is OK
              cmap = AT(
                  CS(("i", "j", "k", "u", "v")),
                  CS(mni_names + ("u", name)),
                  aff,
              )
              assert (
                  nipy2nifti(Image(data, cmap)).shape == shape_shifted
              )
              # Time-like in both, but not matching, not OK
              cmap = AT(
                  CS(("i", "j", "k", "u", name)),
                  CS(mni_names + (name, "u")),
                  aff,
              )
              pytest.raises(NiftiError, nipy2nifti, Image(data, cmap))
              # Time like in both with no match between but no match elsewhere
              # Actually this does cause a problem for non-zero time offset and
              # time axes, but we test that elsewhere.
              cmap = AT(
                  CS(("i", "j", "k", "u", name)),
                  CS(mni_names + ("u", name)),
                  np.diag([3, 4, 5, 6, 0, 1]),
              )
              assert (
                  nipy2nifti(Image(data, cmap)).shape == shape_shifted
              )
              cmap = AT(
                  CS(("i", "j", "k", "u", name)),
                  CS(mni_names + (name, "u")),
                  np.diag([3, 4, 5, 0, 0, 1]),
              )
              assert (
                  nipy2nifti(Image(data, cmap)).shape == shape_shifted
              )
          # Matching to own alias is OK
          cmap = AT(
              CS(("i", "j", "k", time_like, "u")),
              CS(mni_names + (alias, "u")),
              aff,
          )
          assert nipy2nifti(Image(data, cmap)).shape == shape
          cmap = AT(
              CS(("i", "j", "k", alias, "u")),
              CS(mni_names + (time_like, "u")),
              aff,
          )
          assert nipy2nifti(Image(data, cmap)).shape == shape
          # But not to another time-like name
          others = all_names.difference((time_like, alias))
          for name in others:
              cmap = AT(
                  CS(("i", "j", "k", time_like, "u")),
                  CS(mni_names + (name, "u")),
                  aff,
              )
              pytest.raises(NiftiError, nipy2nifti, Image(data, cmap))
              cmap = AT(
                  CS(("i", "j", "k", name, "u")),
                  CS(mni_names + (time_like, "u")),
                  aff,
              )
              pytest.raises(NiftiError, nipy2nifti, Image(data, cmap))
          # It's OK to have more than one time-like, but the order of recognition
          # is 't', 'hz', 'ppm', 'rads'
          for i, better in enumerate(time_cans[:-1]):
              for worse in time_cans[i + 1 :]:
                  cmap = AT(
                      CS(("i", "j", "k", better, worse)),
                      CS(mni_names + (better, worse)),
                      aff,
                  )
                  assert nipy2nifti(Image(data, cmap)).shape == shape
                  cmap = AT(
                      CS(("i", "j", "k", worse, better)),
                      CS(mni_names + (worse, better)),
                      aff,
                  )
                  assert (
                      nipy2nifti(Image(data, cmap)).shape
                      == shape_shifted
                  )
                  # Even if better is only in output
                  cmap = AT(
                      CS(("i", "j", "k", worse, "u")),
                      CS(mni_names + (worse, better)),
                      aff,
                  )
                  assert (
                      nipy2nifti(Image(data, cmap)).shape
                      == shape_shifted
                  )
  
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 7 for calling a global function with example usage: test_time_like_matching() without return types