Error while running dwifslpreproc

Dear MRtrix experts,

I was trying to preprocess my data which consists of:
(1) 109 DWIs in PA direction with 9 b0 volumes intersected
(2) 5 b0 volumes in AP direction

After denoising and unringing both files separately, I tried to do the preprocessing by running:
dwifslpreproc dwi_PA_den_unr.mif dwi_PA_preproc.mif -rpe_header -se_epi nodif_AP_den_unr.mif -fslgrad bvec.txt bval.txt -eddy_options " --slm=linear --data_is_shelled"

But here comes the error message saying:
mrinfo: [WARNING] The following image volumes were not successfully assigned to a b-value shell:
mrinfo: [WARNING] 105 (1838.6958540000001), 106 (1362.0913459999999)
dwifslpreproc: [ERROR] Unhandled Python exception:
dwifslpreproc: [ERROR] AssertionError:
dwifslpreproc: [ERROR] Traceback:
dwifslpreproc: [ERROR] /usr/local/bin/dwifslpreproc:328 (in execute())
dwifslpreproc: [ERROR] assert all(index >= 0 for index in vol2shell)

I’ve checked the number of volumes and number of fields in bval and bvec files and they seem to be fine. I wonder how I can fix this problem and also if there is a better way to preprocess this kind of data.
Thank you!

Amelia

This is the key error message: there are two volumes with b-values that don’t seem to match any shell in the data. You can have a closer look with:

dirstat dwi_PA_den_unr.mif

and

mrinfo -dwgrad dwi_PA_den_unr.mif

If you can copy/paste the output of both of these commands here, we might be able to provide some hints as to how to address the issue.

Thank you for your reply!

Error messages are the same if the above commands are entered:

[ERROR] no valid diffusion gradient table found
[ERROR] error importing diffusion gradient table for image “dwi_PA_den_unr.mif”

If I add -fslgrad bvec.txt bval.txt to both commands:

dirstat dwi_PA_den_unr.mif -fslgrad bvec.txt bval.txt

dirstat: [WARNING] The following image volumes were not successfully assigned to a b-value shell:
dirstat: [WARNING] 105 (1838.6958536643704), 106 (1362.0913460553527)

dwi_PA_den_unr.mif (b=0) [ 9 volumes ]

dwi_PA_den_unr.mif (b=299.29462252602724) [ 8 directions ]

Bipolar electrostatic repulsion model:
nearest-neighbour angles: mean = 37.8142, range [ 9.27132 - 50.9771 ]
energy: total = 49.3987, mean = 12.3497, range [ 10.8088 - 16.2863 ]

Unipolar electrostatic repulsion model:
nearest-neighbour angles: mean = 42.8088, range [ 9.27132 - 67.5727 ]
energy: total = 25.6223, mean = 6.40557, range [ 4.79296 - 10.6733 ]

Spherical Harmonic fit:
condition numbers for lmax = 2 → 2: [ 1.73244 ]

Asymmetry of sampling:
norm of mean direction vector = 0.120899
WARNING: sampling is moderately asymmetric - this may affect resiliance to eddy-current distortions

dwi_PA_den_unr.mif (b=997.53886247146158) [ 28 directions ]

Bipolar electrostatic repulsion model:
nearest-neighbour angles: mean = 23.0871, range [ 10.5554 - 28.3576 ]
energy: total = 667.431, mean = 47.6736, range [ 45.5905 - 51.216 ]

Unipolar electrostatic repulsion model:
nearest-neighbour angles: mean = 26.1677, range [ 20.5421 - 41.1177 ]
energy: total = 355.819, mean = 25.4156, range [ 19.2553 - 30.6029 ]

Spherical Harmonic fit:
condition numbers for lmax = 2 → 6: [ 1.1957 1.49401 13.7412 ]

Asymmetry of sampling:
norm of mean direction vector = 0.369708
WARNING: sampling is moderately asymmetric - this may affect resiliance to eddy-current distortions

