Trait errors on dcm2nii

91 views
Skip to first unread message

thomas.nickson

unread,
Jan 31, 2014, 11:09:49 AM1/31/14
to nipy...@googlegroups.com
Hey All,

I'm just trying to automate some dicom reconstructions using dcm2nii but every time I run the code, which is basically a rewritten version of the example here (http://miykael.github.io/nipype-beginner-s-guide/preparedata.html) except using dcm2nii instead of dicomconvert which doesn't work on my machine.

"""
Import modules
"""


import os                                    # system functions
import nipype.interfaces.freesurfer as fs    # freesurfer
import nipype.interfaces.dcm2nii as d2n      # dicom2nii
import nipype.interfaces.utility as util     # utility
import nipype.pipeline.engine as pe          # pypeline engine

"""
Define experiment specific parameters
"""


#Specification of the folder where the dicom-files are located at
tmp_dir
= '/data/scanautomator/tmp/'

#Output base dir
outputBase_dir
= '/data/scanautomator/tmp/'

#Subject Name for output directory
subject_name
= 'recon'

#Folder name for input directory
folder_name
= '576a5eb9-a0aa-4716-ae32-db6ebf86dcbe___20140117_131433/20140117_131433'

#Specification of a list containing each scan
folder_list
= ['3__3D_T2_SPACE_Sag']
 
#Specification of the name of the dicom and output folder
dicom_dir_name
= 'dicom' #if the path to the dicoms is: '~SOMEPATH/experiment/dicom'
data_dir_name
= 'data'   #if the path to the data should be: '~SOMEPATH/experiment/data'


"""
Define nodes to use
"""

#Node: Infosource - we use IdentityInterface to create our own node, to specify
#                   the list of subjects the pipeline should be executed on
infosource
= pe.Node(interface=util.IdentityInterface(fields=['folder_id']),
                                                      name
="infosource")
infosource
.iterables = ('folder_id', folder_list)

#Node: DICOMConvert - converts the .dcm files into .nii and moves them into
#                     the folder "data" with a subject specific subfolder
dicom2nifti
= pe.Node(interface=d2n.Dcm2nii(), name="dicom2nifti")
dicom2nifti
.terminal_output = 'file'

# dicom2nifti.inputs.base_output_dir = outputBase_dir + '/' + subject_name
# #This will store the output to '~SOMEPATH/experiment/data'
# dicom2nifti.inputs.file_mapping = [('nifti','*.nii'),('info','dicom.txt'),('dti','*dti.bv*')]
# dicom2nifti.inputs.out_type = 'nii'
# dicom2nifti.inputs.subject_dir_template = '%s'


#Node ParseDICOMDIR - for creating a nicer nifti overview textfile
dcminfo
= pe.Node(interface=fs.ParseDICOMDir(), name="dcminfo")
dcminfo
.inputs.sortbyrun = True
dcminfo
.inputs.summarize = True
dcminfo
.inputs.dicom_info_file = 'nifti_overview.txt'


"""
Define pipeline
"""


#Initiation of the preparation pipeline
prepareflow
= pe.Workflow(name="prepareflow")
 
#Define where the workingdir of the all_consuming_workflow should be stored at
prepareflow
.base_dir = tmp_dir + '/workingdir_prepareflow'


"""
Specify node connections
"""


#Define pathfinder function
def pathfinder(scan, subject):
   
import os
    tmp_dir
= '/data/scanautomator/tmp/'
   
print  os.path.join(tmp_dir, subject, scan)
   
return os.path.join(tmp_dir, subject, scan)

#Connect all components
prepareflow
.connect([(infosource, dicom2nifti,[(('folder_id', pathfinder, folder_name),
                                                 
'source_names')]),
                     
(infosource, dcminfo,[(('folder_id', pathfinder, folder_name),
                                             
'dicom_dir')]),
                     
])
 

"""
Run pipeline and create graph
"""


prepareflow
.run(plugin='MultiProc', plugin_args={'n_procs' : 2})
prepareflow
.write_graph(graph2use='flat')





Every time I run it though I get:

traits.trait_errors.TraitError: Each element of the 'source_names' trait of a Dcm2niiInputSpec instance must be an existing file name, but a value of '/data/scanautomator/tmp/576a5eb9-a0aa-4716-ae32-db6ebf86dcbe___20140117_131433/20140117_131433/3__3D_T2_SPACE_Sag' <type 'str'> was specified.

but I've no idea what it means by an existing filename. This doesn't work when I specify a file either.

Any ideas?

Thanks.




Satrajit Ghosh

unread,
Jan 31, 2014, 11:16:14 AM1/31/14
to nipy-user
hi thomas,

two things:

1. regarding the dcm2nii conversion a few notes:
a.  that message typically refers to the fact that /data/scanautomator/tmp/576a5eb9-a0aa-4716-ae32-db6ebf86dcbe___20140117_131433/20140117_131433/3__3D_T2_SPACE_Sag is not an existing file (can you check - perhaps missing an extension)

b. i made a small change which is necessary for 2 below. let me push that change into master (give me a few minutes).

2. if you are up for testing something here is a dicomconverter that i use which does some really nice things (but requires the following: dcmstack, dcm2nii, nipype, rdflib)


cheers,

