code: def test_density_map():
      # One streamline diagonal in volume
      streamlines = [np.array([np.arange(10)] * 3).T]
      shape = (10, 10, 10)
      x = np.arange(10)
      expected = np.zeros(shape)
      expected[x, x, x] = 1.0
      dm = density_map(streamlines, np.eye(4), shape)
      npt.assert_array_equal(dm, expected)
  
      # add streamline, make voxel_size smaller. Each streamline should only be
      # counted once, even if multiple points lie in a voxel
      streamlines.append(np.ones((5, 3)))
      shape = (5, 5, 5)
      x = np.arange(5)
      expected = np.zeros(shape)
      expected[x, x, x] = 1.0
      expected[0, 0, 0] += 1
      affine = np.eye(4) * 2
      affine[:3, 3] = 0.05
      dm = density_map(streamlines, affine, shape)
      npt.assert_array_equal(dm, expected)
      # should work with a generator
      dm = density_map(iter(streamlines), affine, shape)
      npt.assert_array_equal(dm, expected)
  
      # Test passing affine
      affine = np.diag([2, 2, 2, 1.0])
      affine[:3, 3] = 1.0
      dm = density_map(streamlines, affine, shape)
      npt.assert_array_equal(dm, expected)
  
      # Shift the image by 2 voxels, ie 4mm
      affine[:3, 3] -= 4.0
      expected_old = expected
      new_shape = [i + 2 for i in shape]
      expected = np.zeros(new_shape)
      expected[2:, 2:, 2:] = expected_old
      dm = density_map(streamlines, affine, new_shape)
      npt.assert_array_equal(dm, expected)
  
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 2 for calling a global function with example usage: test_density_map() without return types