docstr: Streamline-based linear registration.
  
  For efficiency we apply the registration on cluster centroids and
  remove small clusters.
  
  Parameters
  ----------
  static_files : string
  moving_files : string
  x0 : string, optional
      rigid, similarity or affine transformation model.
  rm_small_clusters : int, optional
      Remove clusters that have less than `rm_small_clusters`.
  qbx_thr : variable int, optional
      Thresholds for QuickBundlesX.
  num_threads : int, optional
      Number of threads to be used for OpenMP parallelization. If None
      (default) the value of OMP_NUM_THREADS environment variable is
      used if it is set, otherwise all available threads are used. If
      < 0 the maximal number of threads minus |num_threads + 1| is used
      (enter -1 to use as many threads as possible). 0 raises an error.
      Only metrics using OpenMP will use this variable.
  greater_than : int, optional
      Keep streamlines that have length greater than
      this value.
  less_than : int, optional
      Keep streamlines have length less than this value.
  nb_pts : int, optional
      Number of points for discretizing each streamline.
  progressive : boolean, optional
  out_dir : string, optional
      Output directory. (default current directory)
  out_moved : string, optional
      Filename of moved tractogram.
  out_affine : string, optional
      Filename of affine for SLR transformation.
  out_stat_centroids : string, optional
      Filename of static centroids.
  out_moving_centroids : string, optional
      Filename of moving centroids.
  out_moved_centroids : string, optional
      Filename of moved centroids.
  
  Notes
  -----
  The order of operations is the following. First short or long
  streamlines are removed. Second the tractogram or a random selection
  of the tractogram is clustered with QuickBundlesX. Then SLR
  [Garyfallidis15]_ is applied.
  
  References
  ----------
  .. [Garyfallidis15] Garyfallidis et al. "Robust and efficient linear
  registration of white-matter fascicles in the space of
  streamlines", NeuroImage, 117, 124--140, 2015
  
  .. [Garyfallidis14] Garyfallidis et al., "Direct native-space fiber
  bundle alignment for group comparisons", ISMRM, 2014.
  
  .. [Garyfallidis17] Garyfallidis et al. Recognition of white matter
  bundles using local and global streamline-based registration
  and clustering, NeuroImage, 2017.
code: def run(
      self,
      static_files,
      moving_files,
      x0="affine",
      rm_small_clusters=50,
      qbx_thr=(40, 30, 20, 15),
      num_threads=None,
      greater_than=50,
      less_than=250,
      nb_pts=20,
      progressive=True,
      out_dir="",
      out_moved="moved.trk",
      out_affine="affine.txt",
      out_stat_centroids="static_centroids.trk",
      out_moving_centroids="moving_centroids.trk",
      out_moved_centroids="moved_centroids.trk",
  ):
      """Streamline-based linear registration.
  
      For efficiency we apply the registration on cluster centroids and
      remove small clusters.
  
      Parameters
      ----------
      static_files : string
      moving_files : string
      x0 : string, optional
          rigid, similarity or affine transformation model.
      rm_small_clusters : int, optional
          Remove clusters that have less than `rm_small_clusters`.
      qbx_thr : variable int, optional
          Thresholds for QuickBundlesX.
      num_threads : int, optional
          Number of threads to be used for OpenMP parallelization. If None
          (default) the value of OMP_NUM_THREADS environment variable is
          used if it is set, otherwise all available threads are used. If
          < 0 the maximal number of threads minus |num_threads + 1| is used
          (enter -1 to use as many threads as possible). 0 raises an error.
          Only metrics using OpenMP will use this variable.
      greater_than : int, optional
          Keep streamlines that have length greater than
          this value.
      less_than : int, optional
          Keep streamlines have length less than this value.
      nb_pts : int, optional
          Number of points for discretizing each streamline.
      progressive : boolean, optional
      out_dir : string, optional
          Output directory. (default current directory)
      out_moved : string, optional
          Filename of moved tractogram.
      out_affine : string, optional
          Filename of affine for SLR transformation.
      out_stat_centroids : string, optional
          Filename of static centroids.
      out_moving_centroids : string, optional
          Filename of moving centroids.
      out_moved_centroids : string, optional
          Filename of moved centroids.
  
      Notes
      -----
      The order of operations is the following. First short or long
      streamlines are removed. Second the tractogram or a random selection
      of the tractogram is clustered with QuickBundlesX. Then SLR
      [Garyfallidis15]_ is applied.
  
      References
      ----------
      .. [Garyfallidis15] Garyfallidis et al. "Robust and efficient linear
      registration of white-matter fascicles in the space of
      streamlines", NeuroImage, 117, 124--140, 2015
  
      .. [Garyfallidis14] Garyfallidis et al., "Direct native-space fiber
      bundle alignment for group comparisons", ISMRM, 2014.
  
      .. [Garyfallidis17] Garyfallidis et al. Recognition of white matter
      bundles using local and global streamline-based registration
      and clustering, NeuroImage, 2017.
      """
  
      io_it = self.get_io_iterator()
  
      logging.info("QuickBundlesX clustering is in use")
      logging.info("QBX thresholds {0}".format(qbx_thr))
  
      for (
          static_file,
          moving_file,
          out_moved_file,
          out_affine_file,
          static_centroids_file,
          moving_centroids_file,
          moved_centroids_file,
      ) in io_it:
          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,
          )
  
          (
              moved,
              affine,
              centroids_static,
              centroids_moving,
          ) = slr_with_qbx(
              static,
              moving,
              x0,
              rm_small_clusters=rm_small_clusters,
              greater_than=greater_than,
              less_than=less_than,
              qbx_thr=qbx_thr,
          )
  
          logging.info("Saving output file {0}".format(out_moved_file))
          new_tractogram = nib.streamlines.Tractogram(
              moved, affine_to_rasmm=np.eye(4)
          )
          nib.streamlines.save(
              new_tractogram, out_moved_file, header=moving_header
          )
  
          logging.info("Saving output file {0}".format(out_affine_file))
          np.savetxt(out_affine_file, affine)
  
          logging.info(
              "Saving output file {0}".format(static_centroids_file)
          )
          new_tractogram = nib.streamlines.Tractogram(
              centroids_static, affine_to_rasmm=np.eye(4)
          )
          nib.streamlines.save(
              new_tractogram,
              static_centroids_file,
              header=static_header,
          )
  
          logging.info(
              "Saving output file {0}".format(moving_centroids_file)
          )
          new_tractogram = nib.streamlines.Tractogram(
              centroids_moving, affine_to_rasmm=np.eye(4)
          )
          nib.streamlines.save(
              new_tractogram,
              moving_centroids_file,
              header=moving_header,
          )
  
          centroids_moved = transform_streamlines(
              centroids_moving, affine
          )
  
          logging.info(
              "Saving output file {0}".format(moved_centroids_file)
          )
  
          new_tractogram = nib.streamlines.Tractogram(
              centroids_moved, affine_to_rasmm=np.eye(4)
          )
          nib.streamlines.save(
              new_tractogram, moved_centroids_file, header=moving_header
          )
  
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 SlrWithQbxFlow obj's underlying member method code with example usage: obj.run(static_files, moving_files, x0, rm_small_clusters, qbx_thr, num_threads, greater_than, less_than, nb_pts, progressive, out_dir, out_moved, out_affine, out_stat_centroids, out_moving_centroids, out_moved_centroids) without return types