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: Write TCK header to file-like object.
  
  Parameters
  ----------
  fileobj : file-like object
      An open file-like object in binary mode pointing to TCK file (and
      ready to read from the beginning of the TCK header).
docstr_tok: ["Write","TCK","header","to","file-like","object",".","Parameters","--","--","--","--","--","fileobj",":","file-like","object","An","open","file-like","object","in","binary","mode","pointing","to","TCK","file","(","and","ready","to","read","from","the","beginning","of","the","TCK","header",")","."]
code: def _write_header(fileobj, header):
      """Write TCK header to file-like object.
  
      Parameters
      ----------
      fileobj : file-like object
          An open file-like object in binary mode pointing to TCK file (and
          ready to read from the beginning of the TCK header).
      """
      # Fields to exclude
      exclude = [
          Field.MAGIC_NUMBER,  # Handled separately.
          Field.NB_STREAMLINES,  # Handled separately.
          Field.ENDIANNESS,  # Handled separately.
          Field.VOXEL_TO_RASMM,  # Streamlines are always in RAS+ mm.
          "count",
          "datatype",
          "file",
      ]  # Fields being replaced.
  
      lines = [
          f"count: {header[Field.NB_STREAMLINES]:010}",
          "datatype: Float32LE",  # Always Float32LE.
      ]
      lines.extend(
          f"{k}: {v}"
          for k, v in header.items()
          if k not in exclude and not k.startswith("_")
      )
      out = "\n".join(lines)
  
      if out.count(":") > len(lines):
          # : only one per line (except the last one which contains END).
          msg = f"Key-value pairs cannot contain ':':\n{out}"
          raise HeaderError(msg)
  
      out = header[Field.MAGIC_NUMBER] + b"\n" + out.encode("utf-8")
  
      # Compute data offset considering the offset string representation
      # headers + "file" header + END + \n's
      hdr_offset = len(out) + 8 + 3 + 3
      offset_repr = f"{hdr_offset}"
  
      # Adding the offset may increase one char to the offset repr
      hdr_offset += len(f"{hdr_offset + len(offset_repr)}")
  
      # Write header to file.
      fileobj.write(out)
      fileobj.write(f"\nfile: . {hdr_offset}\nEND\n".encode())
  
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 7 for calling the TckFile obj's underlying member method code with example usage: obj._write_header(fileobj, header) without return types