class_docstr: The Motion Correction workflow allows the user to align between-volumes
  DWI dataset.
class_docstr_tok: ["The","Motion","Correction","workflow","allows","the","user","to","align","between-volumes","DWI","dataset","."]
docstr: Parameters
  ----------
  input_files : string
      Path to the input volumes. This path may contain wildcards to
      process multiple inputs at once.
  bvalues_files : string
      Path to the bvalues files. This path may contain wildcards to use
      multiple bvalues files at once.
  bvectors_files : string
      Path to the bvectors files. This path may contain wildcards to use
      multiple bvectors files at once.
  b0_threshold : float, optional
      Threshold used to find b0 volumes.
  bvecs_tol : float, optional
      Threshold used to check that norm(bvec) = 1 +/- bvecs_tol
      b-vectors are unit vectors
  out_dir : string, optional
      Directory to save the transformed image and the affine matrix
       (default current directory).
  out_moved : string, optional
      Name for the saved transformed image.
  out_affine : string, optional
      Name for the saved affine matrix.
code: def run(
      self,
      input_files,
      bvalues_files,
      bvectors_files,
      b0_threshold=50,
      bvecs_tol=0.01,
      out_dir="",
      out_moved="moved.nii.gz",
      out_affine="affine.txt",
  ):
      """
      Parameters
      ----------
      input_files : string
          Path to the input volumes. This path may contain wildcards to
          process multiple inputs at once.
      bvalues_files : string
          Path to the bvalues files. This path may contain wildcards to use
          multiple bvalues files at once.
      bvectors_files : string
          Path to the bvectors files. This path may contain wildcards to use
          multiple bvectors files at once.
      b0_threshold : float, optional
          Threshold used to find b0 volumes.
      bvecs_tol : float, optional
          Threshold used to check that norm(bvec) = 1 +/- bvecs_tol
          b-vectors are unit vectors
      out_dir : string, optional
          Directory to save the transformed image and the affine matrix
           (default current directory).
      out_moved : string, optional
          Name for the saved transformed image.
      out_affine : string, optional
          Name for the saved affine matrix.
      """
  
      io_it = self.get_io_iterator()
  
      for dwi, bval, bvec, omoved, oafffine in io_it:
          # Load the data from the input files and store into objects.
          logging.info("Loading {0}".format(dwi))
          data, affine = load_nifti(dwi)
  
          bvals, bvecs = read_bvals_bvecs(bval, bvec)
          # If all b-values are smaller or equal to the b0 threshold, it is
          # assumed that no thresholding is requested
          if any(mask_non_weighted_bvals(bvals, b0_threshold)):
              if b0_threshold < bvals.min():
                  warn(
                      "b0_threshold (value: {0}) is too low, increase your "
                      "b0_threshold. It should be higher than the lowest "
                      "b0 value ({1}).".format(
                          b0_threshold, bvals.min()
                      )
                  )
          gtab = gradient_table(
              bvals, bvecs, b0_threshold=b0_threshold, atol=bvecs_tol
          )
  
          reg_img, reg_affines = motion_correction(
              data=data, gtab=gtab, affine=affine
          )
  
          # Saving the corrected image file
          save_nifti(omoved, reg_img.get_fdata(), affine)
          # Write the affine matrix array to disk
          with open(oafffine, "w") as outfile:
              outfile.write(
                  "# Array shape: {0}\n".format(reg_affines.shape)
              )
              for affine_slice in reg_affines:
                  np.savetxt(outfile, affine_slice, fmt="%-7.2f")
                  outfile.write("# New slice\n")
  
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 1 for calling the MotionCorrectionFlow obj's underlying member method code with example usage: obj.run(input_files, bvalues_files, bvectors_files, b0_threshold, bvecs_tol, out_dir, out_moved, out_affine) without return types