Open
Description
Summary
The Cat12Segment
interface does not accept compressed .nii.gz
files. Everything works fine when one inputs an .nii
file.
Actual behavior
This is the error I get:
TraitError: Each element of the 'in_files' trait of a CAT12SegmentInputSpec instance must be a pathlike object or string representing an existing file, but a value of '/pandora/home/johannes.wiesner/work/testing/debug_cat12/T1w.nii.gz' <class 'str'> was specified.
which by the way is a little bit misleading because the file exists but the file extension if the problem (but this is another topic I guess).
Expected behavior
Run Segmentation on a .nii.gz
file should work because newer versions of CAT12 are able to deal with .nii.gz
files. My CAT12 version is CAT12.9 (r2560) inside an spm12/9.14 environment module.
See also: https://www.neuro.uni-jena.de/cat12/CAT12-Manual-old.pdf
The segmentation module now supports the input of nii.gz files (not
possible for the longitudinal pipeline).
How to replicate the behavior
Here's an example script that should reproduce the error:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Debug CAT12Segment
"""
import subprocess
from nipype.interfaces.cat12.preprocess import CAT12Segment
from nipype import Node
import os
###############################################################################
# Preparation: Download an anatomical files from a public available AWS-bucket
###############################################################################
# download T1w image
command = """
curl \
--create-dirs https://s3.amazonaws.com/openneuro.org/ds004302/sub-02/anat/sub-02_T1w.nii.gz?versionId=93eQ.AwPcMeccJAT3sO9otYv4A_WH3Bj \
-o ./T1w.nii.gz
"""
subprocess.run(command,shell=True)
# gunzip image to get from .nii.gz to .nii
subprocess.run("gunzip -c ./T1w.nii.gz > T1w.nii",shell=True)
# get the full path to the directory where this script is being executed
script_dir = os.path.dirname(os.path.realpath(__file__))
# get full path to both images (nipype always needs absolut paths to inputs)
image_nii = os.path.join(script_dir,'T1w.nii')
image_nii_gz = os.path.join(script_dir,'T1w.nii.gz')
###############################################################################
# Run CAT12Segment inside a node on one image
###############################################################################
# create node
cat12segment = Node(CAT12Segment(surface_and_thickness_estimation=0,
surface_measures=0),
name='cat12segment')
# input image
cat12segment.inputs.in_files = image_nii_gz
# set working directory of node to script directory
cat12segment.base_dir = script_dir
# run the node
cat12segment.run()
Platform details:
{'commit_hash': '%h',
'commit_source': 'archive substitution',
'networkx_version': '3.2.1',
'nibabel_version': '5.2.0',
'nipype_version': '1.8.6',
'numpy_version': '1.26.3',
'pkg_path': '/csp-tools/anaconda3/envs/csp_wiesner_johannes/lib/python3.9/site-packages/nipype',
'scipy_version': '1.12.0',
'sys_executable': '/csp-tools/anaconda3/envs/csp_wiesner_johannes/bin/python',
'sys_platform': 'linux',
'sys_version': '3.9.18 | packaged by conda-forge | (main, Dec 23 2023, '
'16:33:10) \n'
'[GCC 12.3.0]',
'traits_version': '6.3.2'}
Execution environment
Choose one
- My python environment outside container
Metadata
Metadata
Assignees
Labels
No labels