class_docstr: Use hardi_mat to calculate a reconstruction matrix from a gradient table
class_docstr_tok: ["Use","hardi_mat","to","calculate","a","reconstruction","matrix","from","a","gradient","table"]
code: def _create_gradient_matrix(self, bvecs_file, bvals_file):
      _gradient_matrix_file = "gradient_matrix.txt"
      bvals = [
          val
          for val in re.split(
              r"\s+", open(bvals_file).readline().strip()
          )
      ]
      bvecs_f = open(bvecs_file)
      bvecs_x = [
          val for val in re.split(r"\s+", bvecs_f.readline().strip())
      ]
      bvecs_y = [
          val for val in re.split(r"\s+", bvecs_f.readline().strip())
      ]
      bvecs_z = [
          val for val in re.split(r"\s+", bvecs_f.readline().strip())
      ]
      bvecs_f.close()
      gradient_matrix_f = open(_gradient_matrix_file, "w")
      for i in range(len(bvals)):
          if int(bvals[i]) == 0:
              continue
          gradient_matrix_f.write(
              f"{bvecs_x[i]} {bvecs_y[i]} {bvecs_z[i]}\n"
          )
      gradient_matrix_f.close()
      return _gradient_matrix_file
  
imports: import os
  import re
  from ...utils.filemanip import fname_presuffix, split_filename, copyfile
  from ..base import TraitedSpec, File, traits, CommandLine, CommandLineInputSpec, isdefined
label_desc: Use image node_id 1 for calling the HARDIMat obj's underlying member method code with example usage: obj._create_gradient_matrix(bvecs_file, bvals_file) and returns: _gradient_matrix_file