code: def test_near_roi():
      streamlines = [
          np.array([[0.0, 0.0, 0.9], [1.9, 0.0, 0.0], [3, 2.0, 2.0]]),
          np.array([[0.1, 0.0, 0], [0, 1.0, 1.0], [0, 2.0, 2.0]]),
          np.array([[2, 2, 2], [3, 3, 3]]),
      ]
  
      mask = np.zeros((4, 4, 4), dtype=bool)
      mask[0, 0, 0] = True
      mask[1, 0, 0] = True
  
      npt.assert_array_equal(
          near_roi(streamlines, np.eye(4), mask, tol=1),
          np.array([True, True, False]),
      )
      npt.assert_array_equal(
          near_roi(streamlines, np.eye(4), mask),
          np.array([False, True, False]),
      )
  
      # test for handling of various forms of null streamlines
      # including a streamline from previous test because near_roi / tol
      # can't handle completely empty streamline collections
      streamlines_null = [
          np.array([[0.0, 0.0, 0.9], [1.9, 0.0, 0.0], [3, 2.0, 2.0]]),
          np.array([[], [], []]).T,
          np.array([]),
          [],
      ]
      npt.assert_array_equal(
          near_roi(streamlines_null, np.eye(4), mask, tol=1),
          np.array([True, False, False, False]),
      )
      npt.assert_array_equal(
          near_roi(streamlines_null, np.eye(4), mask),
          np.array([False, False, False, False]),
      )
  
      # If there is an affine, we need to use it:
      affine = np.eye(4)
      affine[:, 3] = [-1, 100, -20, 1]
      # Transform the streamlines:
      x_streamlines = [sl + affine[:3, 3] for sl in streamlines]
      npt.assert_array_equal(
          near_roi(x_streamlines, affine, mask, tol=1),
          np.array([True, True, False]),
      )
      npt.assert_array_equal(
          near_roi(x_streamlines, affine, mask, tol=None),
          np.array([False, True, False]),
      )
  
      # Test for use of the 'all' mode:
      npt.assert_array_equal(
          near_roi(x_streamlines, affine, mask, tol=None, mode="all"),
          np.array([False, False, False]),
      )
  
      mask[0, 1, 1] = True
      mask[0, 2, 2] = True
      # Test for use of the 'all' mode, also testing that setting the tolerance
      # to a very small number gets overridden:
      with warnings.catch_warnings():
          warnings.simplefilter("ignore")
          npt.assert_array_equal(
              near_roi(
                  x_streamlines, affine, mask, tol=0.1, mode="all"
              ),
              np.array([False, True, False]),
          )
  
      mask[2, 2, 2] = True
      mask[3, 3, 3] = True
      npt.assert_array_equal(
          near_roi(x_streamlines, affine, mask, tol=None, mode="all"),
          np.array([False, True, True]),
      )
  
      # Test for use of endpoints as selection criteria:
      mask = np.zeros((4, 4, 4), dtype=bool)
      mask[0, 1, 1] = True
      mask[3, 2, 2] = True
  
      npt.assert_array_equal(
          near_roi(
              streamlines, np.eye(4), mask, tol=0.87, mode="either_end"
          ),
          np.array([True, False, False]),
      )
  
      npt.assert_array_equal(
          near_roi(
              streamlines, np.eye(4), mask, tol=0.87, mode="both_end"
          ),
          np.array([False, False, False]),
      )
  
      mask[0, 0, 0] = True
      mask[0, 2, 2] = True
      npt.assert_array_equal(
          near_roi(streamlines, np.eye(4), mask, mode="both_end"),
          np.array([False, True, False]),
      )
  
      # Test with a generator input:
      def generate_sl(streamlines):
          for sl in streamlines:
              yield sl
  
      npt.assert_array_equal(
          near_roi(
              generate_sl(streamlines), np.eye(4), mask, mode="both_end"
          ),
          np.array([False, True, False]),
      )
  
imports: import warnings
  import numpy
  import pytest
  from dipy.tracking import metrics
  from dipy.tracking.streamline import transform_streamlines
  from dipy.tracking.utils import connectivity_matrix, density_map, length, ndbincount, reduce_labels, seeds_from_mask, random_seeds_from_mask, target, target_line_based, unique_rows, near_roi, reduce_rois, path_length, _min_at, max_angle_from_curvature, min_radius_curvature_from_angle
  from dipy.tracking._utils import _to_voxel_coordinates
  from dipy.tracking.vox2track import streamline_mapping
  import numpy.testing
  from dipy.testing import assert_true
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 11 for calling a global function with example usage: test_near_roi() without return types