class_docstr: Manipulates an existing transform file generated with elastix
  
  Example
  -------
  
  >>> from nipype.interfaces.elastix import EditTransform
  >>> tfm = EditTransform()
  >>> tfm.inputs.transform_file = 'TransformParameters.0.txt'  # doctest: +SKIP
  >>> tfm.inputs.reference_image = 'fixed1.nii'  # doctest: +SKIP
  >>> tfm.inputs.output_type = 'unsigned char'
  >>> tfm.run() # doctest: +SKIP
code: def _run_interface(self, runtime):
      import re
      import nibabel as nb
      import numpy as np
  
      contents = ""
  
      with open(self.inputs.transform_file) as f:
          contents = f.read()
  
      if isdefined(self.inputs.output_type):
          p = re.compile(
              (self._pattern % "ResultImagePixelType").decode(
                  "string-escape"
              )
          )
          rep = r"(\g<entry>%s\g<3>" % self.inputs.output_type
          contents = p.sub(rep, contents)
  
      if isdefined(self.inputs.output_format):
          p = re.compile(
              (self._pattern % "ResultImageFormat").decode(
                  "string-escape"
              )
          )
          rep = r"(\g<entry>%s\g<3>" % self.inputs.output_format
          contents = p.sub(rep, contents)
  
      if isdefined(self.inputs.interpolation):
          p = re.compile(
              (self._pattern % "FinalBSplineInterpolationOrder").decode(
                  "string-escape"
              )
          )
          rep = (
              r"(\g<entry>%s\g<3>"
              % self._interp[self.inputs.interpolation]
          )
          contents = p.sub(rep, contents)
  
      if isdefined(self.inputs.reference_image):
          im = nb.load(self.inputs.reference_image)
  
          if len(im.header.get_zooms()) == 4:
              im = nb.func.four_to_three(im)[0]
  
          size = " ".join(["%01d" % s for s in im.shape])
          p = re.compile(
              (self._pattern % "Size").decode("string-escape")
          )
          rep = r"(\g<entry>%s\g<3>" % size
          contents = p.sub(rep, contents)
  
          index = " ".join(["0" for s in im.shape])
          p = re.compile(
              (self._pattern % "Index").decode("string-escape")
          )
          rep = r"(\g<entry>%s\g<3>" % index
          contents = p.sub(rep, contents)
  
          spacing = " ".join(
              ["%0.4f" % f for f in im.header.get_zooms()]
          )
          p = re.compile(
              (self._pattern % "Spacing").decode("string-escape")
          )
          rep = r"(\g<entry>%s\g<3>" % spacing
          contents = p.sub(rep, contents)
  
          itkmat = np.eye(4)
          itkmat[0, 0] = -1
          itkmat[1, 1] = -1
  
          affine = np.dot(itkmat, im.affine)
          dirs = " ".join(
              ["%0.4f" % f for f in affine[0:3, 0:3].reshape(-1)]
          )
          orig = " ".join(
              ["%0.4f" % f for f in affine[0:3, 3].reshape(-1)]
          )
  
          # p = re.compile((self._pattern % 'Direction').decode('string-escape'))
          # rep = '(\g<entry>%s\g<3>' % dirs
          # contents = p.sub(rep, contents)
  
          p = re.compile(
              (self._pattern % "Origin").decode("string-escape")
          )
          rep = r"(\g<entry>%s\g<3>" % orig
          contents = p.sub(rep, contents)
  
      with open(self._get_outfile(), "w") as of:
          of.write(contents)
  
      return runtime
  
file_path: nipype/nipype/interfaces/elastix/utils.py
imports: import os.path
  from ...None import logging
  from ..base import BaseInterface, BaseInterfaceInputSpec, isdefined, TraitedSpec, File, traits
label_desc: Use image node_id 1 for calling the EditTransform obj's underlying member method code with example usage: obj._run_interface(runtime) and returns: runtime