docs: def _get_bvals_bvecs(grouped_dicoms):
      """
      Write the bvals from the sorted dicom files to a bval file
      """
      # loop over all timepoints and create a list with all bvals and bvecs
      bvals = numpy.zeros([len(grouped_dicoms)], dtype=numpy.int32)
      bvecs = numpy.zeros([len(grouped_dicoms), 3])
  
      for group_index in range(0, len(grouped_dicoms)):
          dicom_ = grouped_dicoms[group_index][0]
          # 0019:10bb: Diffusion X
          # 0019:10bc: Diffusion Y
          # 0019:10bd: Diffusion Z
          # 0043:1039: B-values (4 values, 1st value is actual B value)
  
          # bval can be stored both in string as number format in dicom so implement both
          # some workarounds needed for implicit transfer syntax to work
          if isinstance(dicom_[Tag(0x0043, 0x1039)].value, string_types):  # this works for python2.7
              original_bval = float(dicom_[Tag(0x0043, 0x1039)].value.split('\\')[0])
          elif isinstance(dicom_[Tag(0x0043, 0x1039)].value, bytes):  # this works for python3.o
              original_bval = float(dicom_[Tag(0x0043, 0x1039)].value.decode("utf-8").split('\\')[0])
          else:
              original_bval = dicom_[Tag(0x0043, 0x1039)][0]
          original_bvec = numpy.array([0, 0, 0], dtype=numpy.float)
          original_bvec[0] = -float(dicom_[Tag(0x0019, 0x10bb)].value)  # invert based upon mricron output
          original_bvec[1] = float(dicom_[Tag(0x0019, 0x10bc)].value)
          original_bvec[2] = float(dicom_[Tag(0x0019, 0x10bd)].value)
  
          # Add calculated B Value
          if original_bval != 0:  # only normalize if there is a value
              corrected_bval = original_bval * pow(numpy.linalg.norm(original_bvec), 2)
              if numpy.linalg.norm(original_bvec) != 0:
                  normalized_bvec = original_bvec / numpy.linalg.norm(original_bvec)
              else:
                  normalized_bvec = original_bvec
          else:
              corrected_bval = original_bval
              normalized_bvec = original_bvec
  
          bvals[group_index] = int(round(corrected_bval))  # we want the original numbers back as in the protocol
          bvecs[group_index, :] = normalized_bvec
  
      return bvals, bvecs