Closed njhunsak closed 8 years ago
I'm afraid I haven't run into this error before. If the two image volumes are not the same shape, it makes me wonder whether the function called the correct volumes. Did you use the standard inputs with antscorticalthickness.sh and mindboggle? When I run into a nipype error, I either type "nipype_display_crash [crash file]" to see what the inputs and outputs were, or I go to the function's corresponding directory in the nipype working directory and unzip and load the pickle files for closer scrutiny...
Hum. Wasn't able to figure much out from the pklz files. But looking at the input images, the ants_labels.nii.gz_to_ants_labels.nii.gz_through_combined_segmentations.nii.gz file in the Combine_ANTs_cortex_noncortex_labels directory is totally blank where the wmparc.mgz.nii.gz file in the Extract_FreeSurfer_cerebella shows the right and left cerebellum. I'm guessing then something is going wrong when trying to extract the cerebellum label from the ANTs cortical thickness brain segmentation file. When I run antsCorticalThickness.sh, I am using the standard inputs. Am I using the correct file for mindboggle is the question? My output prefix for antscorticalthickness.sh is just a directory. I don't actually givd the files an additional prefix, so when I use mindboggle and I include the "--ants" option, the file I use is called "BrainSegmentation.nii.gz". It's the file that labels CSF as 1, GM as 2, WM as 3, subcortical as 4, brainstem as 5, and cerebellum as 6. Do you think I might be having a problem because I'm using the NKI10andUnder template instead of the OASIS template? Am I using the correct file for the mindboggle --ants option? The pipeline runs fine if I don't include the --ants option, so that's positive! Thanks for your help.
Good sleuthing. As long as your PREFIX results in a segmented file whose full path you can call as SEGMENTS in the mindboggle command (e.g., "mindboggle SUBJECT --ants SEGMENTS"), then you should be okay. I don't recommend using a different template, because the labels of the OASIS label fusion atlas won't coincide with the anatomy of another template. Are you using the NKI10andUnder template instead of the OASIS-30 Atropos template in the antsCorticalThickness.sh command?:
antsCorticalThickness.sh -d 3 -a IMAGE -o PREFIX \ -e OASIS-30_Atropos_template/T_template0.nii.gz \ -t OASIS-30_Atropos_template/T_template0_BrainCerebellum.nii.gz \ -m OASIS-30_Atropos_template/T_template0_BrainCerebellumProbabilityMask.nii.gz \ -f OASIS-30_Atropos_template/T_template0_BrainCerebellumExtractionMask.nii.gz \ -p OASIS-30_Atropos_template/Priors2/priors%d.nii.gz
I am using the NKI10andUnder template instead of the OASIS-30 Atropos template in the antsCroticalThickness.sh command. However, I reran antsCorticalThickness.sh with the OASIS-30 template and I still get the same problem. The ants_labels.nii.gz_to_ants_labels.nii.gz_through_combined_segmentations.nii.gz
file is blank. Hence, this is the crash output I get. At what point in the pipeline is the ants_labels.nii.gz_to_ants_labels.nii.gz_through_combined_segmentations.nii.gz
file created?
File: /fslhome/intj5/scripts/crash-20151015-125645-intj5-FreeSurfer_cerebellum_ANTs_cerebrum.pklz
Node: Mindboggle.Volume_labels.FreeSurfer_cerebellum_ANTs_cerebrum
Working directory: /fslhome/intj5/mindboggle_working/1004--2014-08-15/Mindboggle/Volume_labels/FreeSurfer_cerebellum_ANTs_cerebrum
Node inputs:
erase_labels = False
function_str = S'def overwrite_volume_labels(source, target, output_file=\'\', ignore_labels=[0],
erase_labels=True, background_value=-1):
"""
For every label in a source image, optionally erase all voxels in the
target image with this label (if erase_labels is True), and
for every voxel in the source image with this label,
assign the label to the corresponding voxel in the target image.
The source and target images must have the same volume dimensions.
Parameters
----------
source : string
labeled nibabel-readable (e.g., nifti) file
target : string
labeled nibabel-readable (e.g., nifti) file
output_file : string
labeled nibabel-readable (e.g., nifti) file
ignore_labels : list
list of source labels to ignore
erase_labels : Boolean
erase target labels (that are in source) before overwriting?
background_value : integer
background value (if erase_labels==True)
Returns
-------
output_file : string
labeled nibabel-readable (e.g., nifti) file
Examples
--------
>>> # Overwrite DKT25 with DKT31 labels
>>> import os
>>> from mindboggle.guts.relabel import overwrite_volume_labels
>>> from mindboggle.mio.plots import plot_volumes
>>> data_path = os.environ[\'MINDBOGGLE_DATA\']
>>> source = os.path.join(data_path, \'arno\', \'labels\', \'labels.DKT31.manual.nii.gz\')
>>> target = os.path.join(data_path, \'arno\', \'labels\', \'labels.DKT25.manual.nii.gz\')
>>> output_file = \'\'
>>> ignore_labels = [0]
>>> erase_labels = True
>>> background_value = -1
>>> output_file = overwrite_volume_labels(source, target, output_file, ignore_labels, erase_labels, background_value)
>>> # View
>>> plot_volumes(output_file)
"""
import os
import numpy as np
import nibabel as nb
if not output_file:
output_file = os.path.join(os.getcwd(), os.path.basename(source) +
\'_to_\' + os.path.basename(target))
# Load labeled image volumes:
vol_source = nb.load(source)
vol_target = nb.load(target)
if vol_source.shape != vol_target.shape:
raise(IOError(\'{0} and {1} need to be the same shape.\'.
format(source, target)))
xfm = vol_target.get_affine()
data_source = vol_source.get_data().ravel()
data_target = vol_target.get_data().ravel()
# Initialize output:
new_data = data_target.copy()
# Find indices with labels in source:
IX = [(i,x) for i,x in enumerate(data_source) if x not in ignore_labels]
I = [x[0] for x in IX]
X = [x[1] for x in IX]
# Erase target labels (that are in source) before overwriting:
if erase_labels:
rm_labels = np.unique(X)
Irm = [i for i,x in enumerate(data_target) if x in rm_labels]
new_data[Irm] = background_value
# Overwrite target labels with source labels:
new_data[I] = X
# Reshape to original dimensions:
new_data = np.reshape(new_data, vol_target.shape)
# Save relabeled file:
img = nb.Nifti1Image(new_data, xfm)
img.to_filename(output_file)
if not os.path.exists(output_file):
s = "overwrite_volume_labels() did not create " + output_file + "."
raise(IOError(s))
return output_file
'
.
ignore_exception = False
ignore_labels = [0]
output_file =
source = /bluehome3/intj5/mindboggle_working/1004--2014-08-15/Mindboggle/Volume_labels/Extract_FreeSurfer_cerebella/wmparc.mgz.nii.gz
target = /bluehome3/intj5/mindboggle_working/1004--2014-08-15/Mindboggle/Volume_labels/Combine_ANTs_cortex_noncortex_labels/ants_labels.nii.gz_to_ants_labels.nii.gz_through_combined_segmentations.nii.gz
Traceback:
Traceback (most recent call last):
File "/bluehome3/intj5/apps/miniconda/lib/python2.7/site-packages/nipype/pipeline/plugins/linear.py", line 38, in run
node.run(updatehash=updatehash)
File "/bluehome3/intj5/apps/miniconda/lib/python2.7/site-packages/nipype/pipeline/engine.py", line 1428, in run
self._run_interface()
File "/bluehome3/intj5/apps/miniconda/lib/python2.7/site-packages/nipype/pipeline/engine.py", line 1538, in _run_interface
self._result = self._run_command(execute)
File "/bluehome3/intj5/apps/miniconda/lib/python2.7/site-packages/nipype/pipeline/engine.py", line 1664, in _run_command
result = self._interface.run()
File "/bluehome3/intj5/apps/miniconda/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1033, in run
runtime = self._run_wrapper(runtime)
File "/bluehome3/intj5/apps/miniconda/lib/python2.7/site-packages/nipype/interfaces/base.py", line 983, in _run_wrapper
runtime = self._run_interface(runtime)
File "/bluehome3/intj5/apps/miniconda/lib/python2.7/site-packages/nipype/interfaces/utility.py", line 445, in _run_interface
out = function_handle(**args)
File "<string>", line 60, in overwrite_volume_labels
IOError: /bluehome3/intj5/mindboggle_working/1004--2014-08-15/Mindboggle/Volume_labels/Extract_FreeSurfer_cerebella/wmparc.mgz.nii.gz and /bluehome3/intj5/mindboggle_working/1004--2014-08-15/Mindboggle/Volume_labels/Combine_ANTs_cortex_noncortex_labels/ants_labels.nii.gz_to_ants_labels.nii.gz_through_combined_segmentations.nii.gz need to be the same shape.
Interface Function failed to run.
The working subdirectory where you are running into a problem, FreeSurfer_cerebellum_ANTs_cerebrum, is the penultimate step of the volume portion of the mindboggle pipeline where FS and ANTs images are combined, just prior to volume feature extraction. You can generate a flow diagram like the one below by adding "-g hier" to your mindboggle command. If you backtrack upstream through the flow diagram from this node, you can find out which working subdirectory contains the culprit. Since the error says that the FS cerebella image and ANTs cerebella image are not the same shape, my suspicion is that it may be as early as the Fetch_atlas stage.
Oh thanks for the info on getting the hierarchy generated. I was a little overwhelmed at the thought of doing that manually!
On Oct 15, 2015, at 4:41 PM, Arno Klein notifications@github.com wrote:
The working subdirectory where you are running into a problem, FreeSurfer_cerebellum_ANTs_cerebrum, is the penultimate step of the volume portion of the mindboggle pipeline where FS and ANTs images are combined, just prior to volume feature extraction. You can generate a flow diagram like the one below by adding "-g hier" to your mindboggle command. If you backtrack upstream through the flow diagram from this node, you can find out which working subdirectory contains the culprit. Since the error says that the FS cerebella image and ANTs cerebella image are not the same shape, my suspicion is that it may be as early as the Fetch_atlas stage.
— Reply to this email directly or view it on GitHub.
Were you able to resolve the problem you were having?
Nope. But I haven't had the time to focus on it either.
On Oct 22, 2015, at 11:17 PM, Arno Klein notifications@github.com wrote:
Were you able to resolve your problem?
— Reply to this email directly or view it on GitHub.
I have revised these functions and added doctests to pull sample data and run the functions on those data. They pass the tests, so you might wish to give it another try. You would need to reinstall Mindboggle on linux using the install script (https://github.com/nipy/mindboggle/blob/master/install/install_mindboggle.sh). I am also finishing up work on a virtual machine that you will be able to install on any OS...
Have you encountered this error before? Any help would be greatly appreciated. I'm so close and would really love to have this program run sans errors! Thanks. Naomi