code: def test_5d(data_dict):
      # What happened to a 5d image? We should get 4d images back
      img = data_dict["fmridata"]
      data = img.get_fdata()
      # Make a last input and output axis called 'v'
      vcs = CS("v")
      xtra_cmap = AffineTransform(vcs, vcs, np.eye(2))
      cmap_5d = cm_product(img.coordmap, xtra_cmap)
      data_5d = data.reshape(data.shape + (1,))
      fived = Image(data_5d, cmap_5d)
      mask = data_dict["mask"]
      mask_data = mask.get_fdata()
      mask_data = mask_data.reshape(mask_data.shape + (1,))
      cmap_4d = cm_product(mask.coordmap, xtra_cmap)
      mask4d = Image(mask_data, cmap_4d)
      nimages = data_dict["nimages"]
      ntotal = nimages - 1
      ncomp = 5
      p = pca_image(fived, "t", mask4d, ncomp=ncomp)
      assert _rank(p) == ntotal
      assert p["basis_vectors over t"].shape == (nimages, ntotal)
      assert p["basis_projections"].shape == data.shape[:3] + (ncomp, 1)
      assert p["pcnt_var"].shape == (ntotal,)
      assert_almost_equal(p["pcnt_var"].sum(), 100.0)
  
      assert p["basis_projections"].axes.coord_names == (
          "i",
          "j",
          "k",
          "PCA components",
          "v",
      )
      assert_array_equal(
          p["basis_projections"].coordmap.affine, fived.coordmap.affine
      )
      # flip the PCA dimension to end
      data_5d = data.reshape(data.shape[:3] + (1, data.shape[3]))
      # Make the last axis name be 'group'.  't' is not a length 1 dimension we
      # are going to leave as is
      gcs = CS(["group"])
      xtra_cmap = AffineTransform(gcs, gcs, np.eye(2))
      cmap_5d = cm_product(img.coordmap, xtra_cmap)
      fived = Image(data_5d, cmap_5d)
      # Give the mask a 't' dimension, but no group dimension
      mask = data_dict["mask"]
      mask_data = mask.get_fdata()
      mask_data = mask_data.reshape(mask_data.shape + (1,))
      # We need to replicate the time scaling of the image cmap, hence the 2. in
      # the affine
      xtra_cmap = AffineTransform(CS("t"), CS("t"), np.diag([2.0, 1]))
      cmap_4d = cm_product(mask.coordmap, xtra_cmap)
      mask4d = Image(mask_data, cmap_4d)
      nimages = data_dict["nimages"]
      ntotal = nimages - 1
      ncomp = 5
      # We can now show the axis does not have to be time
      p = pca_image(fived, mask=mask4d, ncomp=ncomp, axis="group")
      assert p["basis_vectors over group"].shape == (nimages, ntotal)
      assert p["basis_projections"].axes.coord_names == (
          "i",
          "j",
          "k",
          "t",
          "PCA components",
      )
      assert p["basis_projections"].shape == data.shape[:3] + (1, ncomp)
  
imports: import numpy
  import pytest
  from nibabel.affines import from_matvec
  from numpy.testing import assert_almost_equal, assert_array_equal
  from ....core.api import AffineTransform, Image
  from ....core.api import CoordinateSystem
  from ....core.image.image import rollimg
  from ....core.reference.coordinate_map import AxisError, drop_io_dim
  from ....core.reference.coordinate_map import product
  from ....io.api import load_image
  from ....testing import funcfile
  from ..pca import pca
  from ..pca import pca_image
  from .test_pca import res2pos1
label_desc: Use image node_id 11 for calling a global function with example usage: test_5d(data_dict) without return types