nipreps / fmriprep

fMRIPrep is a robust and easy-to-use pipeline for preprocessing of diverse fMRI data. The transparent workflow dispenses of manual intervention, thereby ensuring the reproducibility of the results.
https://fmriprep.org
Apache License 2.0
638 stars 294 forks source link

PhaseEncodingDirection of EPI #2553

Open Avijit-Chowdhury1 opened 3 years ago

Avijit-Chowdhury1 commented 3 years ago

I am trying to run preprocessing of some 7T data with fieldmap distortion correction. The data was collected in sagittal slices. Data acquisition sequence is : Saggital > Coronal > Transversal Sagittal R >> L Coronal A >> P Transversal F >> H

I am using dicm2niix to convert my dicoms to NIFTI. In the .json file, I am getting the PhaseEncodingDirection for my functional scan as “i”. In saggital slices, "i" should be A>P direction.

However, in the fmriprep output HTML, I see that the phase-encoding direction of the EPI is specified as ""LEFT-RIGHT". Because of this the fieldmap distortion correction is also being applied in the LEFT-RIGHT direction.

Is this an error with fmriprep? I have tried changing the phase encoding direction in the .json file to "j" and fmriprep detects the direction to be Anterior-Posterior as expected.

effigies commented 3 years ago

Can you provide the fslhd (or header readout from any tool, really) of your file?

Avijit-Chowdhury1 commented 3 years ago

sizeof_hdr 348 data_type INT16 dim0 4 dim1 162 dim2 218 dim3 126 dim4 250 dim5 1 dim6 1 dim7 1 vox_units mm time_units s datatype 4 nbyper 2 bitpix 16 pixdim0 0.000000 pixdim1 1.100917 pixdim2 1.100917 pixdim3 1.100000 pixdim4 2.690000 pixdim5 0.000000 pixdim6 0.000000 pixdim7 0.000000 vox_offset 352 cal_max 0.0000 cal_min 0.0000 scl_slope 1.000000 scl_inter 0.000000 phase_dim 1 freq_dim 2 slice_dim 3 slice_name Unknown slice_code 0 slice_start 0 slice_end 0 slice_duration 0.000000 time_offset 0.000000 intent Unknown intent_code 0 intent_name intent_p1 0.000000 intent_p2 0.000000 intent_p3 0.000000 qform_name Scanner Anat qform_code 1 qto_xyz:1 0.000000 0.000000 -1.100000 68.750000 qto_xyz:2 -1.100917 0.000000 0.000000 97.043587 qto_xyz:3 0.000000 1.100917 0.000000 -135.242950 qto_xyz:4 0.000000 0.000000 0.000000 1.000000 qform_xorient Anterior-to-Posterior qform_yorient Inferior-to-Superior qform_zorient Right-to-Left sform_name Scanner Anat sform_code 1 sto_xyz:1 0.000000 0.000000 -1.100000 68.750000 sto_xyz:2 -1.100917 0.000000 0.000000 97.043587 sto_xyz:3 0.000000 1.100917 0.000000 -135.242950 sto_xyz:4 0.000000 0.000000 0.000000 1.000000 sform_xorient Anterior-to-Posterior sform_yorient Inferior-to-Superior sform_zorient Right-to-Left file_type NIFTI-1+ file_code 1 descrip TE=29;Time=115439.485;phase=1;mb=3 aux_file

Avijit-Chowdhury1 commented 3 years ago

Can you provide the fslhd (or header readout from any tool, really) of your file?

Here you go, thanks

effigies commented 3 years ago

So your orientation is PSL, so "i" is A->P, so the inputs look good. When we report it, we use the function get_world_pedir:

https://github.com/nipreps/fmriprep/blob/4961a56fa61884304c477403c68d7608e29efb33/fmriprep/interfaces/reports.py#L277-L298

Which seems to give the right result:

>>> from fmriprep.interfaces.reports import get_world_pedir
>>> get_world_pedir("PSL", "i")
'Anterior-Posterior'

So it seems we must be either providing an incorrect orientation or reorienting your input file without adjusting the PhaseEncodingDirection to match.

effigies commented 3 years ago

Do you have single-band reference images that are in a different orientation to your BOLD?

Avijit-Chowdhury1 commented 3 years ago

Do you have single-band reference images that are in a different orientation to your BOLD?

No, I do not have any single-band reference files in my folder.

