Dwifslpreproc mrconvert: [ERROR] Phase-encoding matrix requires 4 columns to convert to eddy format

Dear experts,

I am sorry for all the questions. I have several datasets processing different things so different errors are occurring simultaneously.

I am analyzing the NKI dataset at the moment and running into errors with dwifslpreproc.

my commands:

######## COMMANDS ########
echo "Converting NIFTI to mif"
time mrconvert -json_import ${rawDTI_dir}/sub-A000${subject}_ses-BAS1_dwi.json -fslgrad ${rawDTI_dir}/sub-A000${subject}_ses-BAS1_dwi.bvec ${rawDTI_dir}/sub-A000${subject}_ses-BAS1_dwi.bval ${rawDTI_dir}/sub-A000${subject}_ses-BAS1_dwi.nii.gz ${dir_out}/preprocessed/dwi_${subject}.mif

echo "Denoising and Unringing"
time dwidenoise ${dir_out}/preprocessed/dwi_${subject}.mif ${dir_out}/preprocessed/dwi_${subject}_denoised.mif
time mrdegibbs ${dir_out}/preprocessed/dwi_${subject}_denoised.mif ${dir_out}/preprocessed/dwi_${subject}_denoised_unringed.mif #-axes list, select the slice axes (default: 0,1 - i.e. x-y).

echo "Eddy correction"
time dwifslpreproc ${dir_out}/preprocessed/dwi_${subject}_denoised_unringed.mif ${dir_out}/preprocessed/dwi_${subject}_denoised_unringed_eddy.mif -scratch /ifs/loni/groups/matherlab/shai/NKI/Scripts/tmpDIR/ -nocleanup -rpe_header -eddy_options " --slm=linear --data_is_shelled"

the error:

dwifslpreproc: Changing to scratch directory (/path/tmpDIR/dwifslpreproc-tmp-FQ9DVO/)
Command:  mrconvert dwi.mif - | dwiextract - se_epi.mif -bzero
dwifslpreproc: [WARNING] DWI header indicates no phase encoding contrast between b=0 images; proceeding without inhomogeneity field estimation
Function: posix.remove('se_epi.mif')
Command:  mrinfo dwi.mif -export_grad_mrtrix grad.b
Command:  dwi2mask dwi.mif - | maskfilter - dilate - | mrconvert - eddy_mask.nii -datatype float32 -strides -1,+2,+3
Command:  mrconvert dwi.mif eddy_in.nii -strides -1,+2,+3,+4 -export_grad_fsl bvecs bvals -export_pe_eddy eddy_config.txt eddy_indices.txt

dwifslpreproc: [ERROR] mrconvert dwi.mif eddy_in.nii -strides -1,+2,+3,+4 -export_grad_fsl bvecs bvals -export_pe_eddy eddy_config.txt eddy_indices.txt (dwifslpreproc:898)
dwifslpreproc: [ERROR] Information from failed command:
dwifslpreproc:
               mrconvert: [ERROR] Phase-encoding matrix requires 4 columns to convert to eddy format

I am not sure why this keeps happening, as this step has not been an issue with other datasets.

In the tmpDir, I see:

-bash-4.1$ mrinfo dwi.mif
************************************************
Image name:          "dwi.mif"
************************************************
  Dimensions:        106 x 90 x 64 x 137
  Voxel size:        2 x 2 x 2 x 2.4
  Data strides:      [ -1 2 3 4 ]
  Format:            MRtrix
  Data type:         32 bit float (little endian)
  Intensity scaling: offset = 0, multiplier = 1
  Transform:                    1           0          -0        -104
                                0           1          -0      -81.42
                               -0           0           1      -51.81
  ConversionSoftware: dcm2niix
  ConversionSoftwareVersion: v1.0.20170411 GCC4.3.2
  EchoTime:          0.0850000009
  EffectiveEchoSpacing: 0.000690002984
  FlipAngle:         90
  ImageType:         ORIGINAL
  [6 entries]        PRIMARY
                     ...
                     ND
                     MOSAIC
  MagneticFieldStrength: 3
  Manufacturer:      Siemens
  ManufacturersModelName: TrioTim
  PhaseEncodingDirection: j-
  ProcedureStepDescription: RESEARCH_colcombe
  ProtocolName:      DIFF_137_AP
  RepetitionTime:    2.4000001
  ScanningSequence:  EP
  SequenceName:      ep_b5
  SequenceVariant:   SK_MTC
  SeriesDescription: DIFF_137_AP
  command_history:   mrconvert -json_import /path/sub-x_ses-BAS1_dwi.json -fslgrad path//sub-x_ses-BAS1_dwi.bvec /path//sub-x_ses-BAS1_dwi.bval /path//sub-x_ses-BAS1_dwi.nii.gz /path/dwi_x.mif  (version=3.0.2)
                     dwidenoise /path/dwi_x.mif /path/dwi_x_denoised.mif  (version=3.0.2)
                     mrdegibbs /path/dwi_x_denoised.mif /path//dwi_x_denoised_unringed.mif  (version=3.0.2)
                     path/mrtrix3_fsl/bin/mrconvert /path/dwi_x_denoised_unringed.mif /path/dwi.mif -json_export /path/dwifslpreproc-tmp-7FX0MA/dwi.json  (version=3.0.2)
  comments:          TE=85;Time=101833.648;phase=1;dwell=0.690
  dw_scheme:         0.5773502692,-0.5773502692,0.5773502692,5
  [137 entries]      -0.9999964445,0,0.002666641185,1500
                     ...
                     -0.3654368189,0.1927519045,-0.9106605486,1495
                     -0.2564740874,-0.8533932908,0.4538071547,1505
