code: def test_canica_square_img(mask_img):
      data, components, rng = _make_canica_test_data(n_subjects=8)
  
      # We do a large number of inits to be sure to find the good match
      canica = CanICA(
          n_components=4,
          random_state=rng,
          mask=mask_img,
          smoothing_fwhm=0.0,
          n_init=50,
      )
      canica.fit(data)
      maps = get_data(canica.components_img_)
      maps = np.rollaxis(maps, 3, 0)
  
      # FIXME: This could be done more efficiently, e.g. thanks to hungarian
      # Find pairs of matching components
      # compute the cross-correlation matrix between components
      mask = get_data(mask_img) != 0
      K = np.corrcoef(components[:, mask.ravel()], maps[:, mask])[
          4:, :4
      ]
  
      # K should be a permutation matrix, hence its coefficients
      # should all be close to 0 1 or -1
      K_abs = np.abs(K)
  
      assert np.sum(K_abs > 0.9) == 4
  
      K_abs[K_abs > 0.9] -= 1
  
      assert_array_almost_equal(K_abs, 0, 1)
  
imports: import numpy
  import pytest
  from nibabel import Nifti1Image
  from numpy.testing import assert_array_almost_equal
  from nilearn._utils.testing import write_imgs_to_path
  from nilearn.conftest import _affine_eye, _rng
  from nilearn.decomposition.canica import CanICA
  from nilearn.image import get_data, iter_img
  from nilearn.maskers import MultiNiftiMasker
label_desc: Use image node_id 9 for calling a global function with example usage: test_canica_square_img(mask_img) without return types