class_docstr: Convenience class to encapsulate TCK file format.
  
  Notes
  -----
  MRtrix (so its file format: TCK) considers streamlines coordinates
  to be in world space (RAS+ and mm space). MRtrix refers to that space
  as the "real" or "scanner" space [#]_.
  
  Moreover, when streamlines are mapped back to voxel space [#]_, a
  streamline point located at an integer coordinate (i,j,k) is considered
  to be at the center of the corresponding voxel. This is in contrast with
  TRK's internal convention where it would have referred to a corner.
  
  NiBabel's streamlines internal representation follows the same
  convention as MRtrix.
  
  .. [#] http://www.nitrc.org/pipermail/mrtrix-discussion/2014-January/000859.html
  .. [#] http://nipy.org/nibabel/coordinate_systems.html#voxel-coordinates-are-in-voxel-space
class_docstr_tok: ["Convenience","class","to","encapsulate","TCK","file","format",".","Notes","--","--","-","MRtrix","(","so","its","file","format",":","TCK",")","considers","streamlines","coordinates","to","be","in","world","space","(","RAS+","and","mm","space",")",".","MRtrix","refers","to","that","space","as","the","``","real","''","or","``","scanner","''","space","[","#","]","_",".","Moreover",",","when","streamlines","are","mapped","back","to","voxel","space","[","#","]","_",",","a","streamline","point","located","at","an","integer","coordinate","(","i",",","j",",","k",")","is","considered","to","be","at","the","center","of","the","corresponding","voxel",".","This","is","in","contrast","with","TRK","'s","internal","convention","where","it","would","have","referred","to","a","corner",".","NiBabel","'s","streamlines","internal","representation","follows","the","same","convention","as","MRtrix",".","..","[","#","]","http",":","\/\/www.nitrc.org\/pipermail\/mrtrix-discussion\/2014-January\/000859.html","..","[","#","]","http",":","\/\/nipy.org\/nibabel\/coordinate_systems.html","#","voxel-coordinates-are-in-voxel-space"]
docstr: Return generator that reads TCK data from `fileobj` given `header`
  
  Parameters
  ----------
  fileobj : string or file-like object
      If string, a filename; otherwise an open file-like object in
      binary mode pointing to TCK file (and ready to read from the
      beginning of the TCK header). Note that calling this function
      does not change the file position.
  header : dict
      Metadata associated with this tractogram file.
  buffer_size : float, optional
      Size (in Mb) for buffering.
  
  Yields
  ------
  points : ndarray of shape (n_pts, 3)
      Streamline points
docstr_tok: ["Return","generator","that","reads","TCK","data","from","`","fileobj","`","given","`","header","`","Parameters","--","--","--","--","--","fileobj",":","string","or","file-like","object","If","string",",","a","filename",";","otherwise","an","open","file-like","object","in","binary","mode","pointing","to","TCK","file","(","and","ready","to","read","from","the","beginning","of","the","TCK","header",")",".","Note","that","calling","this","function","does","not","change","the","file","position",".","header",":","dict","Metadata","associated","with","this","tractogram","file",".","buffer_size",":","float",",","optional","Size","(","in","Mb",")","for","buffering",".","Yields","--","--","--","points",":","ndarray","of","shape","(","n_pts",",","3",")","Streamline","points"]
code: def _read(cls, fileobj, header, buffer_size=4):
      """Return generator that reads TCK data from `fileobj` given `header`
  
      Parameters
      ----------
      fileobj : string or file-like object
          If string, a filename; otherwise an open file-like object in
          binary mode pointing to TCK file (and ready to read from the
          beginning of the TCK header). Note that calling this function
          does not change the file position.
      header : dict
          Metadata associated with this tractogram file.
      buffer_size : float, optional
          Size (in Mb) for buffering.
  
      Yields
      ------
      points : ndarray of shape (n_pts, 3)
          Streamline points
      """
      dtype = header["_dtype"]
      coordinate_size = 3 * dtype.itemsize
      # Make buffer_size an integer and a multiple of coordinate_size.
      buffer_size = int(buffer_size * MEGABYTE)
      buffer_size += coordinate_size - (buffer_size % coordinate_size)
  
      with Opener(fileobj) as f:
          start_position = f.tell()
  
          # Set the file position at the beginning of the data.
          f.seek(header["_offset_data"], os.SEEK_SET)
  
          eof = False
          leftover = np.empty((0, 3), dtype="<f4")
          n_streams = 0
  
          while not eof:
              buff = bytearray(buffer_size)
              n_read = f.readinto(buff)
              eof = n_read != buffer_size
              if eof:
                  buff = buff[:n_read]
  
              raw_values = np.frombuffer(buff, dtype=dtype)
  
              # Convert raw_values into a list of little-endian triples (for x,y,z coord)
              coords = raw_values.astype("<f4", copy=False).reshape(
                  (-1, 3)
              )
  
              # Find stream delimiter locations (all NaNs)
              delims = np.where(np.isnan(coords).all(axis=1))[0]
  
              # Recover leftovers, which can't have delimiters in them
              if leftover.size:
                  delims += leftover.shape[0]
                  coords = np.vstack((leftover, coords))
  
              begin = 0
              for delim in delims:
                  pts = coords[begin:delim]
                  if pts.size:
                      yield pts
                      n_streams += 1
                  begin = delim + 1
  
              # The rest becomes the new leftover.
              leftover = coords[begin:]
  
          if not (
              leftover.shape == (1, 3) and np.isinf(leftover).all()
          ):
              if n_streams == 0:
                  msg = "Cannot find a streamline delimiter. This file might be corrupted."
              else:
                  msg = "Expecting end-of-file marker 'inf inf inf'"
              raise DataError(msg)
  
          # In case the 'count' field was not provided.
          header[Field.NB_STREAMLINES] = n_streams
  
          # Set the file position where it was (in case it was already open).
          f.seek(start_position, os.SEEK_CUR)
  
imports: import os
  import warnings
  from contextlib import suppress
  import numpy
  from nibabel.openers import Opener
  from .array_sequence import ArraySequence
  from .header import Field
  from .tractogram import LazyTractogram, Tractogram, TractogramItem
  from .tractogram_file import DataError, DataWarning, HeaderError, HeaderWarning, TractogramFile
  from .utils import peek_next
label_desc: Use image node_id 9 for calling the TckFile obj's underlying member method code with example usage: obj._read(cls, fileobj, header, buffer_size) without return types