code: def afq_profile(
      data,
      bundle,
      affine,
      n_points=100,
      profile_stat=np.average,
      orient_by=None,
      weights=None,
      **weights_kwarg,
  ):
      """
      Calculates a summarized profile of data for a bundle or tract
      along its length.
  
      Follows the approach outlined in [Yeatman2012]_.
  
      Parameters
      ----------
      data : 3D volume
          The statistic to sample with the streamlines.
  
      bundle : StreamLines class instance
          The collection of streamlines (possibly already resampled into an array
           for each to have the same length) with which we are resampling. See
           Note below about orienting the streamlines.
      affine : array_like (4, 4)
          The mapping from voxel coordinates to streamline points.
          The voxel_to_rasmm matrix, typically from a NIFTI file.
      n_points: int, optional
          The number of points to sample along the bundle. Default: 100.
      orient_by: streamline, optional.
          A streamline to use as a standard to orient all of the streamlines in
          the bundle according to.
      weights : 1D array or 2D array or callable (optional)
          Weight each streamline (1D) or each node (2D) when calculating the
          tract-profiles. Must sum to 1 across streamlines (in each node if
          relevant). If callable, this is a function that calculates weights.
      profile_stat : callable
          The statistic used to average the profile across streamlines.
          If weights is not None, this must take weights as a keyword argument.
          The default, np.average, is the same as np.mean but takes weights
          as a keyword argument.
      weights_kwarg : key-word arguments
          Additional key-word arguments to pass to the weight-calculating
          function. Only to be used if weights is a callable.
  
      Returns
      -------
      ndarray : a 1D array with the profile of `data` along the length of
          `bundle`
  
      Notes
      -----
      Before providing a bundle as input to this function, you will need to make
      sure that the streamlines in the bundle are all oriented in the same
      orientation relative to the bundle (use :func:`orient_by_streamline`).
  
      References
      ----------
      .. [Yeatman2012] Yeatman, Jason D., Robert F. Dougherty,
         Nathaniel J. Myall, Brian A. Wandell, and Heidi M. Feldman. 2012.
         "Tract Profiles of White Matter Properties: Automating Fiber-Tract
         Quantification" PloS One 7 (11): e49790.
  
      """
      if orient_by is not None:
          bundle = orient_by_streamline(bundle, orient_by)
      if affine is None:
          affine = np.eye(4)
      if len(bundle) == 0:
          raise ValueError("The bundle contains no streamlines")
  
      # Resample each streamline to the same number of points:
      fgarray = set_number_of_points(bundle, n_points)
  
      # Extract the values
      values = np.array(values_from_volume(data, fgarray, affine))
  
      if weights is not None:
          if callable(weights):
              weights = weights(bundle, **weights_kwarg)
          else:
              # We check that weights *always sum to 1 across streamlines*:
              if not np.allclose(np.sum(weights, 0), np.ones(n_points)):
                  raise ValueError(
                      "The sum of weights across streamlines",
                      " must be equal to 1",
                  )
  
          return profile_stat(values, weights=weights, axis=0)
      else:
          return profile_stat(values, axis=0)
  
file_path: dipy/dipy/stats/analysis.py
imports: import os
  import numpy
  from scipy.spatial import cKDTree
  from scipy.ndimage import map_coordinates
  from scipy.spatial.distance import mahalanobis
  from dipy.io.utils import save_buan_profiles_hdf5
  from dipy.segment.clustering import QuickBundles
  from dipy.segment.metricspeed import AveragePointwiseEuclideanMetric
  from dipy.tracking.streamline import set_number_of_points, values_from_volume, orient_by_streamline, Streamlines
label_desc: Use image node_id 5 for calling a global function with example usage: afq_profile(data, bundle, affine, n_points, profile_stat, orient_by, weights) and returns: profile_stat, profile_stat