code: def test_peak_directions_nl():
      def discrete_eval(sphere):
          return abs(sphere.vertices).sum(-1)
  
      directions, values = peak_directions_nl(discrete_eval)
      assert_equal(directions.shape, (4, 3))
      assert_array_almost_equal(abs(directions), 1 / np.sqrt(3))
      assert_array_equal(values, abs(directions).sum(-1))
  
      # Test using a different sphere
      sphere = unit_icosahedron.subdivide(4)
      directions, values = peak_directions_nl(
          discrete_eval, sphere=sphere
      )
      assert_equal(directions.shape, (4, 3))
      assert_array_almost_equal(abs(directions), 1 / np.sqrt(3))
      assert_array_equal(values, abs(directions).sum(-1))
  
      # Test the relative_peak_threshold
      def discrete_eval(sphere):
          A = abs(sphere.vertices).sum(-1)
          x, y, z = sphere.vertices.T
          B = 1 + (x * z > 0) + 2 * (y * z > 0)
          return A * B
  
      directions, values = peak_directions_nl(discrete_eval, 0.01)
      assert_equal(directions.shape, (4, 3))
  
      directions, values = peak_directions_nl(discrete_eval, 0.3)
      assert_equal(directions.shape, (3, 3))
  
      directions, values = peak_directions_nl(discrete_eval, 0.6)
      assert_equal(directions.shape, (2, 3))
  
      directions, values = peak_directions_nl(discrete_eval, 0.8)
      assert_equal(directions.shape, (1, 3))
      assert_almost_equal(values, 4 * 3 / np.sqrt(3))
  
      # Test odfs with large areas of zero
      def discrete_eval(sphere):
          A = abs(sphere.vertices).sum(-1)
          x, y, z = sphere.vertices.T
          B = (x * z > 0) + 2 * (y * z > 0)
          return A * B
  
      directions, values = peak_directions_nl(discrete_eval, 0.0)
      assert_equal(directions.shape, (3, 3))
  
      directions, values = peak_directions_nl(discrete_eval, 0.6)
      assert_equal(directions.shape, (2, 3))
  
      directions, values = peak_directions_nl(discrete_eval, 0.8)
      assert_equal(directions.shape, (1, 3))
      assert_almost_equal(values, 3 * 3 / np.sqrt(3))
  
imports: import warnings
  import numpy
  import pickle
  from io import BytesIO
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal, assert_equal, assert_
  from dipy.reconst.odf import OdfFit, OdfModel, gfa
  from dipy.direction.peaks import peaks_from_model, peak_directions, peak_directions_nl, reshape_peaks_for_visualization
  from dipy.core.subdivide_octahedron import create_unit_hemisphere
  from dipy.core.sphere import unit_icosahedron
  from dipy.sims.voxel import multi_tensor, multi_tensor_odf
  from dipy.data import get_fnames, get_sphere, default_sphere
  from dipy.core.gradients import gradient_table, GradientTable
  from dipy.core.sphere_stats import angular_similarity
  from dipy.core.sphere import HemiSphere
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.reconst.shm import descoteaux07_legacy_msg, tournier07_legacy_msg
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 1 for calling a global function with example usage: test_peak_directions_nl() and returns: abs, unknown, unknown