Skip to content

dcmstack output file path #1087

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

Closed
TheChymera opened this issue Apr 20, 2015 · 18 comments
Closed

dcmstack output file path #1087

TheChymera opened this issue Apr 20, 2015 · 18 comments

Comments

@TheChymera
Copy link
Collaborator

Hello, I am trying to specify an ouput file path for the nipype.interfaces.dcmstack.DcmStack interface, which should be in my data hierarchy and not in my script hierarchy.

I am doing this ~via:

from nipype.interfaces.dcmstack import DcmStack
stacker = DcmStack()
stacker.inputs.out_format = "/path/to/my/data"

stubbornly, dcmstack will export the resulting file to /path/to/my/script/_path_to_my_data

Can we fix this somehow? Right now I hav to export to my script directory and then move the file -.- which is a dodgy and slow way to fix this (different hard drives etc).

@oesteban
Copy link
Contributor

Right now, I guess that's not possible:

return path.join(os.getcwd(), out_fn)

A nice solution to the problem could be adding a bool switch to NiftiGeneratorBaseInputSpec indicating if the path is absolute or relative. Then, modify the line I've pointed out to choose between op.join or op.abspath.

@TheChymera
Copy link
Collaborator Author

and how would that switch get triggered?

@oesteban
Copy link
Contributor

@TheChymera I have written a fast patch, let me know if it works out for you. I'm not 100% sure this will work, but you'll need to check it out from my branch:

git remote add oesteban [email protected]:oesteban/nipype.git
git remote update
git pull oesteban fix/DCMStackOutput-1087

PS. When you use the interface, make sure you set the input use_cwd=False

@TheChymera
Copy link
Collaborator Author

Do I need to test this before the pull gets accepted? I am running the live nipype version, but setting up a development installation that works nicely with my package manager might take a while :-/

@TheChymera
Copy link
Collaborator Author

@oesteban how do I use this feature?

I installed the live version of nipype, and still stuff gets exported to /path/to/my/script/_path_to_my_data.

I guess I have t speify the destination via somethign other than stacker.inputs.out_format - but what?

@satra
Copy link
Member

satra commented Apr 22, 2015

try use_cwd = False for that interface

@TheChymera
Copy link
Collaborator Author

@satra so:

stacker.inputs.out_format = "/path/to/my/data"
stacker.inputs.use_cwd = False

?

@satra
Copy link
Member

satra commented Apr 22, 2015

yes

@TheChymera
Copy link
Collaborator Author

@satra tried it - that still exports the file to /path/to/my/script/_path_to_my_data

@satra
Copy link
Member

satra commented Apr 22, 2015

i looked at the code, and it looks like it's doing the correct thing. can you insert a debug breakpoint and step through.

@TheChymera
Copy link
Collaborator Author

uhm, how do I do that? Can you maybe test this at your end as well?

I am just running the interface as:

            stacker.inputs.dicom_files = my_files_list
            stacker.inputs.embed_meta = True
            file_name = "EPIwhatever"
            stacker.inputs.out_format = /path/to/my/file
            stacker.inputs.use_cwd = False
            result = stacker.run()
            print(result.outputs.out_file)

And that prints /path/to/my/script/path_to_my_file, and puts the file there, as opposed to under the /path/to/my/file directory. By the way, how would the interface deal with an inexistent output path (i.e. one where some directories would need to be created) ?

@oesteban oesteban reopened this Apr 23, 2015
@oesteban
Copy link
Contributor

ok, I see. There is also this function

def sanitize_path_comp(path_comp):
converting slashes to underscores. @satra, what do you think of adding an out_path input that is cwd by default?

oesteban added a commit to oesteban/nipype that referenced this issue Apr 23, 2015
@oesteban
Copy link
Contributor

@TheChymera now you can do (provided you checkout my branch):

stacker.inputs.dicom_files = my_files_list
stacker.inputs.embed_meta = True
file_name = "EPIwhatever"
stacker.inputs.out_path = '/path/to/my'
stacker.inputs.out_format = 'file'
result = stacker.run()
print(result.outputs.out_file)

@satra
Copy link
Member

satra commented Apr 23, 2015

[OT] @oesteban - i think it would be good to start building a set of regression tests with actual data using Testkraut. i know we have stayed away from regression tests because of data and software requirements, but i think it would be good to start adding these test specs.

@oesteban
Copy link
Contributor

@satra I've taken a glimpse on the testkraut project and it looks awesome. Very appropriate for nipype :)

@TheChymera
Copy link
Collaborator Author

@oesteban sadly, I have still not set up any ebuilds for different live sources than the main branch on the main tree. I believe I will not do so soon, actually. I hope you can pull this here within the next few days.

@oesteban
Copy link
Contributor

I'm to merge this then. I've done the following:

import glob
from nipype.interfaces.dcmstack import DcmStack
s = DcmStack()
s.inputs.out_path = '/home/oesteban/tmp/very/long/nonexistent/path'
s.inputs.out_format = 'file'
s.inputs.embed_meta = True
s.inputs.dicom_files = glob.glob('../T1_1/MR.0003.0*.IMA')
res = s.run()

Then, print res.outputs yields:

out_file = /home/oesteban/tmp/very/long/nonexistent/path/file.nii.gz

oesteban added a commit to oesteban/nipype that referenced this issue Apr 24, 2015
@TheChymera
Copy link
Collaborator Author

Looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants