code: def test_odf_slicer(interactive=False):
      # Prepare our data
      sphere = get_sphere("repulsion100")
      shape = (11, 11, 11, sphere.vertices.shape[0])
      odfs = np.ones(shape)
  
      affine = np.array(
          [
              [2.0, 0.0, 0.0, 3.0],
              [0.0, 2.0, 0.0, 3.0],
              [0.0, 0.0, 2.0, 1.0],
              [0.0, 0.0, 0.0, 1.0],
          ]
      )
      mask = np.ones(odfs.shape[:3], bool)
      mask[:4, :4, :4] = False
  
      # Test that affine and mask work
      odf_actor = actor.odf_slicer(
          odfs,
          sphere=sphere,
          affine=affine,
          mask=mask,
          scale=0.25,
          colormap="blues",
      )
  
      k = 2
      I, J, _ = odfs.shape[:3]
      odf_actor.display_extent(0, I - 1, 0, J - 1, k, k)
  
      scene = window.Scene()
      scene.add(odf_actor)
      scene.reset_camera()
      scene.reset_clipping_range()
  
      if interactive:
          window.show(scene, reset_camera=False)
  
      arr = window.snapshot(scene)
      report = window.analyze_snapshot(arr, find_objects=True)
      npt.assert_equal(report.objects, 11 * 11 - 16)
  
      # Test that global colormap works
      odf_actor = actor.odf_slicer(
          odfs,
          sphere=sphere,
          mask=mask,
          scale=0.25,
          colormap="blues",
          norm=False,
          global_cm=True,
      )
      scene.clear()
      scene.add(odf_actor)
      scene.reset_camera()
      scene.reset_clipping_range()
      if interactive:
          window.show(scene)
  
      # Test that the most basic odf_slicer instantiation works
      odf_actor = actor.odf_slicer(odfs)
      scene.clear()
      scene.add(odf_actor)
      scene.reset_camera()
      scene.reset_clipping_range()
      if interactive:
          window.show(scene)
  
      # Test that odf_slicer.display works properly
      scene.clear()
      scene.add(odf_actor)
      scene.add(actor.axes((11, 11, 11)))
      for i in range(11):
          odf_actor.display(i, None, None)
          if interactive:
              window.show(scene)
      for j in range(11):
          odf_actor.display(None, j, None)
          if interactive:
              window.show(scene)
  
      # With mask equal to zero everything should be black
      mask = np.zeros(odfs.shape[:3])
      odf_actor = actor.odf_slicer(
          odfs,
          sphere=sphere,
          mask=mask,
          scale=0.25,
          colormap="blues",
          norm=False,
          global_cm=True,
      )
      scene.clear()
      scene.add(odf_actor)
      scene.reset_camera()
      scene.reset_clipping_range()
      if interactive:
          window.show(scene)
  
      # global_cm=True with colormap=None should raise an error
      npt.assert_raises(
          OSError,
          actor.odf_slicer,
          odfs,
          sphere=sphere,
          mask=None,
          scale=0.25,
          colormap=None,
          norm=False,
          global_cm=True,
      )
  
      # Dimension mismatch between sphere vertices and number
      # of SF coefficients will raise an error.
      npt.assert_raises(
          ValueError,
          actor.odf_slicer,
          odfs,
          mask=None,
          sphere=get_sphere("repulsion200"),
          scale=0.25,
      )
  
      # colormap=None and global_cm=False results in directionally encoded colors
      odf_actor = actor.odf_slicer(
          odfs,
          sphere=sphere,
          mask=None,
          scale=0.25,
          colormap=None,
          norm=False,
          global_cm=False,
      )
      scene.clear()
      scene.add(odf_actor)
      scene.reset_camera()
      scene.reset_clipping_range()
      if interactive:
          window.show(scene)
  
      # Test that SH coefficients input works
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          B = sh_to_sf_matrix(sphere, sh_order=4, return_inv=False)
      odfs = np.zeros((11, 11, 11, B.shape[0]))
      odfs[..., 0] = 1.0
      odf_actor = actor.odf_slicer(odfs, sphere=sphere, B_matrix=B)
  
      scene.clear()
      scene.add(odf_actor)
      scene.reset_camera()
      scene.reset_clipping_range()
      if interactive:
          window.show(scene)
  
      # Dimension mismatch between sphere vertices and dimension of
      # B matrix will raise an error.
      npt.assert_raises(
          ValueError,
          actor.odf_slicer,
          odfs,
          mask=None,
          sphere=get_sphere("repulsion200"),
      )
  
      # Test that constant colormap color works. Also test that sphere
      # normals are oriented correctly. Will show purple spheres with
      # a white contour.
      odf_contour = actor.odf_slicer(
          odfs, sphere=sphere, B_matrix=B, colormap=(255, 255, 255)
      )
      odf_contour.GetProperty().SetAmbient(1.0)
      odf_contour.GetProperty().SetFrontfaceCulling(True)
  
      odf_actor = actor.odf_slicer(
          odfs,
          sphere=sphere,
          B_matrix=B,
          colormap=(255, 0, 255),
          scale=0.4,
      )
      scene.clear()
      scene.add(odf_contour)
      scene.add(odf_actor)
      scene.reset_camera()
      scene.reset_clipping_range()
      if interactive:
          window.show(scene)
  
      # Test that we can change the sphere on an active actor
      new_sphere = get_sphere("symmetric362")
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          new_B = sh_to_sf_matrix(
              new_sphere, sh_order=4, return_inv=False
          )
      odf_actor.update_sphere(
          new_sphere.vertices, new_sphere.faces, new_B
      )
      if interactive:
          window.show(scene)
  
      del odf_actor
      del odfs
  
imports: import warnings
  import pytest
  import numpy
  import numpy.testing
  from dipy.testing.decorators import use_xvfb, set_random_number_generator
  from dipy.utils.optpkg import optional_package
  from dipy.data import get_sphere
  from dipy.align.reslice import reslice
  from dipy.data import read_stanford_labels
  from dipy.reconst.shm import CsaOdfModel
  from dipy.data import default_sphere
  from dipy.direction import peaks_from_model
  from dipy.tracking import utils
  from dipy.tracking.stopping_criterion import ThresholdStoppingCriterion
  from dipy.tracking.local_tracking import LocalTracking
  from dipy.reconst.shm import descoteaux07_legacy_msg, sh_to_sf_matrix
  from dipy.align.tests.test_streamlinear import fornix_streamlines
  from dipy.tracking.streamline import center_streamlines, transform_streamlines
  from dipy.reconst.dti import color_fa, fractional_anisotropy
label_desc: Use image node_id 4 for calling a global function with example usage: test_odf_slicer(interactive) without return types