code: def test_reg_average():
      """tests for reg_average interface"""
      # Create a reg_average object
      nr_average = RegAverage()
  
      # Check if the command is properly defined
      assert nr_average.cmd == get_custom_path("reg_average")
  
      # Average niis
      one_file = example_data("im1.nii")
      two_file = example_data("im2.nii")
      three_file = example_data("im3.nii")
      nr_average.inputs.avg_files = [one_file, two_file, three_file]
      nr_average.inputs.omp_core_val = 1
      generated_cmd = nr_average.cmdline
  
      # Read the reg_average_cmd
      reg_average_cmd = os.path.join(os.getcwd(), "reg_average_cmd")
      with open(reg_average_cmd, "rb") as f_obj:
          argv = f_obj.read()
      os.remove(reg_average_cmd)
  
      expected_argv = "{} {} -avg {} {} {} -omp 1".format(
          get_custom_path("reg_average"),
          os.path.join(os.getcwd(), "avg_out.nii.gz"),
          one_file,
          two_file,
          three_file,
      )
  
      assert argv.decode("utf-8") == expected_argv
  
      # Test command line with text file
      expected_cmd = "{} --cmd_file {}".format(
          get_custom_path("reg_average"),
          reg_average_cmd,
      )
  
      assert generated_cmd == expected_cmd
  
      # Test Reg Average: average txt
      nr_average_2 = RegAverage()
      one_file = example_data("TransformParameters.0.txt")
      two_file = example_data("ants_Affine.txt")
      three_file = example_data("elastix.txt")
      nr_average_2.inputs.avg_files = [one_file, two_file, three_file]
      nr_average_2.inputs.omp_core_val = 1
      generated_cmd = nr_average_2.cmdline
  
      # Read the reg_average_cmd
      reg_average_cmd = os.path.join(os.getcwd(), "reg_average_cmd")
      with open(reg_average_cmd, "rb") as f_obj:
          argv = f_obj.read()
      os.remove(reg_average_cmd)
  
      expected_argv = "{} {} -avg {} {} {} -omp 1".format(
          get_custom_path("reg_average"),
          os.path.join(os.getcwd(), "avg_out.txt"),
          one_file,
          two_file,
          three_file,
      )
  
      assert argv.decode("utf-8") == expected_argv
  
      # Test Reg Average: average list
      nr_average_3 = RegAverage()
      one_file = example_data("TransformParameters.0.txt")
      two_file = example_data("ants_Affine.txt")
      three_file = example_data("elastix.txt")
      nr_average_3.inputs.avg_lts_files = [
          one_file,
          two_file,
          three_file,
      ]
      nr_average_3.inputs.omp_core_val = 1
      generated_cmd = nr_average_3.cmdline
  
      # Read the reg_average_cmd
      reg_average_cmd = os.path.join(os.getcwd(), "reg_average_cmd")
      with open(reg_average_cmd, "rb") as f_obj:
          argv = f_obj.read()
      os.remove(reg_average_cmd)
  
      expected_argv = "{} {} -avg_lts {} {} {} -omp 1".format(
          get_custom_path("reg_average"),
          os.path.join(os.getcwd(), "avg_out.txt"),
          one_file,
          two_file,
          three_file,
      )
  
      assert argv.decode("utf-8") == expected_argv
  
      # Test Reg Average: average ref
      nr_average_4 = RegAverage()
      ref_file = example_data("anatomical.nii")
      one_file = example_data("im1.nii")
      two_file = example_data("im2.nii")
      three_file = example_data("im3.nii")
      trans1_file = example_data("roi01.nii")
      trans2_file = example_data("roi02.nii")
      trans3_file = example_data("roi03.nii")
      nr_average_4.inputs.warp_files = [
          trans1_file,
          one_file,
          trans2_file,
          two_file,
          trans3_file,
          three_file,
      ]
      nr_average_4.inputs.avg_ref_file = ref_file
      nr_average_4.inputs.omp_core_val = 1
      generated_cmd = nr_average_4.cmdline
  
      # Read the reg_average_cmd
      reg_average_cmd = os.path.join(os.getcwd(), "reg_average_cmd")
      with open(reg_average_cmd, "rb") as f_obj:
          argv = f_obj.read()
      os.remove(reg_average_cmd)
  
      expected_argv = (
          "{} {} -avg_tran {} -omp 1 {} {} {} {} {} {}".format(
              get_custom_path("reg_average"),
              os.path.join(os.getcwd(), "avg_out.nii.gz"),
              ref_file,
              trans1_file,
              one_file,
              trans2_file,
              two_file,
              trans3_file,
              three_file,
          )
      )
  
      assert argv.decode("utf-8") == expected_argv
  
      # Test Reg Average: demean3
      nr_average_5 = RegAverage()
      ref_file = example_data("anatomical.nii")
      one_file = example_data("im1.nii")
      two_file = example_data("im2.nii")
      three_file = example_data("im3.nii")
      aff1_file = example_data("TransformParameters.0.txt")
      aff2_file = example_data("ants_Affine.txt")
      aff3_file = example_data("elastix.txt")
      trans1_file = example_data("roi01.nii")
      trans2_file = example_data("roi02.nii")
      trans3_file = example_data("roi03.nii")
      nr_average_5.inputs.warp_files = [
          aff1_file,
          trans1_file,
          one_file,
          aff2_file,
          trans2_file,
          two_file,
          aff3_file,
          trans3_file,
          three_file,
      ]
      nr_average_5.inputs.demean3_ref_file = ref_file
      nr_average_5.inputs.omp_core_val = 1
      generated_cmd = nr_average_5.cmdline
  
      # Read the reg_average_cmd
      reg_average_cmd = os.path.join(os.getcwd(), "reg_average_cmd")
      with open(reg_average_cmd, "rb") as f_obj:
          argv = f_obj.read()
      os.remove(reg_average_cmd)
  
      expected_argv = (
          "{} {} -demean3 {} -omp 1 {} {} {} {} {} {} {} {} {}".format(
              get_custom_path("reg_average"),
              os.path.join(os.getcwd(), "avg_out.nii.gz"),
              ref_file,
              aff1_file,
              trans1_file,
              one_file,
              aff2_file,
              trans2_file,
              two_file,
              aff3_file,
              trans3_file,
              three_file,
          )
      )
  
      assert argv.decode("utf-8") == expected_argv
  
file_path: nipype/nipype/interfaces/niftyreg/tests/test_regutils.py
imports: import os
  import pytest
  from ....utils.filemanip import which
  from ....testing import example_data
  from ..None import get_custom_path, RegAverage, RegResample, RegJacobian, RegTools, RegMeasure, RegTransform
label_desc: Use image node_id 5 for calling a global function with example usage: test_reg_average() without return types