class_docstr: Convenience class to encapsulate TRK file format.
  
  Notes
  -----
  TrackVis (so its file format: TRK) considers the streamline coordinate
  (0,0,0) to be in the corner of the voxel whereas NiBabel's streamlines
  internal representation (Voxel space) assumes (0,0,0) to be in the
  center of the voxel.
  
  Thus, streamlines are shifted by half a voxel on load and are shifted
  back on save.
docstr: Return generator that reads TRK data from `fileobj` given `header`
  
  Parameters
  ----------
  fileobj : string or file-like object
      If string, a filename; otherwise an open file-like object
      pointing to TRK file (and ready to read from the beginning
      of the TRK header). Note that calling this function
      does not change the file position.
  header : dict
      Metadata associated with this tractogram file.
  
  Yields
  ------
  data : tuple of ndarrays
      Length 3 tuple of streamline data of form (points, scalars,
      properties), where:
  
      * points: ndarray of shape (n_pts, 3)
      * scalars: ndarray of shape (n_pts, nb_scalars_per_point)
      * properties: ndarray of shape (nb_properties_per_point,)
docstr_tok: ["Return","generator","that","reads","TRK","data","from","`","fileobj","`","given","`","header","`","Parameters","--","--","--","--","--","fileobj",":","string","or","file-like","object","If","string",",","a","filename",";","otherwise","an","open","file-like","object","pointing","to","TRK","file","(","and","ready","to","read","from","the","beginning","of","the","TRK","header",")",".","Note","that","calling","this","function","does","not","change","the","file","position",".","header",":","dict","Metadata","associated","with","this","tractogram","file",".","Yields","--","--","--","data",":","tuple","of","ndarrays","Length","3","tuple","of","streamline","data","of","form","(","points",",","scalars",",","properties",")",",","where",":","*","points",":","ndarray","of","shape","(","n_pts",",","3",")","*","scalars",":","ndarray","of","shape","(","n_pts",",","nb_scalars_per_point",")","*","properties",":","ndarray","of","shape","(","nb_properties_per_point",",",")"]
code: def _read(fileobj, header):
      """Return generator that reads TRK data from `fileobj` given `header`
  
      Parameters
      ----------
      fileobj : string or file-like object
          If string, a filename; otherwise an open file-like object
          pointing to TRK file (and ready to read from the beginning
          of the TRK header). Note that calling this function
          does not change the file position.
      header : dict
          Metadata associated with this tractogram file.
  
      Yields
      ------
      data : tuple of ndarrays
          Length 3 tuple of streamline data of form (points, scalars,
          properties), where:
  
          * points: ndarray of shape (n_pts, 3)
          * scalars: ndarray of shape (n_pts, nb_scalars_per_point)
          * properties: ndarray of shape (nb_properties_per_point,)
      """
      i4_dtype = np.dtype(header[Field.ENDIANNESS] + "i4")
      f4_dtype = np.dtype(header[Field.ENDIANNESS] + "f4")
  
      with Opener(fileobj) as f:
          start_position = f.tell()
  
          nb_pts_and_scalars = int(
              3 + header[Field.NB_SCALARS_PER_POINT]
          )
          pts_and_scalars_size = int(
              nb_pts_and_scalars * f4_dtype.itemsize
          )
          nb_properties = header[Field.NB_PROPERTIES_PER_STREAMLINE]
          properties_size = int(nb_properties * f4_dtype.itemsize)
  
          # Set the file position at the beginning of the data.
          f.seek(header["_offset_data"], os.SEEK_SET)
  
          # If 'count' field is 0, i.e. not provided, we have to loop
          # until the EOF.
          nb_streamlines = header[Field.NB_STREAMLINES]
          if nb_streamlines == 0:
              nb_streamlines = np.inf
  
          count = 0
          nb_pts_dtype = i4_dtype.str[:-1]
          while count < nb_streamlines:
              nb_pts_str = f.read(i4_dtype.itemsize)
  
              # Check if we reached EOF
              if len(nb_pts_str) == 0:
                  break
  
              # Read number of points of the next streamline.
              nb_pts = struct.unpack(nb_pts_dtype, nb_pts_str)[0]
  
              # Read streamline's data
              points_and_scalars = np.ndarray(
                  shape=(nb_pts, nb_pts_and_scalars),
                  dtype=f4_dtype,
                  buffer=f.read(nb_pts * pts_and_scalars_size),
              )
  
              points = points_and_scalars[:, :3]
              scalars = points_and_scalars[:, 3:]
  
              # Read properties
              properties = np.ndarray(
                  shape=(nb_properties,),
                  dtype=f4_dtype,
                  buffer=f.read(properties_size),
              )
  
              yield points, scalars, properties
              count += 1
  
          # In case the 'count' field was not provided.
          header[Field.NB_STREAMLINES] = count
  
          # Set the file position where it was (in case it was already open).
          f.seek(start_position, os.SEEK_CUR)
  
imports: import os
  import string
  import struct
  import warnings
  import numpy
  import nibabel
  from nibabel.openers import Opener
  from nibabel.orientations import aff2axcodes, axcodes2ornt
  from nibabel.volumeutils import endian_codes, native_code, swapped_code
  from .array_sequence import create_arraysequences_from_generator
  from .header import Field
  from .tractogram import LazyTractogram, Tractogram, TractogramItem
  from .tractogram_file import DataError, HeaderError, HeaderWarning, TractogramFile
  from .utils import peek_next
label_desc: Use image node_id 8 for calling the TrkFile obj's underlying member method code with example usage: obj._read(fileobj, header) without return types