code: def compress_streamlines_python(
      streamline, tol_error=0.01, max_segment_length=10
  ):
      """
      Python version of the FiberCompression found on
      https://github.com/scilus/FiberCompression.
      """
      if streamline.shape[0] <= 2:
          return streamline.copy()
  
      # Euclidean distance
      def segment_length(p1, p2):
          return np.sqrt(((p1 - p2) ** 2).sum())
  
      # Projection of a 3D point on a 3D line, minimal distance
      def dist_to_line(p1, p2, p0):
          return norm(np.cross(p2 - p1, p0 - p2)) / norm(p2 - p1)
  
      nb_points = 0
      compressed_streamline = np.zeros_like(streamline)
  
      # Copy first point since it is always kept.
      compressed_streamline[0, :] = streamline[0, :]
      nb_points += 1
      p1 = streamline[0]
      prev_id = 0
  
      for next_id, p2 in enumerate(streamline[2:], start=2):
          # Euclidean distance between last added point and current point.
          if segment_length(p1, p2) > max_segment_length:
              compressed_streamline[nb_points, :] = streamline[
                  next_id - 1, :
              ]
              nb_points += 1
              p1 = streamline[next_id - 1]
              prev_id = next_id - 1
              continue
  
          # Check that each point is not offset by more than `tol_error` mm.
          for o, p0 in enumerate(
              streamline[prev_id + 1 : next_id], start=prev_id + 1
          ):
              dist = dist_to_line(p1, p2, p0)
  
              if np.isnan(dist) or dist > tol_error:
                  compressed_streamline[nb_points, :] = streamline[
                      next_id - 1, :
                  ]
                  nb_points += 1
                  p1 = streamline[next_id - 1]
                  prev_id = next_id - 1
                  break
  
      # Copy last point since it is always kept.
      compressed_streamline[nb_points, :] = streamline[-1, :]
      nb_points += 1
  
      # Make sure the array have the correct size
      return compressed_streamline[:nb_points]
  
imports: import warnings
  import types
  import numpy
  from numpy.linalg import norm
  import numpy.testing
  from dipy.testing.memory import get_type_refcount
  from dipy.testing import assert_arrays_equal
  from dipy.testing.decorators import set_random_number_generator
  from dipy.testing import assert_true
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_raises, assert_allclose, assert_almost_equal, assert_equal
  from dipy.tracking.streamlinespeed import compress_streamlines, length, set_number_of_points
  from dipy.tracking.streamline import Streamlines
  from dipy.tracking.streamline import relist_streamlines, unlist_streamlines, center_streamlines, transform_streamlines, select_random_set_of_streamlines, select_by_rois, orient_by_rois, orient_by_streamline, values_from_volume, deform_streamlines, cluster_confidence
label_desc: Use image node_id 14 for calling a global function with example usage: compress_streamlines_python(streamline, tol_error, max_segment_length) and returns: compressed_streamline, streamline, np, unknown