docstr: BundleWarp: streamline-based nonlinear registration.
  
  BundleWarp is nonrigid registration method for deformable registration
  of white matter tracts.
  
  Parameters
  ----------
  static_file : string
      Path to the static (reference) .trk file.
  moving_file : string
      Path to the moving (target to be registered) .trk file.
  dist : string, optional
      Path to the precalculated distance matrix file.
  alpha : float, optional
      Represents the trade-off between regularizing the deformation and
      having points match very closely. Lower value of alpha means high
      deformations. It is represented with λ in BundleWarp paper. NOTE:
      setting alpha<=0.01 will result in highly deformable registration
      that could extremely modify the original anatomy of the moving
      bundle. (default 0.3)
  beta : int, optional
      Represents the strength of the interaction between points
      Gaussian kernel size. (default 20)
  max_iter : int, optional
      Maximum number of iterations for deformation process in ml-CPD
      method. (default 15)
  affine : boolean, optional
      If False, use rigid registration as starting point. (default True)
  out_dir : string, optional
      Output directory. (default current directory)
  out_linear_moved : string, optional
      Filename of linearly moved bundle.
  out_nonlinear_moved : string, optional
      Filename of nonlinearly moved (warped) bundle.
  out_warp_transform : string, optional
      Filename of warp transformations generated by BundleWarp.
  out_warp_kernel : string, optional
      Filename of regularization gaussian kernel generated by BundleWarp.
  out_dist : string, optional
      Filename of MDF distance matrix.
  out_matched_pairs : string, optional
      Filename of matched pairs; treamline correspondences between two
      bundles.
  
  References
  ----------
   .. [Chandio2023] Chandio et al. "BundleWarp, streamline-based nonlinear
      registration of white matter tracts." bioRxiv (2023): 2023-01.
code: def run(
      self,
      static_file,
      moving_file,
      dist=None,
      alpha=0.3,
      beta=20,
      max_iter=15,
      affine=True,
      out_dir="",
      out_linear_moved="linearly_moved.trk",
      out_nonlinear_moved="nonlinearly_moved.trk",
      out_warp_transform="warp_transform.npy",
      out_warp_kernel="warp_kernel.npy",
      out_dist="distance_matrix.npy",
      out_matched_pairs="matched_pairs.npy",
  ):
      """BundleWarp: streamline-based nonlinear registration.
  
      BundleWarp is nonrigid registration method for deformable registration
      of white matter tracts.
  
      Parameters
      ----------
      static_file : string
          Path to the static (reference) .trk file.
      moving_file : string
          Path to the moving (target to be registered) .trk file.
      dist : string, optional
          Path to the precalculated distance matrix file.
      alpha : float, optional
          Represents the trade-off between regularizing the deformation and
          having points match very closely. Lower value of alpha means high
          deformations. It is represented with λ in BundleWarp paper. NOTE:
          setting alpha<=0.01 will result in highly deformable registration
          that could extremely modify the original anatomy of the moving
          bundle. (default 0.3)
      beta : int, optional
          Represents the strength of the interaction between points
          Gaussian kernel size. (default 20)
      max_iter : int, optional
          Maximum number of iterations for deformation process in ml-CPD
          method. (default 15)
      affine : boolean, optional
          If False, use rigid registration as starting point. (default True)
      out_dir : string, optional
          Output directory. (default current directory)
      out_linear_moved : string, optional
          Filename of linearly moved bundle.
      out_nonlinear_moved : string, optional
          Filename of nonlinearly moved (warped) bundle.
      out_warp_transform : string, optional
          Filename of warp transformations generated by BundleWarp.
      out_warp_kernel : string, optional
          Filename of regularization gaussian kernel generated by BundleWarp.
      out_dist : string, optional
          Filename of MDF distance matrix.
      out_matched_pairs : string, optional
          Filename of matched pairs; treamline correspondences between two
          bundles.
  
      References
      ----------
       .. [Chandio2023] Chandio et al. "BundleWarp, streamline-based nonlinear
          registration of white matter tracts." bioRxiv (2023): 2023-01.
      """
  
      logging.info("Loading static file {0}".format(static_file))
      logging.info("Loading moving file {0}".format(moving_file))
  
      static_obj = nib.streamlines.load(static_file)
      moving_obj = nib.streamlines.load(moving_file)
  
      static, static_header = static_obj.streamlines, static_obj.header
      moving, moving_header = moving_obj.streamlines, moving_obj.header
  
      static = set_number_of_points(static, 20)
      moving = set_number_of_points(moving, 20)
  
      deformed_bundle, affine_bundle, dists, mp, warp = bundlewarp(
          static,
          moving,
          dist=dist,
          alpha=alpha,
          beta=beta,
          max_iter=max_iter,
          affine=affine,
      )
  
      logging.info("Saving output file {0}".format(out_linear_moved))
      new_tractogram = nib.streamlines.Tractogram(
          affine_bundle, affine_to_rasmm=np.eye(4)
      )
      nib.streamlines.save(
          new_tractogram,
          pjoin(out_dir, out_linear_moved),
          header=moving_header,
      )
  
      logging.info("Saving output file {0}".format(out_nonlinear_moved))
      new_tractogram = nib.streamlines.Tractogram(
          deformed_bundle, affine_to_rasmm=np.eye(4)
      )
      nib.streamlines.save(
          new_tractogram,
          pjoin(out_dir, out_nonlinear_moved),
          header=moving_header,
      )
  
      df = pd.DataFrame(warp, columns=["transforms", "gaussian_kernel"])
  
      logging.info("Saving output file {0}".format(out_warp_transform))
      np.save(
          pjoin(out_dir, out_warp_transform), np.array(df["transforms"])
      )
  
      logging.info("Saving output file {0}".format(out_warp_kernel))
      np.save(
          pjoin(out_dir, out_warp_kernel),
          np.array(df["gaussian_kernel"]),
      )
  
      logging.info("Saving output file {0}".format(out_dist))
      np.save(pjoin(out_dir, out_dist), dist)
  
      logging.info("Saving output file {0}".format(out_matched_pairs))
      np.save(pjoin(out_dir, out_matched_pairs), mp)
  
imports: import logging
  from warnings import warn
  import numpy
  import nibabel
  from os.path import join
  from dipy.utils.optpkg import optional_package
  from dipy.align.imaffine import AffineMap
  from dipy.align.imwarp import SymmetricDiffeomorphicRegistration, DiffeomorphicMap
  from dipy.align.metrics import CCMetric, SSDMetric, EMMetric
  from dipy.align.reslice import reslice
  from dipy.align import affine_registration, motion_correction
  from dipy.align.streamlinear import slr_with_qbx
  from dipy.tracking.streamline import set_number_of_points
  from dipy.align.streamwarp import bundlewarp
  from dipy.core.gradients import mask_non_weighted_bvals, gradient_table
  from dipy.io.image import save_nifti, load_nifti, save_qa_metric
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.tracking.streamline import transform_streamlines
  from dipy.workflows.workflow import Workflow
label_desc: Use image node_id 2 for calling the BundleWarpFlow obj's underlying member method code with example usage: obj.run(static_file, moving_file, dist, alpha, beta, max_iter, affine, out_dir, out_linear_moved, out_nonlinear_moved, out_warp_transform, out_warp_kernel, out_dist, out_matched_pairs) without return types