code: def test_PCAMask(data):
      # for 2 and 4D case
      ntotal = data["nimages"] - 1
      ncomp = 5
      arr4d = data["fmridata"]
      mask3d = data["mask"]
      arr2d = arr4d.reshape((-1, data["nimages"]))
      mask1d = mask3d.reshape(-1)
      for arr, mask in (arr4d, mask3d), (arr2d, mask1d):
          p = pca(arr, -1, mask, ncomp=ncomp)
          assert p["basis_vectors"].shape == (data["nimages"], ntotal)
          assert p["basis_projections"].shape == mask.shape + (ncomp,)
          assert p["pcnt_var"].shape == (ntotal,)
          assert_almost_equal(p["pcnt_var"].sum(), 100.0)
      # Any reasonable datatype for mask
      for dt in (
          [np.bool_]
          + np.sctypes["int"]
          + np.sctypes["uint"]
          + np.sctypes["float"]
      ):
          p = pca(arr4d, -1, mask3d.astype(dt), ncomp=ncomp)
          assert p["basis_vectors"].shape == (data["nimages"], ntotal)
          assert p["basis_projections"].shape == mask3d.shape + (ncomp,)
          assert p["pcnt_var"].shape == (ntotal,)
          assert_almost_equal(p["pcnt_var"].sum(), 100.0)
      # Mask data shape must match
      pytest.raises(ValueError, pca, arr4d, -1, mask1d)
  
imports: import numpy
  import pytest
  from nipy.io.api import load_image
  from nipy.testing import assert_almost_equal, assert_array_almost_equal, funcfile
  from ..pca import pca
label_desc: Use image node_id 12 for calling a global function with example usage: test_PCAMask(data) without return types