dwi_PA_den_unr.mif (b=2000.0000032121188) [ 62 directions ]

Bipolar electrostatic repulsion model:
nearest-neighbour angles: mean = 15.7643, range [ 12.7401 - 19.2941 ]
energy: total = 3459.76, mean = 111.605, range [ 109.694 - 114.286 ]

Unipolar electrostatic repulsion model:
nearest-neighbour angles: mean = 17.5853, range [ 13.9162 - 24.987 ]
energy: total = 1709.12, mean = 55.1329, range [ 50.2279 - 61.7386 ]

Spherical Harmonic fit:
condition numbers for lmax = 2 → 8: [ 1.06139 1.18397 1.36185 2.16956 ]

Asymmetry of sampling:
norm of mean direction vector = 0.0720096

and

mrinfo -dwgrad dwi_PA_den_unr.mif -fslgrad bvec.txt bval.txt

0 0 0 0
0 0 0 0
-0.652649542612188 0.71530647902281 -0.249770325691607 2000.0002291448
0.37339030821588 0.00771626913651343 -0.927642246192498 1000.00022380936
-0.65965264382114 -0.700210037130223 -0.273064632279377 1999.99967363952
-0.425115027170809 -0.204376747870102 0.881763777098834 1999.99965025177
-0.930645009297076 0.00860338962371999 -0.36582215400031 1000.0000874725
-0.234356096166635 0.70283500852363 0.671639911696085 2000.00040678892
0.562695919950539 -0.0771081699932221 0.823059919927652 2000.0000003516
0.168079121305228 0.9386990297436 -0.30098760861485 300.000102433096
0.972411807261569 0.0366927098966688 -0.230366929351259 2000.00001126449
0.0150288922672603 -0.999084030721927 -0.0400653460442625 999.999698279802
-0.146507156998894 -0.870317262767685 0.470195188274684 2000.00035496168
0.231357682639846 0.412363943410551 0.881152427709542 2000.00064592897
-0.737717251888076 -0.596050365366183 0.317012962216917 1000.00004910262
0.766236240050363 -0.537484043020728 -0.352126295427613 2000.00005194031
0.105095904498045 0.985241785914717 0.135105418637877 1999.99944819755
0 0 0 0
-0.390458947250548 0.55722431472121 -0.732832090997298 1000.00027019207
-0.149478633302755 0.507315377270226 -0.848697381974935 2000.00017921613
0.93343650179064 0.141095858759094 0.329830647099215 2000.00003517908
-0.190518158492642 -0.631276311274824 -0.751793222972796 999.999805870045
0.703635679068718 0.549998871455532 -0.449886733010817 2000.00006214172
0.521505173878429 -0.276232026757512 -0.807296860523727 2000.0000469531
-0.965469559090954 0.254645733384911 0.0549916442523777 300.000062710865
0.371720201726911 -0.92701544924519 -0.0496633515667637 1999.99987380927
0.783060177645071 -0.585285165611507 -0.210375932800263 999.99987831058
-0.830425037456931 0.324888033355832 -0.452594766813355 2000.00020492191
0.330163237719867 0.748692436800174 0.574849433796843 2000.00039108091
0.235357531182817 0.698629893827278 -0.675664934687612 1000.00007492586
-0.0252759290993658 0.0379201686488251 -0.998961054404929 2000.00014252836
0.546842290579453 0.822022275903206 -0.158880103073765 1999.99992261423
-0.705845814900482 -0.572901657744436 -0.416611781087803 1000.00004278418
0 0 0 0
-0.319518881827251 0.782629949981659 -0.534226586335394 2000.00010231319
-0.796402921366003 -0.0474093630577857 0.602905248885885 1999.99974200998
-0.869801261305662 0.0871697341395704 0.485641023062422 999.999905022761
-0.689124549662939 -0.344475524835289 -0.637529581934284 2000.00017609044
0.930071992155872 -0.367232402954371 0.0103175398020503 2000.000076743
-0.0387865533837705 -0.269543904021067 -0.962206675866308 300.000102348306
-0.321784537290427 -0.587162033302883 0.742762046828195 1999.99990937504
-0.358188673377807 -0.0314200285419143 -0.933120386697382 1000.0000928125
-0.894627113795976 -0.446195401943238 0.0234944790492188 2000.00016187314
-0.438398027574796 0.801557240714476 0.406587209927617 2000.00029585174
0.352032082192845 -0.761169811497065 -0.544696182447144 1000.0001011678
0.150773295533187 -0.341780709874397 -0.927606252518716 2000.00011850409
0.536092574100136 -0.458146663681737 0.709017902843069 2000.00049170514
-0.511030779275147 0.816974526933613 -0.267208093019345 1000.00027679295
0.0808828723113458 -0.976225457200873 0.201101510883468 2000.00038023648
0 0 0 0
0.026140396669367 0.878216448103584 0.477548479153994 2000.00050965305
0.48046760687536 0.875618076081277 0.0494354486496021 1000.00005463278
0.822175440314581 -0.265690210101659 -0.503424530192621 1999.99999846952
0.367359835691263 0.132172823264373 0.920639503775073 2000.00080911125
0.805181257519815 0.51776728055735 0.289136967064152 299.999964589479
-0.993661479531319 0.0474439909325547 -0.101911392003161 1999.99992137637
0.984204876106977 0.16580356755165 -0.0620478753415135 1000.00015015781
0.430800343869696 0.889176717346983 0.154194127805812 2000.00005692014
-0.13173951195581 -0.350188795198917 0.927368593767751 1999.99994061584
0.00961024946459843 0.298369753377368 -0.954401976828818 1000.00011142304
-0.699417118855117 0.711819900076127 0.0642504763252299 1999.9996062143
0.66083465671961 0.346616793034254 -0.665698396621866 2000.00008038555
-0.817783333086412 0.45350264507504 -0.354352608338109 1000.00006582083
0.797893876678741 0.00747038053066175 0.602751652816728 1999.99971585826
-0.435246513079407 -0.774930329873898 0.458304982182988 2000.00015550354
0 0 0 0
-0.33269031958098 0.423206984908473 0.842741359600788 999.999882287048
-0.514650058120205 0.541826381717323 0.664499427954595 1999.9994705513
0.817056429816889 0.454426055459905 0.354846094263457 1999.99995194021
0.51891468781919 -0.606298145871778 0.602602775531242 299.999944708613
0.0540042373913465 -0.735431094475289 0.67544403737294 2000.00019321844
-0.0108380109196039 0.921630758200255 -0.387916592914675 999.999830300256
0.069049903178605 0.633383659156832 0.770751095480329 1999.99981586622
-0.893099048876535 -0.323924614100414 0.312164913588516 1999.9998258803
-0.665632462406544 -0.223524340882359 -0.712018464664862 999.999902629319
-0.399665611893265 0.881013618261005 -0.25314502386702 1999.99978088419
-0.299294463436903 0.235500364835816 -0.924641769723937 2000.00008771424
0.676819337286428 0.269793966890722 -0.684928317493537 999.999948918634
0.322497210114459 -0.0765184405364161 -0.943472563313987 2000.00049470869
-0.511242805052435 -0.559697384583514 -0.652203673688282 2000.0000387101
0.167840263488799 0.886017705627799 0.432206283232975 1000.00007758807
0 0 0 0
-0.841161354296278 0.488384680882299 -0.232223985664588 2000.00007467639
-0.24976801872322 -0.956623746809379 0.149956473229613 2000.00018059607
-0.632028603232694 -0.0675729560690457 0.771993355090457 300.000034904091
-0.185904777890706 0.940564720516054 0.284213687351549 1999.99961505658
-0.4754559551591 0.865109057582523 0.159774695094143 999.99993623342
-0.748384535224544 -0.659642681561461 0.0692251406582043 1999.99938414262
-0.933735314126377 0.252291831114932 0.25394329112223 1999.99998232314
-0.660972945111305 0.235562038257733 -0.71247827473036 1000.00001479242
-0.612438395408371 0.600800465115572 -0.513768442925928 1999.99989936378
-0.613731596601915 0.014510990865411 0.789381377077372 1999.99976144676
-0.681335443301997 0.379520296269051 0.625896443847001 1000.00001966139
-0.0995100334001546 -0.205228408260224 -0.973642158955576 1999.99905938523
0.973754556848089 0.218352536020355 0.0642201917706612 1999.99988971312
-0.838817776035681 -0.541622326413553 -0.0550453825213679 1000.00027172606
-0.292222791582431 -0.887136734445747 -0.357203379710644 2000.00011522126
0 0 0 0
0.705591864582493 -0.241774852129539 0.666096870967535 1999.99963388189
0.218638561613619 -0.873811566381057 -0.434339182936806 299.999940686719
0.620429912312826 -0.727933149248131 -0.291856221679782 2000.00011403173
-0.00198795006659175 -0.191874826427365 -0.981417392875224 999.999933004605
0.107331383121532 0.590804112227291 -0.79964396775849 1999.99951098995
-0.282032418393822 0.511125593335009 0.811916462952235 1999.99973912472
-0.740058494523088 0 0.672542507715475 294.356827827049
-0.55359644872541 -0 -0.832785069485887 1838.69585366437
-0.645225446086714 0 0.763992227527349 1362.09134605535
-0.999870369119035 -0 -0.0161010856082394 931.08744348221
0 0 0 0

