NewSegment and Workflows

53 views
Skip to first unread message

Helmet Karim

unread,
Jul 21, 2014, 2:29:37 PM7/21/14
to nipy...@googlegroups.com
Hi all,

I am creating a pipeline that uses NewSegment. One of NewSegment's outputs is called "modulated_class_images" which is described by the manual/MIT website as "(a list of items which are a list of items which are an existing file name)." I am trying to connect these files into another process. For simplicity, let's say that I wanted to 'reslice' these files in pipeline. I have already defined the NewSegment options properly and have created an object called 'seg' as well as another job we will call 'reslice.' I have:

preprocessing = pe.Workflow(name='preprocessing')

preprocessing.base_dir = '/path/2/studydirectory/'

preprocessing.connect(seg,'modulated_class_images',reslice2ref_all,'in_files')


So, it does not report any errors when I make this connection and will run through the entire analysis up to NewSegment. The problem arises when the modulated class images are fed into in_files. See, normally the outputs of segment or most other processes are 'an existing filename.' The problem here is that this is a list of items which contains existing file names. The workflow does not know how to access this.


The strange thing is that if you use spm SliceTimeCorrection, the output file there is "(a list of items which are an existing file name or an existing file name)." I have seen this run flawlessly for 3D data (which means its output would be a list of existing filenames), which means that the workflow can handle lists of filenames. 


The error that I receive is:

Each element of the 'in_files' trait of a ResliceToReferenceInput instance must be an existing file name, but a value of [] <type 'list'> was specified.


So, my question is: How do I get around this issue? Do I have to wait until the NewSegment job is completed and run it outside the pipeline (which completely defeats the purpose of working inside the workflow)? Or is there some way to tell the workflow that I am specifying a list? Or is the problem because it is a "list of items which are a list of items which are an existing file name"--which means it's a list of a list of existing filenames? 


Thank you,

--Helmet Karim



Satrajit Ghosh

unread,
Jul 21, 2014, 2:44:29 PM7/21/14
to nipy-user
hi helmet,

you can make the reslice2ref node a MapNode and give it as iterfield 'in_files'. the error suggests that the interface requires a single file. as a MapNode it will take a list process each one and output a list.

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/d/optout.

Helmet Karim

unread,
Jul 21, 2014, 3:38:51 PM7/21/14
to nipy...@googlegroups.com
Satra, 

Thank you for your response. I may have made an error, but it did not work. I redefined the object to define the reslice object as:

reslice = pe.MapNode(spm.utils.ResliceToReference(),'in_file', 'reslice')


where 'in_file' was iterable field. Later, in the pipeline I connected them with:


preprocessing.connect(seg,'modulated_class_images',reslice,'in_files')


This results in the same error that I received earlier. Not sure why. I really thought that that would work. Have I made a mistake here?


Thanks,

--Helmet

Satrajit Ghosh

unread,
Jul 21, 2014, 4:32:15 PM7/21/14
to nipy-user
hi helmet,

can you try:

reslice = pe.MapNode(spm.utils.ResliceToReference(), iterfield=['in_file'], name='reslice')

cheers,

satra

Helmet Karim

unread,
Jul 21, 2014, 4:55:32 PM7/21/14
to nipy...@googlegroups.com
Satra,

So the issue from the last question was actually because it needed to be 'in_files' with an 's' and not 'in_file', i.e.:

reslice = pe.MapNode(spm.utils.ResliceToReference(),'in_files', 'reslice')

This however does not fix the problem. Just generates a different error:

Subnode 0 failed
Error: ResliceToReference requires a value for input 'in_files'. For a list of required inputs, see ResliceToReference.help()

The problem is that the in_files were defined at the connect stage. Is it possible that MapNode is not compatible? Also, having realized that the reslice name is 'in_files' and not 'in_file' -- doesn't this mean that reslice should be able to accept a list of files and not just a single file? I actually tested this and it seemed like reslice takes multiple files. So maybe this was not the issue?

Now I am very confused as to what the actual issue might be here. 

Thanks,
--Helmet




On Monday, July 21, 2014 2:29:37 PM UTC-4, Helmet Karim wrote:

Satrajit Ghosh

unread,
Jul 21, 2014, 5:08:48 PM7/21/14
to nipy-user
hi helmet,

it's possible that newsegment is not generating that specific output. can you check the _report folder in that node's working directory. the report.rst file will tell you which outputs were produced.

if the files are not being generated, it might have to do with which tissues were generated. see the example here:


cheers,

satra


Helmet Karim

unread,
Jul 22, 2014, 1:27:09 PM7/22/14
to nipy...@googlegroups.com

Satra,


So I resolved the issue. So when I was defining NewSegment I was doing the following:

from nipype import spm

import nipype.pipeline.engine as pe


seg = pe.Node(interface = spm.NewSegment(),name = 'NewSegment')

seg.inputs.channel_info = (0.0001, 60, (True, True))

seg.inputs.warping_regularization = 4

seg.inputs.sampling_distance = 3

tissue1 = ((TPMfile, 1), 2, (True,True), (True, False))

tissue2 = ((TPMfile, 2), 2, (True,True), (True, False))

tissue3 = ((TPMfile, 3), 2, (True,True), (True, False))

tissue4 = ((TPMfile, 4), 3, (False,False), (True, False))

tissue5 = ((TPMfile, 5), 4, (False,False), (True, False))

tissue6 = ((TPMfile, 6), 2, (False,False), (True, False))

seg.inputs.write_deformation_fields = [False,True]

seg.inputs.affine_regularization = 'mni'

seg.inputs.tissues = [tissue1, tissue2, tissue3, tissue4, tissue5,tissue6]


When I ran this, I noticed that it would output the unmodulated normalized files but NOT the modulated files. So I decided to change the tissue types such that they all had 'True' instead of 'False' at the very end {i.e. tissue1 = ((TPMfile, 1), 2, (True,True), (True, True)) }. This output the modulated and unmodulated. When I switched it to  (False,True) for the last tuple in tissue, it only output the modulated files. So the problem was that the documentation says the opposite.  The manual says that the last tuple be "- which maps to save [Modulated, Unmodualted] - a tuple of two" but it should actually be unmodulated then modulated. Please test this and fix the typo in the manual. You were right though that it was NOT outputting the modulated files because I was mistakenly outputting only the unmodulated. 


Thanks again for your help,

--Helmet

Reply all
Reply to author
Forward
0 new messages