code: def bundle_adjacency(dtracks0, dtracks1, threshold):
      """Find bundle adjacency between two given tracks/bundles
  
      Parameters
      ----------
      dtracks0 : Streamlines
          White matter tract from one subject
      dtracks1 : Streamlines
          White matter tract from another subject
      threshold : float
          Threshold controls
          how much strictness user wants while calculating bundle adjacency
          between two bundles. Smaller threshold means bundles should be strictly
          adjacent to get higher BA score.
  
      Returns
      -------
      res : Float
          Bundle adjacency score between two tracts
  
      References
      ----------
      .. [Garyfallidis12] Garyfallidis E. et al., QuickBundles a method for
                          tractography simplification, Frontiers in Neuroscience,
                          vol 6, no 175, 2012.
      """
      d01 = bundles_distances_mdf(dtracks0, dtracks1)
  
      pair12 = []
  
      for i in range(len(dtracks0)):
          if np.min(d01[i, :]) < threshold:
              j = np.argmin(d01[i, :])
              pair12.append((i, j))
  
      pair12 = np.array(pair12)
      pair21 = []
  
      # solo2 = []
      for i in range(len(dtracks1)):
          if np.min(d01[:, i]) < threshold:
              j = np.argmin(d01[:, i])
              pair21.append((i, j))
  
      pair21 = np.array(pair21)
      A = len(pair12) / float(len(dtracks0))
      B = len(pair21) / float(len(dtracks1))
      res = 0.5 * (A + B)
      return res
  
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 2 for calling a global function with example usage: bundle_adjacency(dtracks0, dtracks1, threshold) and returns: res