code: def test_sphere_extraction(rng):
      """Test sphere extraction."""
      data = rng.random((3, 3, 3, 5))
      img = nibabel.Nifti1Image(data, np.eye(4))
      masker = NiftiSpheresMasker([(1, 1, 1)], radius=1)
  
      # Check attributes defined at fit
      assert not hasattr(masker, "seeds_")
      assert not hasattr(masker, "n_elements_")
  
      masker.fit()
  
      # Check attributes defined at fit
      assert hasattr(masker, "seeds_")
      assert hasattr(masker, "n_elements_")
      assert masker.n_elements_ == 1
  
      # Test the fit
      masker.fit()
  
      # Test the transform
      s = masker.transform(img)
      mask = np.zeros((3, 3, 3), dtype=bool)
      mask[:, 1, 1] = True
      mask[1, :, 1] = True
      mask[1, 1, :] = True
      assert_array_equal(s[:, 0], np.mean(data[mask], axis=0))
  
      # Now with a mask
      mask_img = np.zeros((3, 3, 3))
      mask_img[1, :, :] = 1
      mask_img = nibabel.Nifti1Image(mask_img, np.eye(4))
      masker = NiftiSpheresMasker(
          [(1, 1, 1)], radius=1, mask_img=mask_img
      )
      masker.fit()
      s = masker.transform(img)
      assert_array_equal(
          s[:, 0],
          np.mean(
              data[np.logical_and(mask, get_data(mask_img))], axis=0
          ),
      )
  
imports: import warnings
  import nibabel
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from nilearn._utils import data_gen
  from nilearn.image import get_data, new_img_like
  from nilearn.maskers import NiftiSpheresMasker
label_desc: Use image node_id 2 for calling a global function with example usage: test_sphere_extraction(rng) without return types