class_docstr: Creates a tract density image from a TrackVis track file using functions
  from dipy
  
  Example
  -------
  
  >>> import nipype.interfaces.dipy as dipy
  >>> trk2tdi = dipy.TrackDensityMap()
  >>> trk2tdi.inputs.in_file = 'converted.trk'
  >>> trk2tdi.run()                                   # doctest: +SKIP
class_docstr_tok: ["Creates","a","tract","density","image","from","a","TrackVis","track","file","using","functions","from","dipy","Example","--","--","--","-",">",">",">","import","nipype.interfaces.dipy","as","dipy",">",">",">","trk2tdi","=","dipy.TrackDensityMap","(",")",">",">",">","trk2tdi.inputs.in_file","=","'converted.trk'",">",">",">","trk2tdi.run","(",")","#","doctest",":","+SKIP"]
code: def _run_interface(self, runtime):
      from numpy import min_scalar_type
      from dipy.tracking.utils import density_map
      import nibabel.trackvis as nbt
  
      tracks, header = nbt.read(self.inputs.in_file)
      streams = ((ii[0]) for ii in tracks)
  
      if isdefined(self.inputs.reference):
          refnii = nb.load(self.inputs.reference)
          affine = refnii.affine
          data_dims = refnii.shape[:3]
          kwargs = dict(affine=affine)
      else:
          IFLOGGER.warning(
              "voxel_dims and data_dims are deprecated as of dipy "
              "0.7.1. Please use reference input instead"
          )
  
          if not isdefined(self.inputs.data_dims):
              data_dims = header["dim"]
          else:
              data_dims = self.inputs.data_dims
          if not isdefined(self.inputs.voxel_dims):
              voxel_size = header["voxel_size"]
          else:
              voxel_size = self.inputs.voxel_dims
  
          affine = header["vox_to_ras"]
          kwargs = dict(voxel_size=voxel_size)
  
      data = density_map(streams, data_dims, **kwargs)
      data = data.astype(min_scalar_type(data.max()))
      img = nb.Nifti1Image(data, affine)
      out_file = op.abspath(self.inputs.out_filename)
      nb.save(img, out_file)
  
      IFLOGGER.info(
          "Track density map saved as %s, size=%s, dimensions=%s",
          out_file,
          img.shape,
          img.header.get_zooms(),
      )
  
      return runtime
  
imports: import os.path
  import numpy
  import nibabel
  from looseversion import LooseVersion
  from ...None import logging
  from ..base import TraitedSpec, BaseInterfaceInputSpec, File, isdefined, traits
  from .base import DipyBaseInterface, HAVE_DIPY, dipy_version, dipy_to_nipype_interface, get_dipy_workflows
label_desc: Use image node_id 1 for calling the TrackDensityMap obj's underlying member method code with example usage: obj._run_interface(runtime) and returns: runtime