-bash-4.1$ mrinfo eddy_in.nii
************************************************
Image name:          "eddy_in.nii"
************************************************
  Dimensions:        106 x 90 x 64 x 137
  Voxel size:        2 x 2 x 2 x 2.4
  Data strides:      [ -1 2 3 4 ]
  Format:            NIfTI-1.1
  Data type:         32 bit float (little endian)
  Intensity scaling: offset = 0, multiplier = 1
  Transform:                    1           0          -0        -104
                                0           1          -0      -81.42
                               -0           0           1      -51.81
  comments:          TE=85;Time=101833
  mrtrix_version:    3.0.2

Thanks in advance.

this looks to be a specific error with a few subject.

Ok, any chance you could post the contents of the eddy_config.txt file in the temporary folder?

It looks like the ones that error out don’t have any eddy_config.txt files. A random subject that did not error has the output: 0 -1 0 0.0614

OK, sorry, that makes sense since the command that failed was the one that was supposed to generate that file… :grimacing:

If you run mrinfo on your input DWI file, can you see any difference in the how the PE information is represented between the subjects that work and those that don’t…? I note the information for the DWI inside the temporary folder is simply:

  PhaseEncodingDirection: j-

What does this look like for the other subjects? Maybe they have a much more extensive set of pe_scheme entries instead…?

The phase encoding is the same, I notice the data type is 16 bit integer not 32 bit float. Could that be the issue?

************************************************
Image name:          "dwi.mif"
************************************************
  Dimensions:        106 x 90 x 64 x 137
  Voxel size:        2 x 2 x 2 x 2.4
  Data strides:      [ -1 2 3 4 ]
  Format:            MRtrix
  Data type:         signed 16 bit integer (little endian)
  Intensity scaling: offset = 0, multiplier = 1
  Transform:                    1           0          -0        -104
                                0           1          -0         -63
                               -0           0           1      -22.71
  AcquisitionMatrixPE: 90
  AcquisitionNumber: 1
  AcquisitionTime:   11:08:40.695000
  BandwidthPerPixelPhaseEncode: 16.1030006
  BaseResolution:    106
  ConversionSoftware: dcm2niix
  ConversionSoftwareVersion: v1.0.20180403 GCC5.4.0
  DerivedVendorReportedEchoSpacing: 0.000690002984
  DeviceSerialNumber: 35390
  DwellTime:         2.60000002e-06
  EchoTime:          0.0869999975
  EffectiveEchoSpacing: 0.000690002984
  FlipAngle:         90
  ImageComments:     Unaliased_MB4_PE3_LB
  ImageOrientationPatientDICOM: 1,0,0,0,1,0
  ImageType:         ORIGINAL
  [7 entries]        PRIMARY
                     ...
                     ND
                     MOSAIC
  InPlanePhaseEncodingDirectionDICOM: COL
  InstitutionAddress: Old_Orangeburg_Road_140_Orangeburg_NY_US_10962
  InstitutionName:   Nathan_Kline_Institute_for_Psychiatric_Research
  InstitutionalDepartmentName: Department
  MRAcquisitionType: 2D
  MagneticFieldStrength: 3
  Manufacturer:      Siemens
  ManufacturersModelName: TrioTim
  Modality:          MR
  MultibandAccelerationFactor: 4
  PartialFourier:    0.75
  PatientPosition:   HFS
  PercentPhaseFOV:   84.9057007
  PhaseEncodingDirection: j-
  PhaseEncodingSteps: 68
  PhaseResolution:   1
  PixelBandwidth:    1814
  ProcedureStepDescription: RESEARCH_colcombe
  ProtocolName:      DIFF_137_AP
  PulseSequenceDetails: %CustomerSeq%_cmrr_mbep2d_diff
  ReceiveCoilName:   32Ch_Head
  ReconMatrixPE:     90
  RepetitionTime:    2.4000001
  SAR:               0.475284994
  ScanOptions:       PFP_MT_FS
  ScanningSequence:  EP
  SequenceName:      ep_b0
  SequenceVariant:   SK_MTC_SS
  SeriesDescription: DIFF_137_AP
  SeriesNumber:      10
  ShimSetting:       -2449,-459,20900,838,-87,380,392,7
  SliceThickness:    2
  SoftwareVersions:  syngo_MR_B17
  SpacingBetweenSlices: 2
  StationName:       MRC35390
  TotalReadoutTime:  0.0614
  TxRefAmp:          306.325012
   (version=3.0.2)
  comments:          TE=87;Time=110840.695;phase=1;mb=4
  dw_scheme:         0,0,0,0
  [137 entries]      -0.9999991111,0,0.001333330148,1500
                     ...
                     -0.364946066,0.1931020349,-0.9107831647,1495
                     -0.2566760125,-0.8537650417,0.4529930221,1500
  mrtrix_version:    3.0.2

OK, I had a quick chat with @rsmith about this, the issue is that the problematic dataset doesn’t have a TotalReadoutTime entry for some reason. This is the information that constitutes the 4th column of the PE matrix – hence the error message.

The right way for us to handle this would be to insert some sensible default value in there if that entry is missing, but it’ll take us a while to find the time. A quicker fix for you would be to manually insert that information into your input DWI by adding it to the original JSON file (which I note is used in the initial mrconvert call). Alternatively, you can manually insert that entry during the mrconvert call using the -set_property TotalReadoutTime 0.0614 option (to match what’s in your other header). It doesn’t actually matter what that value is since your call won’t be calling topup (only one PE direction present in the data, so no scope for distortion correction here).

As to why this information is present for all other subjects, but not that one…? Not a clue, sorry… :man_shrugging: