code: def test_stop_conditions():
      """This tests that the Local Tracker behaves as expected for the
      following tissue types.
      """
      # StreamlineStatus.TRACKPOINT = 1
      # StreamlineStatus.ENDPOINT = 2
      # StreamlineStatus.INVALIDPOINT = 0
      tissue = np.array(
          [
              [2, 1, 1, 2, 1],
              [2, 2, 1, 1, 2],
              [1, 1, 1, 1, 1],
              [1, 1, 1, 2, 2],
              [0, 1, 1, 1, 2],
              [0, 1, 1, 0, 2],
              [1, 0, 1, 1, 1],
              [2, 1, 2, 0, 0],
          ]
      )
      tissue = tissue[None]
  
      sphere = HemiSphere.from_sphere(unit_octahedron)
      pmf_lookup = np.array(
          [
              [
                  0.0,
                  0.0,
                  0.0,
              ],
              [0.0, 0.0, 1.0],
          ]
      )
      pmf = pmf_lookup[(tissue > 0).astype("int")]
  
      # Create a seeds along
      x = np.array([0.0, 0, 0, 0, 0, 0, 0, 0])
      y = np.array([0.0, 1, 2, 3, 4, 5, 6, 7])
      z = np.array([1.0, 1, 1, 0, 1, 1, 1, 1])
      seeds = np.column_stack([x, y, z])
  
      # Set up tracking
      endpoint_mask = tissue == StreamlineStatus.ENDPOINT
      invalidpoint_mask = tissue == StreamlineStatus.INVALIDPOINT
      sc = ActStoppingCriterion(endpoint_mask, invalidpoint_mask)
      dg = ProbabilisticDirectionGetter.from_pmf(pmf, 60, sphere)
  
      # valid streamlines only
      streamlines_generator = LocalTracking(
          direction_getter=dg,
          stopping_criterion=sc,
          seeds=seeds,
          affine=np.eye(4),
          step_size=1.0,
          return_all=False,
      )
      streamlines_not_all = iter(streamlines_generator)
  
      # all streamlines
      streamlines_all_generator = LocalTracking(
          direction_getter=dg,
          stopping_criterion=sc,
          seeds=seeds,
          affine=np.eye(4),
          step_size=1.0,
          return_all=True,
      )
      streamlines_all = iter(streamlines_all_generator)
  
      # Check that the first streamline stops at 1 and 2 (ENDPOINT)
      y = 0
      sl = next(streamlines_not_all)
      npt.assert_equal(sl[0], [0, y, 1])
      npt.assert_equal(sl[-1], [0, y, 2])
      npt.assert_equal(len(sl), 2)
  
      sl = next(streamlines_all)
      npt.assert_equal(sl[0], [0, y, 1])
      npt.assert_equal(sl[-1], [0, y, 2])
      npt.assert_equal(len(sl), 2)
  
      # Check that the next streamline stops at 1 and 3 (ENDPOINT)
      y = 1
      sl = next(streamlines_not_all)
      npt.assert_equal(sl[0], [0, y, 1])
      npt.assert_equal(sl[-1], [0, y, 3])
      npt.assert_equal(len(sl), 3)
  
      sl = next(streamlines_all)
      npt.assert_equal(sl[0], [0, y, 1])
      npt.assert_equal(sl[-1], [0, y, 3])
      npt.assert_equal(len(sl), 3)
  
      # This streamline should be the same as above. This row does not have
      # ENDPOINTs, but the streamline should stop at the edge and not include
      # OUTSIDEIMAGE points.
      y = 2
      sl = next(streamlines_not_all)
      npt.assert_equal(sl[0], [0, y, 0])
      npt.assert_equal(sl[-1], [0, y, 4])
      npt.assert_equal(len(sl), 5)
  
      sl = next(streamlines_all)
      npt.assert_equal(sl[0], [0, y, 0])
      npt.assert_equal(sl[-1], [0, y, 4])
      npt.assert_equal(len(sl), 5)
  
      # If we seed on the edge, the first (or last) point in the streamline
      # should be the seed.
      y = 3
      sl = next(streamlines_not_all)
      npt.assert_equal(sl[0], seeds[y])
  
      sl = next(streamlines_all)
      npt.assert_equal(sl[0], seeds[y])
  
      # The last 3 seeds should not produce streamlines,
      # INVALIDPOINT streamlines are rejected (return_all=False).
      npt.assert_equal(len(list(streamlines_not_all)), 0)
  
      # The last 3 seeds should produce invalid streamlines,
      # INVALIDPOINT streamlines are kept (return_all=True).
      # The streamline stops at 1 (INVALIDPOINT) and 3 (ENDPOINT)
      y = 4
      sl = next(streamlines_all)
      npt.assert_equal(sl[0], [0, y, 1])
      npt.assert_equal(sl[-1], [0, y, 3])
      npt.assert_equal(len(sl), 3)
  
      # The streamline stops at 0 (INVALIDPOINT) and 2 (INVALIDPOINT)
      y = 5
      sl = next(streamlines_all)
      npt.assert_equal(sl[0], [0, y, 1])
      npt.assert_equal(sl[-1], [0, y, 2])
      npt.assert_equal(len(sl), 2)
  
      # The streamline should contain only one point, the seed point,
      # because no valid initial direction was returned.
      y = 6
      sl = next(streamlines_all)
      npt.assert_equal(sl[0], seeds[y])
      npt.assert_equal(sl[-1], seeds[y])
      npt.assert_equal(len(sl), 1)
  
      # The streamline should contain only one point, the seed point,
      # because no valid neighboring voxel (ENDPOINT)
      y = 7
      sl = next(streamlines_all)
      npt.assert_equal(sl[0], seeds[y])
      npt.assert_equal(sl[-1], seeds[y])
      npt.assert_equal(len(sl), 1)
  
imports: from logging import warn
  import warnings
  import nibabel
  import numpy
  import numpy.testing
  from dipy.core.gradients import gradient_table
  from dipy.core.sphere import HemiSphere, unit_octahedron
  from dipy.data import get_fnames, get_sphere
  from dipy.direction import BootDirectionGetter, ClosestPeakDirectionGetter, DeterministicMaximumDirectionGetter, PeaksAndMetrics, ProbabilisticDirectionGetter, PTTDirectionGetter
  from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel
  from dipy.reconst.shm import descoteaux07_legacy_msg
  from dipy.tracking.local_tracking import LocalTracking, ParticleFilteringTracking
  from dipy.tracking.streamline import Streamlines
  from dipy.tracking.stopping_criterion import ActStoppingCriterion, BinaryStoppingCriterion, ThresholdStoppingCriterion, StreamlineStatus
  from dipy.tracking.utils import random_seeds_from_mask, seeds_from_mask
  from dipy.sims.voxel import single_tensor, multi_tensor
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 2 for calling a global function with example usage: test_stop_conditions() without return types