code: def _extract_vals(data, streamlines, affine, threedvec=False):
      """
      Helper function for use with `values_from_volume`.
  
      Parameters
      ----------
      data : 3D or 4D array
          Scalar (for 3D) and vector (for 4D) values to be extracted. For 4D
          data, interpolation will be done on the 3 spatial dimensions in each
          volume.
  
      streamlines : ndarray or list
          If array, of shape (n_streamlines, n_nodes, 3)
          If list, len(n_streamlines) with (n_nodes, 3) array in
          each element of the list.
  
      affine : array_like (4, 4)
          The mapping from voxel coordinates to streamline points.
          The voxel_to_rasmm matrix, typically from a NIFTI file.
  
      threedvec : bool
          Whether the last dimension has length 3. This is a special case in
          which we can use :func:`dipy.core.interpolate.interpolate_vector_3d`
          for the interpolation of 4D volumes without looping over the elements
          of the last dimension.
  
      Returns
      ---------
      array or list (depending on the input) : values interpolate to each
          coordinate along the length of each streamline
      """
      data = data.astype(float)
      if isinstance(
          streamlines, (list, types.GeneratorType, Streamlines)
      ):
          streamlines = transform_streamlines(
              streamlines, np.linalg.inv(affine)
          )
          vals = []
          for sl in streamlines:
              if threedvec:
                  vals.append(
                      list(
                          interpolate_vector_3d(data, sl.astype(float))[
                              0
                          ]
                      )
                  )
              else:
                  vals.append(
                      list(
                          interpolate_scalar_3d(data, sl.astype(float))[
                              0
                          ]
                      )
                  )
  
      elif isinstance(streamlines, np.ndarray):
          sl_shape = streamlines.shape
          sl_cat = streamlines.reshape(
              sl_shape[0] * sl_shape[1], 3
          ).astype(float)
  
          inv_affine = np.linalg.inv(affine)
          sl_cat = (
              np.dot(sl_cat, inv_affine[:3, :3]) + inv_affine[:3, 3]
          )
  
          # So that we can index in one operation:
          if threedvec:
              vals = np.array(interpolate_vector_3d(data, sl_cat)[0])
          else:
              vals = np.array(interpolate_scalar_3d(data, sl_cat)[0])
          vals = np.reshape(vals, (sl_shape[0], sl_shape[1], -1))
          if vals.shape[-1] == 1:
              vals = np.reshape(vals, vals.shape[:-1])
      else:
          raise RuntimeError(
              "Extracting values from a volume ",
              "requires streamlines input as an array, ",
              "a list of arrays, or a streamline generator.",
          )
  
      return vals
  
imports: from copy import deepcopy
  from warnings import warn
  import types
  from scipy.spatial.distance import cdist
  import numpy
  from nibabel.affines import apply_affine
  from nibabel.streamlines import ArraySequence
  from dipy.tracking.streamlinespeed import length, set_number_of_points
  from dipy.tracking.distances import bundles_distances_mdf
  import dipy.tracking.utils
  from dipy.core.geometry import dist_to_corner
  from dipy.core.interpolation import interpolate_vector_3d, interpolate_scalar_3d
label_desc: Use image node_id 15 for calling a global function with example usage: _extract_vals(data, streamlines, affine, threedvec) and returns: vals