code: def test_resid(data):
      # Data is projected onto k=10 dimensional subspace then has its mean
      # removed.  Should still have rank 10.
      k = 10
      ncomp = 5
      ntotal = k
      X = np.random.standard_normal((data["nimages"], k))
      p = pca(data["fmridata"], -1, ncomp=ncomp, design_resid=X)
      assert p["basis_vectors"].shape == (data["nimages"], ntotal)
      assert p["basis_projections"].shape == data["mask"].shape + (
          ncomp,
      )
      assert p["pcnt_var"].shape == (ntotal,)
      assert_almost_equal(p["pcnt_var"].sum(), 100.0)
      # if design_resid is None, we do not remove the mean, and we get
      # full rank from our data
      p = pca(data["fmridata"], -1, design_resid=None)
      rank = p["basis_vectors"].shape[1]
      assert rank == data["nimages"]
      rarr = reconstruct(p["basis_vectors"], p["basis_projections"], -1)
      # add back the sqrt MSE, because we standardized
      rmse = root_mse(data["fmridata"], axis=-1)[..., None]
      assert np.allclose(rarr * rmse, data["fmridata"])
  
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 17 for calling a global function with example usage: test_resid(data) without return types