code: def test_save_toffset():
      # Check toffset only gets set for time
      shape = (2, 3, 4, 5, 6, 7)
      data = np.random.normal(size=shape)
      aff = from_matvec(
          np.diag([2.0, 3, 4, 5, 6, 7]), [11, 12, 13, 14, 15, 16]
      )
      xyz_names = talairach_csm(3).coord_names
      in_cs = CS("ijklmn")
      for t_name in "t", "time":
          cmap = AT(in_cs, CS(xyz_names + (t_name, "q", "r")), aff)
          ni_img = nipy2nifti(Image(data, cmap))
          assert get_header(ni_img)["toffset"] == 14
      for time_like in ("hz", "ppm", "rads"):
          cmap = AT(in_cs, CS(xyz_names + (time_like, "q", "r")), aff)
          ni_img = nipy2nifti(Image(data, cmap))
          assert get_header(ni_img)["toffset"] == 0
      # Check that non-matching time causes a nifti error when toffset !=0
      shape_shifted = (2, 3, 4, 6, 5, 7)
      for t_name in "t", "time":
          # No toffset, this is OK
          cmap = AT(
              CS(("i", "j", "k", "u", t_name, "v")),
              CS(xyz_names + ("u", t_name, "v")),
              np.diag([3, 4, 5, 6, 0, 7, 1]),
          )
          assert nipy2nifti(Image(data, cmap)).shape == shape_shifted
          # toffset with 0 on TR (time) diagonal
          aff_z1 = from_matvec(
              np.diag([2.0, 3, 4, 5, 0, 7]), [11, 12, 13, 14, 15, 16]
          )
          cmap = AT(
              CS(("i", "j", "k", "u", t_name, "v")),
              CS(xyz_names + ("u", t_name, "v")),
              aff_z1,
          )
          # Default is to fix the zero
          assert nipy2nifti(Image(data, cmap)).shape == shape_shifted
          assert (
              nipy2nifti(Image(data, cmap), fix0=True).shape
              == shape_shifted
          )
          # Unless fix0 is False
          pytest.raises(
              NiftiError, nipy2nifti, Image(data, cmap), fix0=False
          )
          # Fix doesn't work if there is more than one zero row and column
          aff_z2 = from_matvec(
              np.diag([2.0, 3, 4, 0, 0, 7]), [11, 12, 13, 14, 15, 16]
          )
          cmap = AT(
              CS(("i", "j", "k", "u", t_name, "v")),
              CS(xyz_names + ("u", t_name, "v")),
              aff_z2,
          )
          pytest.raises(
              NiftiError, nipy2nifti, Image(data, cmap), fix0=True
          )
      # zeros on the diagonal are not a problem for non-time, with toffset,
      # because we don't need to set the 'time' part of the translation vector,
      # and therefore we don't need to know which *output axis* is time-like
      for t_name in "hz", "ppm", "rads":
          cmap = AT(
              CS(("i", "j", "k", "u", t_name, "v")),
              CS(xyz_names + ("u", t_name, "v")),
              aff_z1,
          )
          assert (
              nipy2nifti(Image(data, cmap), fix0=False).shape
              == shape_shifted
          )
          cmap = AT(
              CS(("i", "j", "k", "u", t_name, "v")),
              CS(xyz_names + ("u", t_name, "v")),
              aff_z2,
          )
          assert (
              nipy2nifti(Image(data, cmap), fix0=False).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 11 for calling a global function with example usage: test_save_toffset() without return types