code: def test_component_sign(mask_img):
      # We should have a heuristic that flips the sign of components in
      # CanICA to have more positive values than negative values, for
      # instance by making sure that the largest value is positive.
  
      data, _, rng = _make_canica_test_data(noisy=True)
  
      # run CanICA many times (this is known to produce different results)
      canica = CanICA(n_components=4, random_state=rng, mask=mask_img)
  
      for _ in range(3):
          canica.fit(data)
          for mp in iter_img(canica.components_img_):
              mp = get_data(mp)
  
              assert -mp.min() <= mp.max()
  
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 11 for calling a global function with example usage: test_component_sign(mask_img) without return types