Welcome Amelia,

Apologies for taking so long to get to this. I hope my downtime has not severely borked your ability to process your data in time.

There’s two separate components of MRtrix3 that have not been resolved with one another that have therefore come into conflict:

  1. dwifslpreproc needs to be able to look at the diffusion gradient & phase encoding information associated with the data in order to make automated decisions about what processes to apply. This includes whether or not two two volumes are members of the same b-value shell (even if their b-values are not precisely equivalent, which can happen due to a multitude of reasons).

  2. In the process of assigning DWI volumes to shells, it’s possible in some circumstances that based on the heuristic in use, one or more volumes may not be reasonably ascribed to any b-value shell.

The issue then is that I’ve put an assertion in place to try to make sure that my heuristics for part 1 are working, without taking into account the prospect of part 2 occurring.

So there’s multiple avenues that necessitate pursuit here:

  1. Most likely, simply deleting the offending line of code should permit execution on your data. It’s not ideal from my perspective as there are other prospective cases where doing so would lead to other issues (specifically if two volumes had the same gradient direction but different b-values neither of which were attributed to a shell), but it would at least be useful to know whether in your case the script can execute successfully by doing so.

  2. You need to look closely at your data and determine whether there’s been a fault in DICOM conversion, acquisition, or processing. Specifically look at the last four volumes in your gradient table:

    -0.55359644872541 -0 -0.832785069485887 1838.69585366437
    -0.645225446086714 0 0.763992227527349 1362.09134605535
    -0.999870369119035 -0 -0.0161010856082394 931.08744348221
    0 0 0 0
    

    Within each of your b-value shells, there is very little variance in the precise reported b-values, yet there are three volumes here where the b-values vary quite substantially from your intended b-value shells (b = 0, 300, 1000, 2000 as correctly reported by dirstat). In addition to volumes 105 (b=1839) and 106 (b=1362), volume 107 has a b-value of 931, which is being attributed to the b=1000 shell by MRtrix3 but potentially shouldn’t be. You need to find out whether the b-values actually being achieved at the point of acquisition are not those intended (in which case the volumes should probably be discarded prior to processing), or if this is a result of data mis-interpretation, what point along the chain the error occurs.

Rob