/
dti.py
1626 lines (1348 loc) · 49.6 KB
/
dti.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import os
from ...utils.filemanip import split_filename
from ..base import (
CommandLineInputSpec,
CommandLine,
traits,
TraitedSpec,
File,
Directory,
StdOutCommandLine,
StdOutCommandLineInputSpec,
isdefined,
InputMultiPath,
)
class DTIFitInputSpec(StdOutCommandLineInputSpec):
in_file = File(
exists=True,
argstr="%s",
mandatory=True,
position=1,
desc="voxel-order data filename",
)
bgmask = File(
argstr="-bgmask %s",
exists=True,
desc=(
"Provides the name of a file containing a background mask computed using, "
"for example, FSL bet2 program. The mask file contains zero in background "
"voxels and non-zero in foreground."
),
)
scheme_file = File(
exists=True,
argstr="%s",
mandatory=True,
position=2,
desc="Camino scheme file (b values / vectors, see camino.fsl2scheme)",
)
non_linear = traits.Bool(
argstr="-nonlinear",
position=3,
desc="Use non-linear fitting instead of the default linear regression "
"to the log measurements. ",
)
class DTIFitOutputSpec(TraitedSpec):
tensor_fitted = File(exists=True, desc="path/name of 4D volume in voxel order")
class DTIFit(StdOutCommandLine):
"""
Reads diffusion MRI data, acquired using the acquisition scheme detailed in the scheme file,
from the data file.
Use non-linear fitting instead of the default linear regression to the log measurements.
The data file stores the diffusion MRI data in voxel order with the measurements stored
in big-endian format and ordered as in the scheme file.
The default input data type is four-byte float.
The default output data type is eight-byte double.
See modelfit and camino for the format of the data file and scheme file.
The program fits the diffusion tensor to each voxel and outputs the results,
in voxel order and as big-endian eight-byte doubles, to the standard output.
The program outputs eight values in each voxel:
[exit code, ln(S(0)), D_xx, D_xy, D_xz, D_yy, D_yz, D_zz].
An exit code of zero indicates no problems.
For a list of other exit codes, see modelfit(1).
The entry S(0) is an estimate of the signal at q=0.
Example
-------
>>> import nipype.interfaces.camino as cmon
>>> fit = cmon.DTIFit()
>>> fit.inputs.scheme_file = 'A.scheme'
>>> fit.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> fit.run() # doctest: +SKIP
"""
_cmd = "dtfit"
input_spec = DTIFitInputSpec
output_spec = DTIFitOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["tensor_fitted"] = os.path.abspath(self._gen_outfilename())
return outputs
def _gen_outfilename(self):
_, name, _ = split_filename(self.inputs.in_file)
return name + "_DT.Bdouble"
class DTMetricInputSpec(CommandLineInputSpec):
eigen_data = File(
exists=True,
argstr="-inputfile %s",
mandatory=True,
desc="voxel-order data filename",
)
metric = traits.Enum(
"fa",
"md",
"rd",
"l1",
"l2",
"l3",
"tr",
"ra",
"2dfa",
"cl",
"cp",
"cs",
argstr="-stat %s",
mandatory=True,
desc="Specifies the metric to compute.",
)
inputdatatype = traits.Enum(
"double",
"float",
"long",
"int",
"short",
"char",
argstr="-inputdatatype %s",
usedefault=True,
desc="Specifies the data type of the input data.",
)
outputdatatype = traits.Enum(
"double",
"float",
"long",
"int",
"short",
"char",
argstr="-outputdatatype %s",
usedefault=True,
desc="Specifies the data type of the output data.",
)
data_header = File(
argstr="-header %s",
exists=True,
desc=(
"A Nifti .nii or .nii.gz file containing the header information. "
"Usually this will be the header of the raw data file from which "
"the diffusion tensors were reconstructed."
),
)
outputfile = File(
argstr="-outputfile %s",
genfile=True,
desc=(
"Output name. Output will be a .nii.gz file if data_header is provided and"
"in voxel order with outputdatatype datatype (default: double) otherwise."
),
)
class DTMetricOutputSpec(TraitedSpec):
metric_stats = File(
exists=True, desc="Diffusion Tensor statistics of the chosen metric"
)
class DTMetric(CommandLine):
"""
Computes tensor metric statistics based on the eigenvalues l1 >= l2 >= l3
typically obtained from ComputeEigensystem.
The full list of statistics is:
- <cl> = (l1 - l2) / l1 , a measure of linearity
- <cp> = (l2 - l3) / l1 , a measure of planarity
- <cs> = l3 / l1 , a measure of isotropy
with: cl + cp + cs = 1
- <l1> = first eigenvalue
- <l2> = second eigenvalue
- <l3> = third eigenvalue
- <tr> = l1 + l2 + l3
- <md> = tr / 3
- <rd> = (l2 + l3) / 2
- <fa> = fractional anisotropy. (Basser et al, J Magn Reson B 1996)
- <ra> = relative anisotropy (Basser et al, J Magn Reson B 1996)
- <2dfa> = 2D FA of the two minor eigenvalues l2 and l3
i.e. sqrt( 2 * [(l2 - <l>)^2 + (l3 - <l>)^2] / (l2^2 + l3^2) )
with: <l> = (l2 + l3) / 2
Example
-------
Compute the CP planar metric as float data type.
>>> import nipype.interfaces.camino as cam
>>> dtmetric = cam.DTMetric()
>>> dtmetric.inputs.eigen_data = 'dteig.Bdouble'
>>> dtmetric.inputs.metric = 'cp'
>>> dtmetric.inputs.outputdatatype = 'float'
>>> dtmetric.run() # doctest: +SKIP
"""
_cmd = "dtshape"
input_spec = DTMetricInputSpec
output_spec = DTMetricOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["metric_stats"] = os.path.abspath(self._gen_outfilename())
return outputs
def _gen_outfilename(self):
return self._gen_outputfile()
def _gen_outputfile(self):
outputfile = self.inputs.outputfile
if not isdefined(outputfile):
outputfile = self._gen_filename("outputfile")
return outputfile
def _gen_filename(self, name):
if name == "outputfile":
_, name, _ = split_filename(self.inputs.eigen_data)
metric = self.inputs.metric
datatype = self.inputs.outputdatatype
if isdefined(self.inputs.data_header):
filename = name + "_" + metric + ".nii.gz"
else:
filename = name + "_" + metric + ".B" + datatype
return filename
class ModelFitInputSpec(StdOutCommandLineInputSpec):
def _gen_model_options(): # @NoSelf
"""
Generate all possible permutations of < multi - tensor > < single - tensor > options
"""
single_tensor = ["dt", "restore", "algdt", "nldt_pos", "nldt", "ldt_wtd"]
multi_tensor = [
"cylcyl",
"cylcyl_eq",
"pospos",
"pospos_eq",
"poscyl",
"poscyl_eq",
"cylcylcyl",
"cylcylcyl_eq",
"pospospos",
"pospospos_eq",
"posposcyl",
"posposcyl_eq",
"poscylcyl",
"poscylcyl_eq",
]
other = ["adc", "ball_stick"]
model_list = single_tensor
model_list.extend(other)
model_list.extend(
[multi + " " + single for multi in multi_tensor for single in single_tensor]
)
return model_list
model = traits.Enum(
_gen_model_options(),
argstr="-model %s",
mandatory=True,
desc="Specifies the model to be fit to the data.",
)
in_file = File(
exists=True,
argstr="-inputfile %s",
mandatory=True,
desc="voxel-order data filename",
)
inputdatatype = traits.Enum(
"float",
"char",
"short",
"int",
"long",
"double",
argstr="-inputdatatype %s",
desc="Specifies the data type of the input file. "
"The input file must have BIG-ENDIAN ordering. "
"By default, the input type is ``float``.",
)
scheme_file = File(
exists=True,
argstr="-schemefile %s",
mandatory=True,
desc="Camino scheme file (b values / vectors, see camino.fsl2scheme)",
)
outputfile = File(argstr="-outputfile %s", desc="Filename of the output file.")
outlier = File(
argstr="-outliermap %s",
exists=True,
desc="Specifies the name of the file to contain the outlier map generated by "
"the RESTORE algorithm.",
)
noisemap = File(
argstr="-noisemap %s",
exists=True,
desc="Specifies the name of the file to contain the estimated noise variance on the "
"diffusion-weighted signal, generated by a weighted tensor fit. "
"The data type of this file is big-endian double.",
)
residualmap = File(
argstr="-residualmap %s",
exists=True,
desc="Specifies the name of the file to contain the weighted residual errors after "
"computing a weighted linear tensor fit. "
"One value is produced per measurement, in voxel order. "
"The data type of this file is big-endian double. "
"Images of the residuals for each measurement can be extracted with shredder.",
)
sigma = traits.Float(
argstr="-sigma %G",
desc="Specifies the standard deviation of the noise in the data. "
"Required by the RESTORE algorithm.",
)
bgthresh = traits.Float(
argstr="-bgthresh %G",
desc="Sets a threshold on the average q=0 measurement to separate "
"foreground and background. The program does not process background voxels, "
"but outputs the same number of values in background voxels and foreground voxels. "
"Each value is zero in background voxels apart from the exit code which is -1.",
)
bgmask = File(
argstr="-bgmask %s",
exists=True,
desc="Provides the name of a file containing a background mask computed using, "
"for example, FSL's bet2 program. The mask file contains zero in background voxels "
"and non-zero in foreground.",
)
cfthresh = traits.Float(
argstr="-csfthresh %G",
desc="Sets a threshold on the average q=0 measurement to determine which voxels "
"are CSF. This program does not treat CSF voxels any different to other voxels.",
)
fixedmodq = traits.List(
traits.Float,
argstr="-fixedmod %s",
minlen=4,
maxlen=4,
desc="Specifies <M> <N> <Q> <tau> a spherical acquisition scheme with M measurements "
"with q=0 and N measurements with :math:`|q|=Q` and diffusion time tau. "
"The N measurements with :math:`|q|=Q` have unique directions. The program reads in "
"the directions from the files in directory PointSets.",
)
fixedbvalue = traits.List(
traits.Float,
argstr="-fixedbvalue %s",
minlen=3,
maxlen=3,
desc="As above, but specifies <M> <N> <b>. The resulting scheme is the same whether "
"you specify b directly or indirectly using -fixedmodq.",
)
tau = traits.Float(
argstr="-tau %G",
desc="Sets the diffusion time separately. This overrides the diffusion time "
"specified in a scheme file or by a scheme index for both the acquisition scheme "
"and in the data synthesis.",
)
class ModelFitOutputSpec(TraitedSpec):
fitted_data = File(exists=True, desc="output file of 4D volume in voxel order")
class ModelFit(StdOutCommandLine):
"""
Fits models of the spin-displacement density to diffusion MRI measurements.
This is an interface to various model fitting routines for diffusion MRI data that
fit models of the spin-displacement density function. In particular, it will fit the
diffusion tensor to a set of measurements as well as various other models including
two or three-tensor models. The program can read input data from a file or can
generate synthetic data using various test functions for testing and simulations.
Example
-------
>>> import nipype.interfaces.camino as cmon
>>> fit = cmon.ModelFit()
>>> fit.model = 'dt'
>>> fit.inputs.scheme_file = 'A.scheme'
>>> fit.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> fit.run() # doctest: +SKIP
"""
_cmd = "modelfit"
input_spec = ModelFitInputSpec
output_spec = ModelFitOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["fitted_data"] = os.path.abspath(self._gen_outfilename())
return outputs
def _gen_outfilename(self):
_, name, _ = split_filename(self.inputs.in_file)
return name + "_fit.Bdouble"
class DTLUTGenInputSpec(StdOutCommandLineInputSpec):
lrange = traits.List(
traits.Float,
desc="Index to one-tensor LUTs. This is the ratio L1/L3 and L2 / L3."
"The LUT is square, with half the values calculated (because L2 / L3 cannot be "
"less than L1 / L3 by definition)."
"The minimum must be >= 1. For comparison, a ratio L1 / L3 = 10 with L2 / L3 = 1 "
"corresponds to an FA of 0.891, and L1 / L3 = 15 with L2 / L3 = 1 corresponds "
"to an FA of 0.929. The default range is 1 to 10.",
argstr="-lrange %s",
minlen=2,
maxlen=2,
position=1,
units="NA",
)
frange = traits.List(
traits.Float,
desc="Index to two-tensor LUTs. This is the fractional anisotropy"
" of the two tensors. The default is 0.3 to 0.94",
argstr="-frange %s",
minlen=2,
maxlen=2,
position=1,
units="NA",
)
step = traits.Float(
argstr="-step %f",
units="NA",
desc="Distance between points in the LUT."
"For example, if lrange is 1 to 10 and the step is 0.1, LUT entries will be computed "
"at L1 / L3 = 1, 1.1, 1.2 ... 10.0 and at L2 / L3 = 1.0, 1.1 ... L1 / L3."
"For single tensor LUTs, the default step is 0.2, for two-tensor LUTs it is 0.02.",
)
samples = traits.Int(
argstr="-samples %d",
units="NA",
desc="The number of synthetic measurements to generate at each point in the LUT. "
"The default is 2000.",
)
snr = traits.Float(
argstr="-snr %f",
units="NA",
desc="The signal to noise ratio of the unweighted (q = 0) measurements."
"This should match the SNR (in white matter) of the images that the LUTs are used with.",
)
bingham = traits.Bool(
argstr="-bingham",
desc="Compute a LUT for the Bingham PDF. This is the default.",
)
acg = traits.Bool(argstr="-acg", desc="Compute a LUT for the ACG PDF.")
watson = traits.Bool(argstr="-watson", desc="Compute a LUT for the Watson PDF.")
inversion = traits.Int(
argstr="-inversion %d",
units="NA",
desc="Index of the inversion to use. The default is 1 (linear single tensor inversion).",
)
trace = traits.Float(
argstr="-trace %G",
units="NA",
desc="Trace of the diffusion tensor(s) used in the test function in the LUT generation. "
"The default is 2100E-12 m^2 s^-1.",
)
scheme_file = File(
argstr="-schemefile %s",
mandatory=True,
position=2,
desc="The scheme file of the images to be processed using this LUT.",
)
class DTLUTGenOutputSpec(TraitedSpec):
dtLUT = File(exists=True, desc="Lookup Table")
class DTLUTGen(StdOutCommandLine):
"""
Calibrates the PDFs for PICo probabilistic tractography.
This program needs to be run once for every acquisition scheme.
It outputs a lookup table that is used by the dtpicoparams program to find PICo PDF
parameters for an image.
The default single tensor LUT contains parameters of the Bingham distribution and is
generated by supplying a scheme file and an estimated signal to noise in white matter
regions of the (q=0) image.
The default inversion is linear (inversion index 1).
Advanced users can control several options, including the extent and resolution of the LUT,
the inversion index, and the type of PDF. See dtlutgen(1) for details.
Example
-------
>>> import nipype.interfaces.camino as cmon
>>> dtl = cmon.DTLUTGen()
>>> dtl.inputs.snr = 16
>>> dtl.inputs.scheme_file = 'A.scheme'
>>> dtl.run() # doctest: +SKIP
"""
_cmd = "dtlutgen"
input_spec = DTLUTGenInputSpec
output_spec = DTLUTGenOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["dtLUT"] = os.path.abspath(self._gen_outfilename())
return outputs
def _gen_outfilename(self):
_, name, _ = split_filename(self.inputs.scheme_file)
return name + ".dat"
class PicoPDFsInputSpec(StdOutCommandLineInputSpec):
in_file = File(
exists=True,
argstr="< %s",
mandatory=True,
position=1,
desc="voxel-order data filename",
)
inputmodel = traits.Enum(
"dt",
"multitensor",
"pds",
argstr="-inputmodel %s",
position=2,
desc="input model type",
usedefault=True,
)
luts = InputMultiPath(
File(exists=True),
argstr="-luts %s",
mandatory=True,
desc="Files containing the lookup tables."
"For tensor data, one lut must be specified for each type of inversion used in the "
"image (one-tensor, two-tensor, three-tensor)."
"For pds, the number of LUTs must match -numpds (it is acceptable to use the same "
"LUT several times - see example, above)."
"These LUTs may be generated with dtlutgen.",
)
pdf = traits.Enum(
"bingham",
"watson",
"acg",
argstr="-pdf %s",
position=4,
desc="""\
Specifies the PDF to use. There are three choices:
* watson - The Watson distribution. This distribution is rotationally symmetric.
* bingham - The Bingham distributionn, which allows elliptical probability density contours.
* acg - The Angular Central Gaussian distribution, which also allows elliptical probability
density contours.
""",
usedefault=True,
)
directmap = traits.Bool(
argstr="-directmap",
desc="Only applicable when using pds as the inputmodel. Use direct mapping between "
"the eigenvalues and the distribution parameters instead of the log of the eigenvalues.",
)
maxcomponents = traits.Int(
argstr="-maxcomponents %d",
units="NA",
desc="The maximum number of tensor components in a voxel (default 2) for multitensor data."
"Currently, only the default is supported, but future releases may allow the input "
"of three-tensor data using this option.",
)
numpds = traits.Int(
argstr="-numpds %d",
units="NA",
desc="The maximum number of PDs in a voxel (default 3) for PD data."
"This option determines the size of the input and output voxels."
"This means that the data file may be large enough to accomodate three or more PDs,"
"but does not mean that any of the voxels are classified as containing three or more PDs.",
)
class PicoPDFsOutputSpec(TraitedSpec):
pdfs = File(exists=True, desc="path/name of 4D volume in voxel order")
class PicoPDFs(StdOutCommandLine):
"""
Constructs a spherical PDF in each voxel for probabilistic tractography.
Example
-------
>>> import nipype.interfaces.camino as cmon
>>> pdf = cmon.PicoPDFs()
>>> pdf.inputs.inputmodel = 'dt'
>>> pdf.inputs.luts = ['lut_file']
>>> pdf.inputs.in_file = 'voxel-order_data.Bfloat'
>>> pdf.run() # doctest: +SKIP
"""
_cmd = "picopdfs"
input_spec = PicoPDFsInputSpec
output_spec = PicoPDFsOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["pdfs"] = os.path.abspath(self._gen_outfilename())
return outputs
def _gen_outfilename(self):
_, name, _ = split_filename(self.inputs.in_file)
return name + "_pdfs.Bdouble"
class TrackInputSpec(CommandLineInputSpec):
in_file = File(
exists=True, argstr="-inputfile %s", position=1, desc="input data file"
)
seed_file = File(exists=True, argstr="-seedfile %s", position=2, desc="seed file")
inputmodel = traits.Enum(
"dt",
"multitensor",
"sfpeak",
"pico",
"repbs_dt",
"repbs_multitensor",
"ballstick",
"wildbs_dt",
"bayesdirac",
"bayesdirac_dt",
"bedpostx_dyad",
"bedpostx",
argstr="-inputmodel %s",
desc="input model type",
usedefault=True,
)
tracker = traits.Enum(
"fact",
"euler",
"rk4",
argstr="-tracker %s",
desc=(
"The tracking algorithm controls streamlines are "
"generated from the data. The choices are: "
"- FACT, which follows the local fibre orientation "
"in each voxel. No interpolation is used."
"- EULER, which uses a fixed step size along the "
"local fibre orientation. With nearest-neighbour "
"interpolation, this method may be very similar to "
"FACT, except that the step size is fixed, whereas "
"FACT steps extend to the boundary of the next voxel "
"(distance variable depending on the entry and exit "
"points to the voxel)."
"- RK4: Fourth-order Runge-Kutta method. The step "
"size is fixed, however the eventual direction of "
"the step is determined by taking and averaging a "
"series of partial steps."
),
usedefault=True,
)
interpolator = traits.Enum(
"nn",
"prob_nn",
"linear",
argstr="-interpolator %s",
desc=(
"The interpolation algorithm determines how "
"the fiber orientation(s) are defined at a given "
"continuous point within the input image. "
"Interpolators are only used when the tracking "
"algorithm is not FACT. The choices are: "
"- NN: Nearest-neighbour interpolation, just "
"uses the local voxel data directly."
"- PROB_NN: Probabilistic nearest-neighbor "
"interpolation, similar to the method pro- "
"posed by Behrens et al [Magnetic Resonance "
"in Medicine, 50:1077-1088, 2003]. The data "
"is not interpolated, but at each point we "
"randomly choose one of the 8 voxels sur- "
"rounding a point. The probability of choosing "
"a particular voxel is based on how close the "
"point is to the centre of that voxel."
"- LINEAR: Linear interpolation of the vector "
"field containing the principal directions at "
"each point."
),
)
stepsize = traits.Float(
argstr="-stepsize %f",
requires=["tracker"],
desc=("Step size for EULER and RK4 tracking. " "The default is 1mm."),
)
inputdatatype = traits.Enum(
"float", "double", argstr="-inputdatatype %s", desc="input file type"
)
gzip = traits.Bool(argstr="-gzip", desc="save the output image in gzip format")
maxcomponents = traits.Int(
argstr="-maxcomponents %d",
units="NA",
desc=(
"The maximum number of tensor components in a "
"voxel. This determines the size of the input "
"file and does not say anything about the "
"voxel classification. The default is 2 if "
"the input model is multitensor and 1 if the "
"input model is dt."
),
)
numpds = traits.Int(
argstr="-numpds %d",
units="NA",
desc=(
"The maximum number of PDs in a voxel for input "
"models sfpeak and pico. The default is 3 for input "
"model sfpeak and 1 for input model pico. This option "
"determines the size of the voxels in the input file "
"and does not affect tracking. For tensor data, use "
"the -maxcomponents option."
),
)
data_dims = traits.List(
traits.Int,
desc="data dimensions in voxels",
argstr="-datadims %s",
minlen=3,
maxlen=3,
units="voxels",
)
voxel_dims = traits.List(
traits.Float,
desc="voxel dimensions in mm",
argstr="-voxeldims %s",
minlen=3,
maxlen=3,
units="mm",
)
ipthresh = traits.Float(
argstr="-ipthresh %f",
desc=(
"Curvature threshold for tracking, expressed as "
"the minimum dot product between two streamline "
"orientations calculated over the length of a "
"voxel. If the dot product between the previous "
"and current directions is less than this "
"threshold, then the streamline terminates. The "
"default setting will terminate fibres that curve "
"by more than 80 degrees. Set this to -1.0 to "
"disable curvature checking completely."
),
)
curvethresh = traits.Float(
argstr="-curvethresh %f",
desc=(
"Curvature threshold for tracking, expressed "
"as the maximum angle (in degrees) between "
"between two streamline orientations "
"calculated over the length of a voxel. If "
"the angle is greater than this, then the "
"streamline terminates."
),
)
curveinterval = traits.Float(
argstr="-curveinterval %f",
requires=["curvethresh"],
desc=(
"Interval over which the curvature threshold "
"should be evaluated, in mm. The default is "
"5mm. When using the default curvature "
"threshold of 90 degrees, this means that "
"streamlines will terminate if they curve by "
"more than 90 degrees over a path length "
"of 5mm."
),
)
anisthresh = traits.Float(
argstr="-anisthresh %f",
desc=(
"Terminate fibres that enter a voxel with lower "
"anisotropy than the threshold."
),
)
anisfile = File(
argstr="-anisfile %s",
exists=True,
desc=(
"File containing the anisotropy map. This is required to "
"apply an anisotropy threshold with non tensor data. If "
"the map issupplied it is always used, even in tensor "
"data."
),
)
outputtracts = traits.Enum(
"float",
"double",
"oogl",
argstr="-outputtracts %s",
desc="output tract file type",
)
out_file = File(
argstr="-outputfile %s", position=-1, genfile=True, desc="output data file"
)
output_root = File(
exists=False,
argstr="-outputroot %s",
position=-1,
desc="root directory for output",
)
class TrackOutputSpec(TraitedSpec):
tracked = File(exists=True, desc="output file containing reconstructed tracts")
class Track(CommandLine):
"""
Performs tractography using one of the following models:
dt', 'multitensor', 'pds', 'pico', 'bootstrap', 'ballstick', 'bayesdirac'
Example
-------
>>> import nipype.interfaces.camino as cmon
>>> track = cmon.Track()
>>> track.inputs.inputmodel = 'dt'
>>> track.inputs.in_file = 'data.Bfloat'
>>> track.inputs.seed_file = 'seed_mask.nii'
>>> track.run() # doctest: +SKIP
"""
_cmd = "track"
input_spec = TrackInputSpec
output_spec = TrackOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
if isdefined(self.inputs.out_file):
out_file_path = os.path.abspath(self.inputs.out_file)
else:
out_file_path = os.path.abspath(self._gen_outfilename())
outputs["tracked"] = out_file_path
return outputs
def _gen_filename(self, name):
if name == "out_file":
return self._gen_outfilename()
else:
return None
def _gen_outfilename(self):
# Currently in_file is only undefined for bedpostx input
if not isdefined(self.inputs.in_file):
name = "bedpostx"
else:
_, name, _ = split_filename(self.inputs.in_file)
return name + "_tracked"
class TrackDT(Track):
"""
Performs streamline tractography using tensor data
Example
-------
>>> import nipype.interfaces.camino as cmon
>>> track = cmon.TrackDT()
>>> track.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> track.inputs.seed_file = 'seed_mask.nii'
>>> track.run() # doctest: +SKIP
"""
def __init__(self, command=None, **inputs):
inputs["inputmodel"] = "dt"
return super(TrackDT, self).__init__(command, **inputs)
class TrackPICoInputSpec(TrackInputSpec):
pdf = traits.Enum(
"bingham",
"watson",
"acg",
argstr="-pdf %s",
desc='Specifies the model for PICo parameters. The default is "bingham.',
)
iterations = traits.Int(
argstr="-iterations %d",
units="NA",
desc="Number of streamlines to generate at each seed point. The default is 5000.",
)
class TrackPICo(Track):
"""
Performs streamline tractography using Probabilistic Index of Connectivity (PICo).
Example
-------
>>> import nipype.interfaces.camino as cmon
>>> track = cmon.TrackPICo()
>>> track.inputs.in_file = 'pdfs.Bfloat'
>>> track.inputs.seed_file = 'seed_mask.nii'
>>> track.run() # doctest: +SKIP
"""
input_spec = TrackPICoInputSpec
def __init__(self, command=None, **inputs):
inputs["inputmodel"] = "pico"
return super(TrackPICo, self).__init__(command, **inputs)
class TrackBedpostxDeterInputSpec(TrackInputSpec):
bedpostxdir = Directory(
argstr="-bedpostxdir %s",
mandatory=True,
exists=True,
desc=("Directory containing bedpostx output"),
)
min_vol_frac = traits.Float(
argstr="-bedpostxminf %d",
units="NA",
desc=(
"Zeros out compartments in bedpostx data "
"with a mean volume fraction f of less than "
"min_vol_frac. The default is 0.01."
),
)
class TrackBedpostxDeter(Track):