Skip to content
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

DcmStack interface and EPI sequences. #1072

Closed
TheChymera opened this issue Apr 1, 2015 · 12 comments
Closed

DcmStack interface and EPI sequences. #1072

TheChymera opened this issue Apr 1, 2015 · 12 comments

Comments

@TheChymera
Copy link
Collaborator

Hi, I am using the nipype.interfaces.dcmstack wrapper to turn some of my DICOM files into NifTi. This works nicely with my anatomical sequences, but not so much with my EPIs. My code is:

from nipype.interfaces.dcmstack import DcmStack
stacker = DcmStack()
stack_directories = [
    "/home/chymera/data/export_ME/dicom/4459/1/EPI/"
    ]
for stack_directory in stack_directories:
    stacker.inputs.dicom_files = stack_directory
    result = stacker.run()
    result.outputs.out_file

And I get the following error:

Traceback (most recent call last):
  File "/home/chymera/src/RS/dcmst.py", line 8, in <module>
    result = stacker.run()
  File "/usr/lib64/python2.7/site-packages/nipype/interfaces/base.py", line 1003, in run
    runtime = self._run_interface(runtime)
  File "/usr/lib64/python2.7/site-packages/nipype/interfaces/dcmstack.py", line 136, in _run_interface
    nii = stack.to_nifti(embed_meta=True)
  File "/usr/lib64/python2.7/site-packages/dcmstack/dcmstack.py", line 857, in to_nifti
    data = self.get_data()
  File "/usr/lib64/python2.7/site-packages/dcmstack/dcmstack.py", line 763, in get_data
    stack_shape = self.get_shape()
  File "/usr/lib64/python2.7/site-packages/dcmstack/dcmstack.py", line 726, in get_shape
    raise InvalidStackError("Unable to guess key for sorting the "
dcmstack.dcmstack.InvalidStackError: The DICOM stack is not valid: Unable to guess key for sorting the fourth dimension
[Finished in 372.764s]

Any ideas what I could do? I was thinking better ask here first instead of upstream at DcmStack, since I want to keep using your wrapper, and not their cli directly. Also, is there any way to see what CLI command the wrapper translates to

Also, my seuences are multi-EPI (3echoes X 20slices X 600 volumes) - if that makes any difference.

@satra
Copy link
Member

satra commented Apr 1, 2015

just a quick first question - are these siemens dicoms?

also you may want to take a look at:

https://gist.github.com/satra/8701942/

@TheChymera
Copy link
Collaborator Author

No, these are dicoms converted from some rather strange BRUKER format. They (the DICOMS, as I also have them here) can certainly be converted to NifTi successfully with a few MATLAB scripts that float around our lab, but I'd rather use a backend that is better supported and reviewed.

I am pretty sure dcmstack should be able to do this, since it dealt with my anatomical scans from the same scanner nicely.

Also, please read my last edit regarding multi-Echo.

Wow. that is some seriously involved code. Is this what it takes to get some nice EPI conversion with dcmstack? Why didn't you add this functionality / this script to nipype?

@satra
Copy link
Member

satra commented Apr 2, 2015

@TheChymera

in this case i believe it's the grouping that it cannot do because of the multi-echo. iirc dicomstack has a way of specifying grouping variables.

re: gist - actually i rely on dcm2nii to do the conversion - across scanners and sequences, i have found it to be the most stable and accurate. then i use dcmstack to essentially embed the metadata into the nifti header. most of the convoluted part has to do with arrangement of folder structure based on the heuristic file. i'm hoping this will be completely replaced by a db in the future, but for now this works really well in our lab. i have off and on considered adding it as a workflow - mostly laziness i think.

@anbai106
Copy link
Contributor

Sorry to open this issue again, I have EPI sequence, and I have different machines( Siemens, GE, Philips), when I use dcmstack to convert these dicoms to nifti, it works well for Siemens GE(ok for DTI, phase and magnitude image), but not for Philips DTI, i got the same errors like above, do you have any suggestion???

@satra
Copy link
Member

satra commented Mar 15, 2017

@anbai106 - at this point we recommend that people use: https://github.com/nipy/heudiconv - it has the added advantage of being able to convert to a bids structure. there is even a docker image if you don't want to install things. https://hub.docker.com/r/nipy/heudiconv/

@anbai106
Copy link
Contributor

anbai106 commented Mar 15, 2017

@satra -Nice, for the converter option with dcmstack, do you have the option to write json file for the metadata, which draws me interests. But my question is that even with heudiconv, you still use the dcmstack, for Philips DTI image, do we still have this errors? I saw there is an issue in the dcmstatck github : https://github.com/moloney/dcmstack/issues/48

Any way, i will try this:)
Look forward to hear you

@satra
Copy link
Member

satra commented Mar 15, 2017

actually we will soon be replacing the converter options with just dcm2niix for now - dcmstack was targeted at siemens scans. you should use the dcm2niix converter option.

@anbai106
Copy link
Contributor

@satra -Yes I know that dcm2niix work fine for all the three machines with -b option, but content that dcm2niix created with -b option is not so complete compared dcmstack, Currently, when dealing with DWI data, we have to calculate the effective-echo-spacing and full-read-out-time, some parameters like this, what we want to do is to compute these parameters for preprocessing step(some times this is a little tricky for different machines), and rewrite these parameters into another json file in BIDS structure, So that is why I wanna use dcmstack to get more elaborate json file.

@mgxd
Copy link
Member

mgxd commented Mar 15, 2017

@anbai106 dcm2niix should calculate effective echo spacing for you. As for total readout time, this post discusses potential ways to calculate it. If you still want to use dcmstack, working with the developers may be your best bet.

@satra
Copy link
Member

satra commented Mar 15, 2017

@anbai106 - i completely understand. one of the things on the plate, but no resources at this time is to move some of the dicomstack functionality to nibabel or a standalone library:

  • python 2/3 compatible
  • reads and organizes dicoms across scanners
  • understands metadata from different scanners

@anbai106
Copy link
Contributor

@mgxd - Thanks for your reply, Finally, I think for Siemens, it is quite stable to calculate the parameters needed for preprocessing(like you showed in the post), but for Philips and GE, it is not the same, I think for Siemens, I have finished the scripts to calculate these parameters, and for dcm2niix, the json file looks like this:

{
"Manufacturer": "Philips",
"ManufacturersModelName": "Achieva",
"ProtocolName": "9df63866-b968-4c96-9028-7ef15396a5b5",
"ImageType": ["ORIGINAL", "PRIMARY", "M", "FFE", "M", "FFE"],
"AcquisitionDateTime": "2016-02-25T13:40:22.546875",
"PhilipsRescaleSlope": 1.3939,
"PhilipsRescaleIntercept": 0,
"PhilipsScaleSlope": 0.000572839,
"UsePhilipsFloatNotDisplayScaling": 1,
"MagneticFieldStrength": 3,
"FlipAngle": 60,
"EchoTime": 0.004606,
"RepetitionTime": 0.688,
"ConversionSoftware": "dcm2niix",
"ConversionSoftwareVersion": "v1.0.20170207"
}

But for Philips, the effective-echo-spacing is like this:
echo spacing in msec = 1000 * (water-fat shift (per pixel)/(water-fat shift (in Hz) * echo train length))

Which dcm2niix's json file does not give the details from DTI image, and dcmstack doest not work for Philips DTI.

I will try the dcmstack develop code to adapt them into Philips DTI image,

Thanks for your advice

good night

@satra
Copy link
Member

satra commented Mar 15, 2017

@chrisfilo - this is relevant to bids.

@mgxd mgxd closed this as completed Nov 2, 2017
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

4 participants