code: def values_from_volume(data, streamlines, affine):
      """Extract values of a scalar/vector along each streamline from a 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.
  
      Returns
      -------
      array or list (depending on the input) : values interpolate to each
          coordinate along the length of each streamline.
  
      Notes
      -----
      Values are extracted from the image based on the 3D coordinates of the
      nodes that comprise the points in the streamline, without any interpolation
      into segments between the nodes. Using this function with streamlines that
      have been resampled into a very small number of nodes will result in very
      few values.
      """
      data = np.asarray(data)
      if len(data.shape) == 4:
          if data.shape[-1] == 3:
              return _extract_vals(
                  data, streamlines, affine, threedvec=True
              )
          if isinstance(streamlines, types.GeneratorType):
              streamlines = Streamlines(streamlines)
          vals = []
          for ii in range(data.shape[-1]):
              vals.append(
                  _extract_vals(data[..., ii], streamlines, affine)
              )
  
          if isinstance(vals[-1], np.ndarray):
              return np.swapaxes(np.array(vals), 2, 1).T
          else:
              new_vals = []
              for sl_idx in range(len(streamlines)):
                  sl_vals = []
                  for ii in range(data.shape[-1]):
                      sl_vals.append(vals[ii][sl_idx])
                  new_vals.append(np.array(sl_vals).T)
              return new_vals
  
      elif len(data.shape) == 3:
          return _extract_vals(data, streamlines, affine)
      else:
          raise ValueError("Data needs to have 3 or 4 dimensions")
  
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 16 for calling a global function with example usage: values_from_volume(data, streamlines, affine) and returns: _extract_vals, np, new_vals, _extract_vals