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: Save tractogram to a filename or file-like object using TCK format.
  
  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 write from the
      beginning of the TCK header data).
docstr_tok: ["Save","tractogram","to","a","filename","or","file-like","object","using","TCK","format",".","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","write","from","the","beginning","of","the","TCK","header","data",")","."]
code: def save(self, fileobj):
      """Save tractogram to a filename or file-like object using TCK format.
  
      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 write from the
          beginning of the TCK header data).
      """
      # Enforce float32 in little-endian byte order for data.
      dtype = np.dtype("<f4")
      header = self.create_empty_header()
  
      # Override hdr's fields by those contained in `header`.
      header.update(self.header)
  
      # Keep counts for correcting incoherent fields or warn.
      nb_streamlines = 0
  
      with Opener(fileobj, mode="wb") as f:
          # Keep track of the beginning of the header.
          beginning = f.tell()
  
          # Write temporary header that we will update at the end
          self._write_header(f, header)
  
          # Make sure streamlines are in rasmm.
          tractogram = self.tractogram.to_world(lazy=True)
          # Assume looping over the streamlines can be done only once.
          tractogram = iter(tractogram)
  
          try:
              # Use the first element to check
              #  1) the tractogram is not empty;
              #  2) quantity of information saved along each streamline.
              first_item, tractogram = peek_next(tractogram)
          except StopIteration:
              # Empty tractogram
              header[Field.NB_STREAMLINES] = 0
              self._finalize_header(f, header, offset=beginning)
  
              # Add the EOF_DELIMITER.
              f.write(self.EOF_DELIMITER.tobytes())
              return
  
          data_for_streamline = first_item.data_for_streamline
          if len(data_for_streamline) > 0:
              keys = ", ".join(data_for_streamline.keys())
              msg = (
                  "TCK format does not support saving additional "
                  f"data alongside streamlines. Dropping: {keys}"
              )
              warnings.warn(msg, DataWarning)
  
          data_for_points = first_item.data_for_points
          if len(data_for_points) > 0:
              keys = ", ".join(data_for_points.keys())
              msg = (
                  "TCK format does not support saving additional "
                  f"data alongside points. Dropping: {keys}"
              )
              warnings.warn(msg, DataWarning)
  
          for t in tractogram:
              data = np.r_[t.streamline, self.FIBER_DELIMITER]
              f.write(data.astype(dtype).tobytes())
              nb_streamlines += 1
  
          header[Field.NB_STREAMLINES] = nb_streamlines
  
          # Add the EOF_DELIMITER.
          f.write(self.EOF_DELIMITER.tobytes())
          self._finalize_header(f, header, offset=beginning)
  
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 6 for calling the TckFile obj's underlying member method code with example usage: obj.save(fileobj) without return types