satra

--
 
---
You received this message because you are subscribed to the Google Groups "NiPy Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nipy-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thomas Nickson

unread,
Jan 31, 2014, 11:23:43 AM1/31/14
to nipy...@googlegroups.com

Hey Satra,

thanks for the reply.

1a. Yeah, I just checked with cd /data/scanautomator/tmp/576a5eb9-a0aa-4716-ae32-db6ebf86dcbe___20140117_131433/20140117_131433/3__3D_T2_SPACE_Sag and it goes to the right directory.

b. can I pull this down with pip or easy_install or do I need to get it through git? If git, what's the easiest way to that?

2. Yes I'll definitely try and test it.

Thanks,

Tom

Satrajit Ghosh

unread,
Jan 31, 2014, 11:34:44 AM1/31/14
to nipy-user
hi tom,

1a. Yeah, I just checked with cd /data/scanautomator/tmp/576a5eb9-a0aa-4716-ae32-db6ebf86dcbe___20140117_131433/20140117_131433/3__3D_T2_SPACE_Sag and it goes to the right directory.

is it a directory or a file? that parameter is expect a file or a list of files.

Thomas Nickson

unread,
Jan 31, 2014, 11:41:51 AM1/31/14
to nipy...@googlegroups.com
I have tried, a folder, and a file but not a list of files.

But it says: must be an existing directory name

and then complains that,

<type 'str'> was specified

Very confusing.

Satrajit Ghosh

unread,
Jan 31, 2014, 11:46:32 AM1/31/14
to nipy-user
let's make sure we are looking at the same thing:


   source_names (an existing file name)

which version of nipype are you using?

cheers,

satra

Chris Filo Gorgolewski

unread,
Jan 31, 2014, 11:47:26 AM1/31/14
to nipy...@googlegroups.com
Single file also gave you an error? This is a bug.

The interface expects a list of dicom files that you want to convert.

The error message is a bit confusing, but it mentions files not directories. Nonetheless we should try to improve it.

Thomas Nickson

unread,
Jan 31, 2014, 11:54:27 AM1/31/14
to nipy...@googlegroups.com
Ah, no now I see it's my error. When I use a single file then the error is from another part of the program that expects a folder but I'm trying to use the same list for both. Thanks for the help!

I know that dcm2nii accepts a folder instead of a list of files. Is there any way to reinstate this behaviour in nypype? Or is it just to use the folder path to scrape the dcm files in python?

Tom

Satrajit Ghosh

unread,
Jan 31, 2014, 12:59:43 PM1/31/14
to nipy-user
hi tom,

re: downloading branches and nipype, git is the best approach (and gitref.org is a good source)

alternatively (before it gets merged) you can download this and install from there.


cheers,

satra

Satrajit Ghosh

unread,
Jan 31, 2014, 1:02:29 PM1/31/14
to nipy-user
re: directory support for dcm2nii

in many cases we have decided not to implement directory support because they become very hard to create a hash of or hashing can take ages because you need to hash every object in the directory. if there was a store which would provide it's own hash, then it would be easier.

cheers,

satra

Thomas Nickson

unread,
Jan 31, 2014, 3:12:10 PM1/31/14
to nipy...@googlegroups.com

Ah okay. Thanks for the help.

What features does your script have?

Satrajit Ghosh

unread,
Jan 31, 2014, 3:45:54 PM1/31/14
to nipy-user

What features does your script have? 

- it allows customizable directory layouts and naming schemes through heuristic file
- it only converts the necessary dicoms, not everything in a directory
- you can keep links to dicom files in the participant layout
- it's faster than parsesdicomdir or mri_convert if you use dcm2nii option
- it embeds all the dicom metadata inside the nifti header using dcmstack
- it tracks the provenance of the conversion from dicom to nifti in w3c prov format
- the example shows a conversion to openfmri layout structure

- soon you'll be able to add more tags to the metadata representation of the files
- and push the metadata to a provenance store

Christopher Bell

unread,
Feb 22, 2014, 2:50:12 AM2/22/14
to nipy...@googlegroups.com
What script exactly are you referring to here? Is this one of the nipype example
scripts?


Satrajit Ghosh

unread,
Feb 22, 2014, 8:11:12 AM2/22/14
to nipy-user
On Sat, Feb 22, 2014 at 2:50 AM, Christopher Bell <christoph...@gmail.com> wrote:
What script exactly are you referring to here? Is this one of the nipype example
scripts?


On Fri, Jan 31, 2014 at 12:45 PM, Satrajit Ghosh <sa...@mit.edu> wrote:

What features does your script have? 

- it allows customizable directory layouts and naming schemes through heuristic file
- it only converts the necessary dicoms, not everything in a directory
- you can keep links to dicom files in the participant layout
- it's faster than parsesdicomdir or mri_convert if you use dcm2nii option
- it embeds all the dicom metadata inside the nifti header using dcmstack
- it tracks the provenance of the conversion from dicom to nifti in w3c prov format
- the example shows a conversion to openfmri layout structure

- soon you'll be able to add more tags to the metadata representation of the files
- and push the metadata to a provenance store


it's this gist: https://gist.github.com/satra/8701942

cheers,

satra

Reply all
Reply to author
Forward
0 new messages