code: def save(tractogram, filename, **kwargs):
      r"""Saves a tractogram to a file.
  
      Parameters
      ----------
      tractogram : :class:`Tractogram` object or :class:`TractogramFile` object
          If :class:`Tractogram` object, the file format will be guessed from
          `filename` and a :class:`TractogramFile` object will be created using
          provided keyword arguments.
          If :class:`TractogramFile` object, the file format is known and will
          be used to save its content to `filename`.
      filename : str
          Name of the file where the tractogram will be saved.
      \*\*kwargs : keyword arguments
          Keyword arguments passed to :class:`TractogramFile` constructor.
          Should not be specified if `tractogram` is already an instance of
          :class:`TractogramFile`.
      """
      tractogram_file_class = detect_format(filename)
      if isinstance(tractogram, Tractogram):
          if tractogram_file_class is None:
              msg = f"Unknown tractogram file format: '{filename}'"
              raise ValueError(msg)
  
          tractogram_file = tractogram_file_class(tractogram, **kwargs)
  
      else:  # Assume it's a TractogramFile object.
          tractogram_file = tractogram
          if tractogram_file_class is None or not isinstance(
              tractogram_file, tractogram_file_class
          ):
              msg = (
                  "The extension you specified is unusual for the provided"
                  " 'TractogramFile' object."
              )
              warnings.warn(msg, ExtensionWarning)
  
          if kwargs:
              msg = (
                  "A 'TractogramFile' object was provided, no need for"
                  " keyword arguments."
              )
              raise ValueError(msg)
  
      tractogram_file.save(filename)
  
file_path: nibabel/nibabel/streamlines/__init__.py
imports: import os
  import warnings
  from .array_sequence import ArraySequence
  from .header import Field
  from .tck import TckFile
  from .tractogram import LazyTractogram, Tractogram
  from .tractogram_file import ExtensionWarning
  from .trk import TrkFile
label_desc: Use image node_id 4 for calling a global function with example usage: save(tractogram, filename) without return types