Interestingly, when I used the different phase-encoded fieldmaps (AP / AP), the fieldmap correction seems to work in the right direction (even though the HTML reports the PhaseEncodingDirection as L-R). When I use the Phase-Magnitude pair fieldmap, however, distortion correction is applied in the L-R direction.

Of note, when I use FSL, I do have to input unwarpdir= x- in FUGUE to get distortion correction in the AP direction.

effigies commented 3 years ago

Is there any chance you could provide a minimal dataset that reproduces? e.g., One subject, with one T1w and one BOLD image, and whatever necessary fieldmap data?

Avijit-Chowdhury1 commented 3 years ago

Is there any chance you could provide a minimal dataset that reproduces? e.g., One subject, with one T1w and one BOLD image, and whatever necessary fieldmap data?

Of course, here you go: https://www.dropbox.com/sh/ardkp6myddlgt8c/AAAuKb7TWkLaWc0d6NMGIgpMa?dl=0 Please note, this only has the Phase-magnitude pair fieldmap. Thanks a lot.

effigies commented 3 years ago

Please note, this only has the Phase-magnitude pair fieldmap.

Thanks. That should be enough to reproduce the issues you've described.

effigies commented 3 years ago

@Avijit-Chowdhury1 When I run fMRIPrep 21.0.0rc0 on the data you provided, I see the following functional summary:

Summary
  • Original orientation: PSL
  • Repetition time (TR): 2.69s
  • Phase-encoding (PE) direction: Anterior-Posterior
  • Single-echo EPI sequence.
  • Slice timing correction: Applied
  • Susceptibility distortion correction: FMB (fieldmap-based) - phase-difference map
  • Registration: FSL flirt with boundary-based registration (BBR) metric - 6 dof
  • Non-steady-state volumes: 0

And looking at the report, the SDC occurs in the A/P direction. Could you verify you were using a new working directory, and share your command and version?

Avijit-Chowdhury1 commented 3 years ago

Hi, it might have something to do with my fmriprep version. When I run

python -m pip install --user --upgrade fmriprep-docker

the version installed is fmriprep-docker-20.2.3. How do I install the latest version?

effigies commented 3 years ago

Add the --pre flag to get the release candidate.

Avijit-Chowdhury1 commented 3 years ago

crash-20210922-194243-root-ds_t1w_ref_xfms-997633b9-e43b-4a3c-9230-722ced4e4686.txt

I get the following error when trying to run fMRIPrep 21.0.0rc0

effigies commented 3 years ago

Is that a reliable error? It looks like a filesystem issue, which are often pretty stochastic.

Avijit-Chowdhury1 commented 3 years ago

Is that a reliable error? It looks like a filesystem issue, which is often pretty stochastic.

I tried again and it works now. The distortion correction is also being applied in the correct direction. Guess this is an issue with the older version of fmriprep?

Also a follow-up question: If I put both types of fieldmaps in my BIDS folder (opposite phase-encoded EPI and Phase-magnitude pair), will the distortion correction be done twice?

effigies commented 3 years ago

I tried again and it works now. The distortion correction is also being applied in the correct direction. Guess this is an issue with the older version of fmriprep?

Probably. 21.0.0 saw a complete overhaul of SDC correction.

If I put both types of fieldmaps in my BIDS folder (opposite phase-encoded EPI and Phase-magnitude pair), will the distortion correction be done twice?

No. If IntendedFor is set for both, then phase difference fieldmaps will take priority over PE-polar. If you want to choose among them, the easier thing would be to move to B0FieldIdentifier/B0FieldSource, so that you're changing the metadata on the BOLD files rather than on the fieldmaps.

Avijit-Chowdhury1 commented 3 years ago

I tried again and it works now. The distortion correction is also being applied in the correct direction. Guess this is an issue with the older version of fmriprep?

Probably. 21.0.0 saw a complete overhaul of SDC correction.

If I put both types of fieldmaps in my BIDS folder (opposite phase-encoded EPI and Phase-magnitude pair), will the distortion correction be done twice?

No. If IntendedFor is set for both, then phase difference fieldmaps will take priority over PE-polar. If you want to choose among them, the easier thing would be to move to B0FieldIdentifier/B0FieldSource, so that you're changing the metadata on the BOLD files rather than on the fieldmaps.

https://fmriprep.org/en/1.0.1/api/index.html#sdc-base . this link says PE-polar will take priority over phase-diff fieldmaps.

effigies commented 3 years ago

The order of priority has changed in 21.0. Unfortunately, I'm not finding up-to-date documentation. I'll make an issue for that.