UNFmontreal / Dcm2Bids

Reorganising NIfTI files from dcm2niix into the Brain Imaging Data Structure
https://UNFmontreal.github.io/Dcm2Bids/
GNU General Public License v3.0
157 stars 82 forks source link

post_op #258

Closed raniaezzo closed 1 year ago

raniaezzo commented 1 year ago

I am running into a problem using the post_op method outlined in the config file as done here: https://unfmontreal.github.io/Dcm2Bids/3.0.1/how-to/use-advanced-commands/?h=deface#how-to-use-advanced-configuration

When I follow the documentation instructions and use "post_op": [{"cmd": "pydeface --outfile dst_file src_file", "datatype": "anat", "suffix": ["T1w"]}], I get an error: raise ValueError("post_op is not defined correctly." ValueError: post_op is not defined correctly.Please check the documentation.

The logic in the sidecar.py code looks for substrings "dstFile" and "srcFile" -- so I tried replacing the command with "cmd": "pydeface --outfile dstFile srcFile”, but I still get errors: traits.trait_errors.TraitError: The 'reference' trait of a FLIRTInputSpec instance must be a pathlike object or string representing an existing file, but a value of 'srcFile' <class 'str'> was specified.

It basically is not recognizing the source and destination path in either case. Any idea how to fix?

It's possible this person was running into the same problem: https://neurostars.org/t/problem-using-pydeface-in-dcm2bids-config-file/26542

arnaudbore commented 1 year ago

Thank you @raniaezzo for reporting this issue. I'll try to replicate it asap and fix it if needed.

arnaudbore commented 1 year ago

@raniaezzo can you try with the PR #260 ? I think this should fix your issue.

raniaezzo commented 1 year ago

@arnaudbore Yes, thanks. It fixed the original issue which was about getting pydeface to run. However, after it completes, the output is not actually defaced when doing it through dcm2bids function.

When I run dcm2bids, the output includes:

INFO | Running: pydeface --outfile /Users/rje257/Desktop/BIDS_testing/sub-0325/ses-01/anat/sub-0325_ses-01_run-01_T1w.nii.gz /Users/rje257/Desktop/BIDS_testing/tmp_dcm2bids/sub-0325_ses-01/032_Subject_0325_anat-T1w_20221003112735.nii.gz --verbose --debug --force . . . (it pauses and takes a while during the defacing step) . . . INFO | --- dcm2bids end ---

But the output /Users/rje257/Desktop/BIDS_testing/sub-0325/ses-01/anat/sub-0325_ses-01_run-01_T1w.nii.gz is NOT defaced.

I copied the output file back into the tmp directory and re-ran the pydeface command directly (not through dcm2bids), and the defacing works.

arnaudbore commented 1 year ago

I fixed the issue I think you are referring. Can you check you test the PR with the latest commit.


commit 2dc01db96bcbd505ef6559e6ebffb877990582f0 (HEAD -> fix_post_op, origin/fix_post_op)
Author: Arnaud Bore <arnaud.bore@gmail.com>
Date:   Mon Sep 11 17:14:15 2023 -0400

    change cp to shutil copy
raniaezzo commented 1 year ago

Yes, that worked. Thanks!

arnaudbore commented 1 year ago

Perfect, everything you see in this PR will be in the next release end of this week I think.