old_contents: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  import os
  from tempfile import mkdtemp
  from shutil import rmtree
  
  from nipype.testing import (assert_equal, example_data, skipif, assert_true, assert_in)
  from nipype.algorithms.confounds import FramewiseDisplacement, ComputeDVARS
  import numpy as np
  
  
  nonitime = True
  try:
      import nitime
      nonitime = False
  except ImportError:
      pass
  
  
  def test_fd():
      tempdir = mkdtemp()
      ground_truth = np.loadtxt(example_data('fsl_motion_outliers_fd.txt'))
      fdisplacement = FramewiseDisplacement(in_plots=example_data('fsl_mcflirt_movpar.txt'),
                                            out_file=tempdir + '/fd.txt')
      res = fdisplacement.run()
  
      with open(res.outputs.out_file) as all_lines:
          for line in all_lines:
              yield assert_in, 'framewise_displacement', line
              break
  
      yield assert_true, np.allclose(ground_truth, np.loadtxt(res.outputs.out_file), atol=.16)
      yield assert_true, np.abs(ground_truth.mean() - res.outputs.fd_average) < 1e-2
  
      rmtree(tempdir)
  
  @skipif(nonitime)
  def test_dvars():
      tempdir = mkdtemp()
      ground_truth = np.loadtxt(example_data('ds003_sub-01_mc.DVARS'))
      dvars = ComputeDVARS(in_file=example_data('ds003_sub-01_mc.nii.gz'),
                           in_mask=example_data('ds003_sub-01_mc_brainmask.nii.gz'),
                           save_all=True)
  
      origdir = os.getcwd()
      os.chdir(tempdir)
  
      res = dvars.run()
  
      dv1 = np.loadtxt(res.outputs.out_std)
      yield assert_equal, (np.abs(dv1 - ground_truth).sum()/ len(dv1)) < 0.05, True
  
      os.chdir(origdir)
      rmtree(tempdir)
  
new_contents: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  import os
  from tempfile import mkdtemp
  from shutil import rmtree
  
  from io import open
  
  from nipype.testing import (assert_equal, example_data, skipif, assert_true, assert_in)
  from nipype.algorithms.confounds import FramewiseDisplacement, ComputeDVARS
  import numpy as np
  
  
  nonitime = True
  try:
      import nitime
      nonitime = False
  except ImportError:
      pass
  
  
  def test_fd():
      tempdir = mkdtemp()
      ground_truth = np.loadtxt(example_data('fsl_motion_outliers_fd.txt'))
      fdisplacement = FramewiseDisplacement(in_plots=example_data('fsl_mcflirt_movpar.txt'),
                                            out_file=tempdir + '/fd.txt')
      res = fdisplacement.run()
  
      with open(res.outputs.out_file) as all_lines:
          for line in all_lines:
              yield assert_in, 'framewise_displacement', line
              break
  
      yield assert_true, np.allclose(ground_truth, np.loadtxt(res.outputs.out_file), atol=.16)
      yield assert_true, np.abs(ground_truth.mean() - res.outputs.fd_average) < 1e-2
  
      rmtree(tempdir)
  
  @skipif(nonitime)
  def test_dvars():
      tempdir = mkdtemp()
      ground_truth = np.loadtxt(example_data('ds003_sub-01_mc.DVARS'))
      dvars = ComputeDVARS(in_file=example_data('ds003_sub-01_mc.nii.gz'),
                           in_mask=example_data('ds003_sub-01_mc_brainmask.nii.gz'),
                           save_all=True)
  
      origdir = os.getcwd()
      os.chdir(tempdir)
  
      res = dvars.run()
  
      dv1 = np.loadtxt(res.outputs.out_std)
      yield assert_equal, (np.abs(dv1 - ground_truth).sum()/ len(dv1)) < 0.05, True
  
      os.chdir(origdir)
      rmtree(tempdir)
  
subject: use from io import open