Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 convert_motionxfm2itk_188: c3d_affine_tool […] died with <Signals.SIGABRT: 6> #1702

Closed
2 tasks
shnizzedy opened this issue Mar 15, 2022 · 6 comments · Fixed by #1683
Closed
2 tasks
Assignees
Labels
3 - Critical bug RBC https://github.com/PennLINC/RBC
Milestone

Comments

@shnizzedy
Copy link
Member

Describe the bug

Node: cpac_sub-colornest035_ses-1.convert_motionxfm2itk_188
Working directory: /outputs/working/cpac_sub-colornest035_ses-1/_scan_rest_run-01/convert_motionxfm2itk_188

Node inputs:

function_str = def run_c3d(reference_file, source_file, transform_file):

    import os
    import subprocess

    itk_transform = os.path.join(os.getcwd(), 'affine.txt')

    cmd = ['c3d_affine_tool', '-ref', reference_file, '-src',
            source_file, transform_file, '-fsl2ras', '-oitk', itk_transform]
    retcode = subprocess.check_output(cmd)

    return itk_transform

reference_file = <undefined>
source_file = <undefined>
transform_file = ['/outputs/working/cpac_sub-colornest035_ses-1/_scan_rest_run-01/oned_matrix_concat_86/MD5E-s43982431--4505293d1740413480db269995b35cf6_calc.aff12.1D']

Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/code/CPAC/pipeline/nipype_pipeline_engine/engine.py", line 388, in run
    return super().run(updatehash)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 516, in run
    result = self._run_interface(execute=True)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 1386, in _run_interface
    self.config["execution"]["stop_on_first_crash"]
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 1295, in _collate_results
    "Subnodes of node: %s failed:\n%s" % (self.name, "\n".join(msg))
Exception: Subnodes of node: convert_motionxfm2itk_188 failed:
Subnode 0 failed
Error: Traceback (most recent call last):

  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/utils.py", line 94, in nodelist_runner
    result = node.run(updatehash=updatehash)

  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 516, in run
    result = self._run_interface(execute=True)

  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_interface
    return self._run_command(execute)

  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 741, in _run_command
    result = self._interface.run(cwd=outdir)

  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/core.py", line 419, in run
    runtime = self._run_interface(runtime)

  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/utility/wrappers.py", line 142, in _run_interface
    out = function_handle(**args)

  File "<string>", line 10, in run_c3d

  File "/usr/local/miniconda/lib/python3.7/subprocess.py", line 411, in check_output
    **kwargs).stdout

  File "/usr/local/miniconda/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)

subprocess.CalledProcessError: Command '['c3d_affine_tool', '-ref', '/outputs/working/cpac_sub-colornest035_ses-1/_scan_rest_run-01/func_get_fmriprep_ref_83/ref_bold.nii.gz', '-src', '/outputs/working/cpac_sub-colornest035_ses-1/_scan_rest_run-01/func_get_fmriprep_ref_83/ref_bold.nii.gz', '/outputs/working/cpac_sub-colornest035_ses-1/_scan_rest_run-01/oned_matrix_concat_86/MD5E-s43982431--4505293d1740413480db269995b35cf6_calc.aff12.1D', '-fsl2ras', '-oitk', '/outputs/working/cpac_sub-colornest035_ses-1/_scan_rest_run-01/convert_motionxfm2itk_188/mapflow/_convert_motionxfm2itk_1880/affine.txt']' died with <Signals.SIGABRT: 6>.

Running the command in a container:

terminate called after throwing an instance of 'char const*'

To reproduce

Run with

functional_preproc:
  motion_estimates_and_correction:
    motion_correction:
      using: [3dvolreg]
registration_workflows: 
  functional_registration:
    func_registration_to_template:
      apply_transform:
        using: single_step_resampling

Expected behavior

c3d_affine_tool succeeds

Acceptance criteria

  • c3d_affine_tool succeeds
    or
  • 'single_step_resampling' is explicitly disallowed for 3dvolreg

Screenshots

No response

C-PAC version

v1.8.4-dev

Container platform

Singularity

Docker and/or Singularity version(s)

Singularity 3.8.5-2.el7

Additional context

No response

@shnizzedy shnizzedy added bug 3 - Critical RBC https://github.com/PennLINC/RBC labels Mar 15, 2022
@shnizzedy shnizzedy added this to the 1.8.4 release milestone Mar 15, 2022
@shnizzedy shnizzedy self-assigned this Mar 15, 2022
@shnizzedy
Copy link
Member Author

mcflirt

*.mat directory with 150 MAT_* files, each 4 × 4

3dvolreg

*.1D file with shape 152 × 12

@shnizzedy
Copy link
Member Author

shnizzedy commented Mar 22, 2022

The diagonals in the MAT_* files are 1s

@gkiar
Copy link
Contributor

gkiar commented Mar 22, 2022

What about the right column or the bottom row? Are they predominantly 0s?

@shnizzedy
Copy link
Member Author

the bottom rows are all 0 0 0 1

@shnizzedy shnizzedy linked a pull request Mar 22, 2022 that will close this issue
8 tasks
@gkiar
Copy link
Contributor

gkiar commented Mar 23, 2022

Perfect. As discussed over Slack, the solution then is to reshape each 1 x 12 row into 3 x 4 and pad it with 0 0 0 1 to conform to the homogeneous coordinates standard.

@shnizzedy
Copy link
Member Author

That did the trick!

def one_d_to_mat(one_d_filename):
"""Convert a .1D file to a .mat directory
Parameters
----------
one_d_filename : str
The filename of the .1D file to convert
Returns
-------
mat_filenames : list of str
The of paths in the .mat directory created
"""
mat_dirname = one_d_filename.replace('.1D', '.mat')
with open(one_d_filename, 'r') as one_d_file:
rows = [np.reshape(row, (4, 4)).astype('float') for row in [[
term.strip() for term in row.split(' ') if term.strip()
] + [0, 0, 0, 1] for row in [
line.strip() for line in one_d_file.readlines() if
not line.startswith('#')]]]
try:
os.mkdir(mat_dirname)
except FileExistsError:
pass
for i, row in enumerate(rows):
np.savetxt(os.path.join(mat_dirname, f'MAT_{i:04}'),
row, fmt='%.5f', delimiter=' ')
mat_filenames = [os.path.join(mat_dirname, filename) for
filename in os.listdir(mat_dirname)]
mat_filenames.sort()
return mat_filenames

motion_correct_tool = cfg['functional_preproc',
'motion_estimates_and_correction',
'motion_correction', 'using']
if motion_correct_tool == 'mcflirt':
wf.connect(node, out, motionxfm2itk, 'transform_file')
elif motion_correct_tool == '3dvolreg':
convert_transform = pe.Node(util.Function(
input_names=['one_d_filename'],
output_names=['transform_directory'],
function=one_d_to_mat,
imports=['import os', 'import numpy as np']),
name=f'convert_transform_{pipe_num}')
wf.connect(node, out, convert_transform, 'one_d_filename')
wf.connect(convert_transform, 'transform_directory',
motionxfm2itk, 'transform_file')

shnizzedy added a commit that referenced this issue May 18, 2022
shnizzedy added a commit that referenced this issue May 18, 2022
Ref #1702

Co-authored-by: Greg Kiar <gkiar@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Critical bug RBC https://github.com/PennLINC/RBC
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants