docstr: Recognition of bundles
  
  Extract bundles from a participants' tractograms using model bundles
  segmented from a different subject or an atlas of bundles.
  See [Garyfallidis17]_ for the details.
  
  Parameters
  ----------
  streamlines : Streamlines
      The tractogram in which you want to recognize bundles.
  greater_than : int, optional
      Keep streamlines that have length greater than
      this value (default 50)
  less_than : int, optional
      Keep streamlines have length less than this value (default 1000000)
  cluster_map : QB map, optional.
      Provide existing clustering to start RB faster (default None).
  clust_thr : float, optional.
      Distance threshold in mm for clustering `streamlines`.
      Default: 15.
  nb_pts : int, optional.
      Number of points per streamline (default 20)
  rng : np.random.Generator
      If None define generator in initialization function.
      Default: None
  verbose: bool, optional.
      If True, log information.
  
  Notes
  -----
  Make sure that before creating this class that the streamlines and
  the model bundles are roughly in the same space.
  Also default thresholds are assumed in RAS 1mm^3 space. You may
  want to adjust those if your streamlines are not in world coordinates.
  
  References
  ----------
  .. [Garyfallidis17] Garyfallidis et al. Recognition of white matter
      bundles using local and global streamline-based registration and
      clustering, Neuroimage, 2017.
docstr_tok: ["Recognition","of","bundles","Extract","bundles","from","a","participants","'","tractograms","using","model","bundles","segmented","from","a","different","subject","or","an","atlas","of","bundles",".","See","[","Garyfallidis17","]","_","for","the","details",".","Parameters","--","--","--","--","--","streamlines",":","Streamlines","The","tractogram","in","which","you","want","to","recognize","bundles",".","greater_than",":","int",",","optional","Keep","streamlines","that","have","length","greater","than","this","value","(","default","50",")","less_than",":","int",",","optional","Keep","streamlines","have","length","less","than","this","value","(","default","1000000",")","cluster_map",":","QB","map",",","optional",".","Provide","existing","clustering","to","start","RB","faster","(","default","None",")",".","clust_thr",":","float",",","optional",".","Distance","threshold","in","mm","for","clustering","`","streamlines","`",".","Default",":","15.","nb_pts",":","int",",","optional",".","Number","of","points","per","streamline","(","default","20",")","rng",":","np.random.Generator","If","None","define","generator","in","initialization","function",".","Default",":","None","verbose",":","bool",",","optional",".","If","True",",","log","information",".","Notes","--","--","-","Make","sure","that","before","creating","this","class","that","the","streamlines","and","the","model","bundles","are","roughly","in","the","same","space",".","Also","default","thresholds","are","assumed","in","RAS","1mm^3","space",".","You","may","want","to","adjust","those","if","your","streamlines","are","not","in","world","coordinates",".","References","--","--","--","--","--","..","[","Garyfallidis17","]","Garyfallidis","et","al",".","Recognition","of","white","matter","bundles","using","local","and","global","streamline-based","registration","and","clustering",",","Neuroimage",",","2017","."]
code: def __init__(
      self,
      streamlines,
      greater_than=50,
      less_than=1000000,
      cluster_map=None,
      clust_thr=15,
      nb_pts=20,
      rng=None,
      verbose=False,
  ):
      """Recognition of bundles
  
      Extract bundles from a participants' tractograms using model bundles
      segmented from a different subject or an atlas of bundles.
      See [Garyfallidis17]_ for the details.
  
      Parameters
      ----------
      streamlines : Streamlines
          The tractogram in which you want to recognize bundles.
      greater_than : int, optional
          Keep streamlines that have length greater than
          this value (default 50)
      less_than : int, optional
          Keep streamlines have length less than this value (default 1000000)
      cluster_map : QB map, optional.
          Provide existing clustering to start RB faster (default None).
      clust_thr : float, optional.
          Distance threshold in mm for clustering `streamlines`.
          Default: 15.
      nb_pts : int, optional.
          Number of points per streamline (default 20)
      rng : np.random.Generator
          If None define generator in initialization function.
          Default: None
      verbose: bool, optional.
          If True, log information.
  
      Notes
      -----
      Make sure that before creating this class that the streamlines and
      the model bundles are roughly in the same space.
      Also default thresholds are assumed in RAS 1mm^3 space. You may
      want to adjust those if your streamlines are not in world coordinates.
  
      References
      ----------
      .. [Garyfallidis17] Garyfallidis et al. Recognition of white matter
          bundles using local and global streamline-based registration and
          clustering, Neuroimage, 2017.
      """
      map_ind = np.zeros(len(streamlines))
      for i in range(len(streamlines)):
          map_ind[i] = check_range(
              streamlines[i], greater_than, less_than
          )
      map_ind = map_ind.astype(bool)
  
      self.orig_indices = np.array(list(range(0, len(streamlines))))
      self.filtered_indices = np.array(self.orig_indices[map_ind])
      self.streamlines = Streamlines(streamlines[map_ind])
      self.nb_streamlines = len(self.streamlines)
      self.verbose = verbose
      if self.verbose:
          logger.info(
              f"target brain streamlines length = {len(streamlines)}"
          )
          logger.info(
              f"After refining target brain streamlines"
              f" length = {len(self.streamlines)}"
          )
  
      self.start_thr = [40, 25, 20]
      if rng is None:
          self.rng = np.random.default_rng()
      else:
          self.rng = rng
  
      if cluster_map is None:
          self._cluster_streamlines(clust_thr=clust_thr, nb_pts=nb_pts)
      else:
          if self.verbose:
              t = time()
  
          self.cluster_map = cluster_map
          self.cluster_map.refdata = self.streamlines
          self.centroids = self.cluster_map.centroids
          self.nb_centroids = len(self.centroids)
          self.indices = [
              cluster.indices for cluster in self.cluster_map
          ]
  
          if self.verbose:
              logger.info(
                  f" Streamlines have {self.nb_centroids} centroids"
              )
              logger.info(
                  f" Total loading duration {time() - t:0.3f} s\n"
              )
  
imports: from time import time
  from itertools import chain
  import logging
  import numpy
  from dipy.tracking.streamline import set_number_of_points, nbytes, select_random_set_of_streamlines
  from dipy.segment.clustering import qbx_and_merge
  from dipy.tracking.distances import bundles_distances_mdf, bundles_distances_mam
  from dipy.align.streamlinear import StreamlineLinearRegistration, BundleMinDistanceMetric, BundleSumDistanceMatrixMetric, BundleMinDistanceAsymmetricMetric
  from dipy.tracking.streamline import Streamlines, length
  from dipy.utils.deprecator import deprecated_params
  from nibabel.affines import apply_affine
label_desc: Use image node_id 1 to create a new RecoBundles object  with example: obj = RecoBundles(streamlines, greater_than, less_than, cluster_map, clust_thr, nb_pts, rng, verbose)