code: def test_GradientTable_btensor_calculation():
      # Generate a gradient table without specifying b-tensors
      gradients = np.array(
          [
              [0, 0, 0],
              [1, 0, 0],
              [0, 1, 0],
              [0, 0, 1],
              [3, 4, 0],
              [5, 0, 12],
          ],
          "float",
      )
  
      # Check that when btens attribute not specified it takes the value of None
      gt = GradientTable(gradients)
      npt.assert_equal(gt.btens, None)
  
      # Check that btens are correctly created if specified
      gt = GradientTable(gradients, btens="LTE")
  
      # Check that the number of b tensors is correct
      npt.assert_equal(gt.btens.shape[0], gt.bvals.shape[0])
      for i, (bval, bten) in enumerate(zip(gt.bvals, gt.btens)):
          # Check that the b tensor magnitude is correct
          npt.assert_almost_equal(np.trace(bten), bval)
          # Check that the b tensor orientation is correct
          if bval != 0:
              evals, evecs = np.linalg.eig(bten)
              dot_prod = np.dot(
                  np.real(evecs[:, np.argmax(evals)]), gt.bvecs[i]
              )
              npt.assert_almost_equal(np.abs(dot_prod), 1)
  
      # Check btens input option 1
      for btens in ["LTE", "PTE", "STE", "CTE"]:
          gt = GradientTable(gradients, btens=btens)
          # Check that the number of b tensors is correct
          npt.assert_equal(gt.bvals.shape[0], gt.btens.shape[0])
          for i, (bval, bvec, bten) in enumerate(
              zip(gt.bvals, gt.bvecs, gt.btens)
          ):
              # Check that the b tensor magnitude is correct
              npt.assert_almost_equal(np.trace(bten), bval)
              # Check that the b tensor orientation is correct
              if btens == ("LTE" or "CTE"):
                  if bval != 0:
                      evals, evecs = np.linalg.eig(bten)
                      dot_prod = np.dot(
                          np.real(evecs[:, np.argmax(evals)]), bvec
                      )
                      npt.assert_almost_equal(np.abs(dot_prod), 1)
              elif btens == "PTE":
                  if bval != 0:
                      evals, evecs = np.linalg.eig(bten)
                      dot_prod = np.dot(
                          np.real(evecs[:, np.argmin(evals)]), bvec
                      )
                      npt.assert_almost_equal(np.abs(dot_prod), 1)
  
      # Check btens input option 2
      btens = np.array(["LTE", "PTE", "STE", "CTE", "LTE", "PTE"])
      gt = GradientTable(gradients, btens=btens)
      # Check that the number of b tensors is correct
      npt.assert_equal(gt.bvals.shape[0], gt.btens.shape[0])
      for i, (bval, bvec, bten) in enumerate(
          zip(gt.bvals, gt.bvecs, gt.btens)
      ):
          # Check that the b tensor magnitude is correct
          npt.assert_almost_equal(np.trace(bten), bval)
          # Check that the b tensor orientation is correct
          if btens[i] == ("LTE" or "CTE"):
              if bval != 0:
                  evals, evecs = np.linalg.eig(bten)
                  dot_prod = np.dot(
                      np.real(evecs[:, np.argmax(evals)]), bvec
                  )
                  npt.assert_almost_equal(np.abs(dot_prod), 1)
          elif btens[i] == "PTE":
              if bval != 0:
                  evals, evecs = np.linalg.eig(bten)
                  dot_prod = np.dot(
                      np.real(evecs[:, np.argmin(evals)]), bvec
                  )
                  npt.assert_almost_equal(np.abs(dot_prod), 1)
  
      # Check btens input option 3
      btens = np.array([np.eye(3, 3) for i in range(6)])
      gt = GradientTable(gradients, btens=btens)
      npt.assert_equal(btens, gt.btens)
      npt.assert_equal(gt.bvals.shape[0], gt.btens.shape[0])
  
      # Check invalid input
      npt.assert_raises(
          ValueError, GradientTable, gradients=gradients, btens="PPP"
      )
      npt.assert_raises(
          ValueError,
          GradientTable,
          gradients=gradients,
          btens=np.array([np.eye(3, 3) for i in range(10)]),
      )
      npt.assert_raises(
          ValueError,
          GradientTable,
          gradients=gradients,
          btens=np.zeros((10, 10)),
      )
  
imports: import warnings
  import numpy
  import numpy.testing
  import pytest
  from dipy.data import get_fnames
  from dipy.core.gradients import b0_threshold_empty_gradient_message, b0_threshold_update_slicing_message, gradient_table, GradientTable, gradient_table_from_bvals_bvecs, gradient_table_from_qvals_bvecs, gradient_table_from_gradient_strength_bvecs, WATER_GYROMAGNETIC_RATIO, mask_non_weighted_bvals, orientation_to_string, reorient_bvecs, generate_bvecs, check_multi_b, round_bvals, get_bval_indices, unique_bvals_magnitude, unique_bvals_tolerance, unique_bvals, params_to_btens, btens_to_params, orientation_from_string, reorient_vectors
  from dipy.core.geometry import vec2vec_rotmat, vector_norm
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.utils.deprecator import ExpiredDeprecationError
  from dipy.testing import clear_and_catch_warnings
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 5 for calling a global function with example usage: test_GradientTable_btensor_calculation() without return types