/
minc.py
3898 lines (3154 loc) · 109 KB
/
minc.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 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""The minc module provides classes for interfacing with the `MINC
<http://www.bic.mni.mcgill.ca/ServicesSoftware/MINC>`_ command line tools. This
module was written to work with MINC version 2.2.00.
Author: `Carlo Hamalainen <http://carlo-hamalainen.net>`__
"""
import glob
import os
import os.path
import re
import warnings
from ..base import (
TraitedSpec,
CommandLineInputSpec,
CommandLine,
StdOutCommandLineInputSpec,
StdOutCommandLine,
File,
Directory,
InputMultiPath,
OutputMultiPath,
traits,
isdefined,
)
from .base import aggregate_filename
warnings.filterwarnings("always", category=UserWarning)
class ExtractInputSpec(StdOutCommandLineInputSpec):
input_file = File(
desc="input file", exists=True, mandatory=True, argstr="%s", position=-2,
)
output_file = File(
desc="output file",
position=-1,
name_source=["input_file"],
hash_files=False,
name_template="%s.raw",
keep_extension=False,
)
_xor_write = (
"write_ascii",
"write_ascii",
"write_byte",
"write_short",
"write_int",
"write_long",
"write_float",
"write_double",
"write_signed",
"write_unsigned",
)
write_ascii = traits.Bool(
desc="Write out data as ascii strings (default).",
argstr="-ascii",
xor=_xor_write,
)
write_byte = traits.Bool(
desc="Write out data as bytes.", argstr="-byte", xor=_xor_write
)
write_short = traits.Bool(
desc="Write out data as short integers.", argstr="-short", xor=_xor_write
)
write_int = traits.Bool(
desc="Write out data as 32-bit integers.", argstr="-int", xor=_xor_write
)
write_long = traits.Bool(
desc="Superseded by write_int.", argstr="-long", xor=_xor_write
)
write_float = traits.Bool(
desc="Write out data as single precision floating-point values.",
argstr="-float",
xor=_xor_write,
)
write_double = traits.Bool(
desc="Write out data as double precision floating-point values.",
argstr="-double",
xor=_xor_write,
)
_xor_signed = ("write_signed", "write_unsigned")
write_signed = traits.Bool(
desc="Write out signed data.", argstr="-signed", xor=_xor_signed
)
write_unsigned = traits.Bool(
desc="Write out unsigned data.", argstr="-unsigned", xor=_xor_signed
)
write_range = traits.Tuple(
traits.Float,
traits.Float,
argstr="-range %s %s",
desc="Specify the range of output values\nDefault value: 1.79769e+308 1.79769e+308.",
)
_xor_normalize = (
"normalize",
"nonormalize",
)
normalize = traits.Bool(
desc="Normalize integer pixel values to file max and min.",
argstr="-normalize",
xor=_xor_normalize,
)
nonormalize = traits.Bool(
desc="Turn off pixel normalization.", argstr="-nonormalize", xor=_xor_normalize
)
image_range = traits.Tuple(
traits.Float,
traits.Float,
desc="Specify the range of real image values for normalization.",
argstr="-image_range %s %s",
)
image_minimum = traits.Float(
desc=(
"Specify the minimum real image value for normalization."
"Default value: 1.79769e+308."
),
argstr="-image_minimum %s",
)
image_maximum = traits.Float(
desc=(
"Specify the maximum real image value for normalization."
"Default value: 1.79769e+308."
),
argstr="-image_maximum %s",
)
start = InputMultiPath(
traits.Int,
desc="Specifies corner of hyperslab (C conventions for indices).",
sep=",",
argstr="-start %s",
)
count = InputMultiPath(
traits.Int,
desc="Specifies edge lengths of hyperslab to read.",
sep=",",
argstr="-count %s",
)
# FIXME Can we make sure that len(start) == len(count)?
_xor_flip = (
"flip_positive_direction",
"flip_negative_direction",
"flip_any_direction",
)
flip_positive_direction = traits.Bool(
desc="Flip images to always have positive direction.",
argstr="-positive_direction",
xor=_xor_flip,
)
flip_negative_direction = traits.Bool(
desc="Flip images to always have negative direction.",
argstr="-negative_direction",
xor=_xor_flip,
)
flip_any_direction = traits.Bool(
desc="Do not flip images (Default).", argstr="-any_direction", xor=_xor_flip
)
_xor_x_flip = ("flip_x_positive", "flip_x_negative", "flip_x_any")
flip_x_positive = traits.Bool(
desc="Flip images to give positive xspace:step value (left-to-right).",
argstr="+xdirection",
xor=_xor_x_flip,
)
flip_x_negative = traits.Bool(
desc="Flip images to give negative xspace:step value (right-to-left).",
argstr="-xdirection",
xor=_xor_x_flip,
)
flip_x_any = traits.Bool(
desc="Don't flip images along x-axis (default).",
argstr="-xanydirection",
xor=_xor_x_flip,
)
_xor_y_flip = ("flip_y_positive", "flip_y_negative", "flip_y_any")
flip_y_positive = traits.Bool(
desc="Flip images to give positive yspace:step value (post-to-ant).",
argstr="+ydirection",
xor=_xor_y_flip,
)
flip_y_negative = traits.Bool(
desc="Flip images to give negative yspace:step value (ant-to-post).",
argstr="-ydirection",
xor=_xor_y_flip,
)
flip_y_any = traits.Bool(
desc="Don't flip images along y-axis (default).",
argstr="-yanydirection",
xor=_xor_y_flip,
)
_xor_z_flip = ("flip_z_positive", "flip_z_negative", "flip_z_any")
flip_z_positive = traits.Bool(
desc="Flip images to give positive zspace:step value (inf-to-sup).",
argstr="+zdirection",
xor=_xor_z_flip,
)
flip_z_negative = traits.Bool(
desc="Flip images to give negative zspace:step value (sup-to-inf).",
argstr="-zdirection",
xor=_xor_z_flip,
)
flip_z_any = traits.Bool(
desc="Don't flip images along z-axis (default).",
argstr="-zanydirection",
xor=_xor_z_flip,
)
class ExtractOutputSpec(TraitedSpec):
output_file = File(desc="output file in raw/text format", exists=True)
class Extract(StdOutCommandLine):
"""Dump a hyperslab of MINC file data.
Examples
--------
>>> from nipype.interfaces.minc import Extract
>>> from nipype.interfaces.minc.testdata import minc2Dfile
>>> extract = Extract(input_file=minc2Dfile)
>>> extract.run() # doctest: +SKIP
>>> extract = Extract(input_file=minc2Dfile, start=[3, 10, 5], count=[4, 4, 4]) # extract a 4x4x4 slab at offset [3, 10, 5]
>>> extract.run() # doctest: +SKIP
"""
input_spec = ExtractInputSpec
output_spec = ExtractOutputSpec
_cmd = "mincextract"
class ToRawInputSpec(StdOutCommandLineInputSpec):
input_file = File(
desc="input file", exists=True, mandatory=True, argstr="%s", position=-2,
)
output_file = File(
desc="output file",
position=-1,
name_source=["input_file"],
hash_files=False,
name_template="%s.raw",
keep_extension=False,
)
_xor_write = (
"write_byte",
"write_short",
"write_int",
"write_long",
"write_float",
"write_double",
)
write_byte = traits.Bool(
desc="Write out data as bytes.", argstr="-byte", xor=_xor_write
)
write_short = traits.Bool(
desc="Write out data as short integers.", argstr="-short", xor=_xor_write
)
write_int = traits.Bool(
desc="Write out data as 32-bit integers.", argstr="-int", xor=_xor_write
)
write_long = traits.Bool(
desc="Superseded by write_int.", argstr="-long", xor=_xor_write
)
write_float = traits.Bool(
desc="Write out data as single precision floating-point values.",
argstr="-float",
xor=_xor_write,
)
write_double = traits.Bool(
desc="Write out data as double precision floating-point values.",
argstr="-double",
xor=_xor_write,
)
_xor_signed = ("write_signed", "write_unsigned")
write_signed = traits.Bool(
desc="Write out signed data.", argstr="-signed", xor=_xor_signed
)
write_unsigned = traits.Bool(
desc="Write out unsigned data.", argstr="-unsigned", xor=_xor_signed
)
write_range = traits.Tuple(
traits.Float,
traits.Float,
argstr="-range %s %s",
desc=(
"Specify the range of output values."
"Default value: 1.79769e+308 1.79769e+308."
),
)
_xor_normalize = (
"normalize",
"nonormalize",
)
normalize = traits.Bool(
desc="Normalize integer pixel values to file max and min.",
argstr="-normalize",
xor=_xor_normalize,
)
nonormalize = traits.Bool(
desc="Turn off pixel normalization.", argstr="-nonormalize", xor=_xor_normalize
)
class ToRawOutputSpec(TraitedSpec):
output_file = File(desc="output file in raw format", exists=True)
class ToRaw(StdOutCommandLine):
"""Dump a chunk of MINC file data. This program is largely
superceded by mincextract (see Extract).
Examples
--------
>>> from nipype.interfaces.minc import ToRaw
>>> from nipype.interfaces.minc.testdata import minc2Dfile
>>> toraw = ToRaw(input_file=minc2Dfile)
>>> toraw.run() # doctest: +SKIP
>>> toraw = ToRaw(input_file=minc2Dfile, write_range=(0, 100))
>>> toraw.run() # doctest: +SKIP
"""
input_spec = ToRawInputSpec
output_spec = ToRawOutputSpec
_cmd = "minctoraw"
class ConvertInputSpec(CommandLineInputSpec):
input_file = File(
desc="input file for converting",
exists=True,
mandatory=True,
argstr="%s",
position=-2,
)
output_file = File(
desc="output file",
genfile=True,
argstr="%s",
position=-1,
name_source=["input_file"],
hash_files=False,
name_template="%s_convert_output.mnc",
)
clobber = traits.Bool(
desc="Overwrite existing file.",
argstr="-clobber",
usedefault=True,
default_value=True,
)
two = traits.Bool(desc="Create a MINC 2 output file.", argstr="-2")
template = traits.Bool(
desc=(
"Create a template file. The dimensions, variables, and"
"attributes of the input file are preserved but all data it set to zero."
),
argstr="-template",
)
compression = traits.Enum(
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
argstr="-compress %s",
desc="Set the compression level, from 0 (disabled) to 9 (maximum).",
)
chunk = traits.Range(
low=0,
desc="Set the target block size for chunking (0 default, >1 block size).",
argstr="-chunk %d",
)
class ConvertOutputSpec(TraitedSpec):
output_file = File(desc="output file", exists=True)
class Convert(CommandLine):
"""convert between MINC 1 to MINC 2 format.
Examples
--------
>>> from nipype.interfaces.minc import Convert
>>> from nipype.interfaces.minc.testdata import minc2Dfile
>>> c = Convert(input_file=minc2Dfile, output_file='/tmp/out.mnc', two=True) # Convert to MINC2 format.
>>> c.run() # doctest: +SKIP
"""
input_spec = ConvertInputSpec
output_spec = ConvertOutputSpec
_cmd = "mincconvert"
class CopyInputSpec(CommandLineInputSpec):
input_file = File(
desc="input file to copy",
exists=True,
mandatory=True,
argstr="%s",
position=-2,
)
output_file = File(
desc="output file",
genfile=True,
argstr="%s",
position=-1,
name_source=["input_file"],
hash_files=False,
name_template="%s_copy.mnc",
)
_xor_pixel = ("pixel_values", "real_values")
pixel_values = traits.Bool(
desc="Copy pixel values as is.", argstr="-pixel_values", xor=_xor_pixel
)
real_values = traits.Bool(
desc="Copy real pixel intensities (default).",
argstr="-real_values",
xor=_xor_pixel,
)
class CopyOutputSpec(TraitedSpec):
output_file = File(desc="output file", exists=True)
class Copy(CommandLine):
"""
Copy image values from one MINC file to another. Both the input
and output files must exist, and the images in both files must
have an equal number dimensions and equal dimension lengths.
NOTE: This program is intended primarily for use with scripts
such as mincedit. It does not follow the typical design rules of
most MINC command-line tools and therefore should be used only
with caution.
"""
input_spec = CopyInputSpec
output_spec = CopyOutputSpec
_cmd = "minccopy"
class ToEcatInputSpec(CommandLineInputSpec):
input_file = File(
desc="input file to convert",
exists=True,
mandatory=True,
argstr="%s",
position=-2,
)
output_file = File(
desc="output file",
genfile=True,
argstr="%s",
position=-1,
name_source=["input_file"],
hash_files=False,
name_template="%s_to_ecat.v",
keep_extension=False,
)
ignore_patient_variable = traits.Bool(
desc="Ignore informations from the minc patient variable.",
argstr="-ignore_patient_variable",
)
ignore_study_variable = traits.Bool(
desc="Ignore informations from the minc study variable.",
argstr="-ignore_study_variable",
)
ignore_acquisition_variable = traits.Bool(
desc="Ignore informations from the minc acquisition variable.",
argstr="-ignore_acquisition_variable",
)
ignore_ecat_acquisition_variable = traits.Bool(
desc="Ignore informations from the minc ecat_acquisition variable.",
argstr="-ignore_ecat_acquisition_variable",
)
ignore_ecat_main = traits.Bool(
desc="Ignore informations from the minc ecat-main variable.",
argstr="-ignore_ecat_main",
)
ignore_ecat_subheader_variable = traits.Bool(
desc="Ignore informations from the minc ecat-subhdr variable.",
argstr="-ignore_ecat_subheader_variable",
)
no_decay_corr_fctr = traits.Bool(
desc="Do not compute the decay correction factors",
argstr="-no_decay_corr_fctr",
)
voxels_as_integers = traits.Bool(
desc=(
"Voxel values are treated as integers, scale and"
"calibration factors are set to unity"
),
argstr="-label",
)
class ToEcatOutputSpec(TraitedSpec):
output_file = File(desc="output file", exists=True)
class ToEcat(CommandLine):
"""Convert a 2D image, a 3D volumes or a 4D dynamic volumes
written in MINC file format to a 2D, 3D or 4D Ecat7 file.
Examples
--------
>>> from nipype.interfaces.minc import ToEcat
>>> from nipype.interfaces.minc.testdata import minc2Dfile
>>> c = ToEcat(input_file=minc2Dfile)
>>> c.run() # doctest: +SKIP
>>> c = ToEcat(input_file=minc2Dfile, voxels_as_integers=True)
>>> c.run() # doctest: +SKIP
"""
input_spec = ToEcatInputSpec
output_spec = ToEcatOutputSpec
_cmd = "minctoecat"
class DumpInputSpec(StdOutCommandLineInputSpec):
input_file = File(
desc="input file", exists=True, mandatory=True, argstr="%s", position=-2,
)
output_file = File(
desc="output file",
position=-1,
name_source=["input_file"],
hash_files=False,
name_template="%s_dump.txt",
keep_extension=False,
)
_xor_coords_or_header = (
"coordinate_data",
"header_data",
)
coordinate_data = traits.Bool(
desc="Coordinate variable data and header information.",
argstr="-c",
xor=_xor_coords_or_header,
)
header_data = traits.Bool(
desc="Header information only, no data.", argstr="-h", xor=_xor_coords_or_header
)
_xor_annotations = (
"annotations_brief",
"annotations_full",
)
annotations_brief = traits.Enum(
"c",
"f",
argstr="-b %s",
desc="Brief annotations for C or Fortran indices in data.",
xor=_xor_annotations,
)
annotations_full = traits.Enum(
"c",
"f",
argstr="-f %s",
desc="Full annotations for C or Fortran indices in data.",
xor=_xor_annotations,
)
variables = InputMultiPath(
traits.Str,
desc="Output data for specified variables only.",
sep=",",
argstr="-v %s",
)
line_length = traits.Range(
low=0, desc="Line length maximum in data section (default 80).", argstr="-l %d"
)
netcdf_name = traits.Str(
desc="Name for netCDF (default derived from file name).", argstr="-n %s"
)
precision = traits.Either(
traits.Int(),
traits.Tuple(traits.Int, traits.Int),
desc="Display floating-point values with less precision",
argstr="%s",
) # See _format_arg in Dump for actual formatting.
class DumpOutputSpec(TraitedSpec):
output_file = File(desc="output file", exists=True)
class Dump(StdOutCommandLine):
"""Dump a MINC file. Typically used in conjunction with mincgen (see Gen).
Examples
--------
>>> from nipype.interfaces.minc import Dump
>>> from nipype.interfaces.minc.testdata import minc2Dfile
>>> dump = Dump(input_file=minc2Dfile)
>>> dump.run() # doctest: +SKIP
>>> dump = Dump(input_file=minc2Dfile, output_file='/tmp/out.txt', precision=(3, 4))
>>> dump.run() # doctest: +SKIP
"""
input_spec = DumpInputSpec
output_spec = DumpOutputSpec
_cmd = "mincdump"
def _format_arg(self, name, spec, value):
if name == "precision":
if isinstance(value, int):
return "-p %d" % value
elif (
isinstance(value, tuple)
and isinstance(value[0], int)
and isinstance(value[1], int)
):
return "-p %d,%d" % (value[0], value[1],)
else:
raise ValueError("Invalid precision argument: " + str(value))
return super(Dump, self)._format_arg(name, spec, value)
class AverageInputSpec(CommandLineInputSpec):
_xor_input_files = ("input_files", "filelist")
input_files = InputMultiPath(
File(exists=True),
desc="input file(s)",
mandatory=True,
sep=" ",
argstr="%s",
position=-2,
xor=_xor_input_files,
)
filelist = File(
desc="Specify the name of a file containing input file names.",
argstr="-filelist %s",
exists=True,
mandatory=True,
xor=_xor_input_files,
)
output_file = File(
desc="output file",
genfile=True,
argstr="%s",
position=-1,
name_source=["input_files"],
hash_files=False,
name_template="%s_averaged.mnc",
)
two = traits.Bool(desc="Create a MINC 2 output file.", argstr="-2")
clobber = traits.Bool(
desc="Overwrite existing file.",
argstr="-clobber",
usedefault=True,
default_value=True,
)
_xor_verbose = (
"verbose",
"quiet",
)
verbose = traits.Bool(
desc="Print out log messages (default).", argstr="-verbose", xor=_xor_verbose
)
quiet = traits.Bool(
desc="Do not print out log messages.", argstr="-quiet", xor=_xor_verbose
)
debug = traits.Bool(desc="Print out debugging messages.", argstr="-debug")
_xor_check_dimensions = (
"check_dimensions",
"no_check_dimensions",
)
check_dimensions = traits.Bool(
desc="Check that dimension info matches across files (default).",
argstr="-check_dimensions",
xor=_xor_check_dimensions,
)
no_check_dimensions = traits.Bool(
desc="Do not check dimension info.",
argstr="-nocheck_dimensions",
xor=_xor_check_dimensions,
)
_xor_format = (
"format_filetype",
"format_byte",
"format_short",
"format_int",
"format_long",
"format_float",
"format_double",
"format_signed",
"format_unsigned",
)
format_filetype = traits.Bool(
desc="Use data type of first file (default).",
argstr="-filetype",
xor=_xor_format,
)
format_byte = traits.Bool(
desc="Write out byte data.", argstr="-byte", xor=_xor_format
)
format_short = traits.Bool(
desc="Write out short integer data.", argstr="-short", xor=_xor_format
)
format_int = traits.Bool(
desc="Write out 32-bit integer data.", argstr="-int", xor=_xor_format
)
format_long = traits.Bool(
desc="Superseded by -int.", argstr="-long", xor=_xor_format
)
format_float = traits.Bool(
desc="Write out single-precision floating-point data.",
argstr="-float",
xor=_xor_format,
)
format_double = traits.Bool(
desc="Write out double-precision floating-point data.",
argstr="-double",
xor=_xor_format,
)
format_signed = traits.Bool(
desc="Write signed integer data.", argstr="-signed", xor=_xor_format
)
format_unsigned = traits.Bool(
desc="Write unsigned integer data (default).",
argstr="-unsigned",
xor=_xor_format,
)
max_buffer_size_in_kb = traits.Range(
low=0,
desc="Specify the maximum size of the internal buffers (in kbytes).",
value=4096,
usedefault=True,
argstr="-max_buffer_size_in_kb %d",
)
_xor_normalize = (
"normalize",
"nonormalize",
)
normalize = traits.Bool(
desc="Normalize data sets for mean intensity.",
argstr="-normalize",
xor=_xor_normalize,
)
nonormalize = traits.Bool(
desc="Do not normalize data sets (default).",
argstr="-nonormalize",
xor=_xor_normalize,
)
voxel_range = traits.Tuple(
traits.Int,
traits.Int,
argstr="-range %d %d",
desc="Valid range for output data.",
)
sdfile = File(desc="Specify an output sd file (default=none).", argstr="-sdfile %s")
_xor_copy_header = ("copy_header", "no_copy_header")
copy_header = traits.Bool(
desc="Copy all of the header from the first file (default for one file).",
argstr="-copy_header",
xor=_xor_copy_header,
)
no_copy_header = traits.Bool(
desc="Do not copy all of the header from the first file (default for many files)).",
argstr="-nocopy_header",
xor=_xor_copy_header,
)
avgdim = traits.Str(
desc="Specify a dimension along which we wish to average.", argstr="-avgdim %s"
)
binarize = traits.Bool(
desc="Binarize the volume by looking for values in a given range.",
argstr="-binarize",
)
binrange = traits.Tuple(
traits.Float,
traits.Float,
argstr="-binrange %s %s",
desc="Specify a range for binarization. Default value: 1.79769e+308 -1.79769e+308.",
)
binvalue = traits.Float(
desc=(
"Specify a target value (+/- 0.5) for"
"binarization. Default value: -1.79769e+308"
),
argstr="-binvalue %s",
)
weights = InputMultiPath(
traits.Str,
desc='Specify weights for averaging ("<w1>,<w2>,...").',
sep=",",
argstr="-weights %s",
)
width_weighted = traits.Bool(
desc="Weight by dimension widths when -avgdim is used.",
argstr="-width_weighted",
requires=("avgdim",),
)
class AverageOutputSpec(TraitedSpec):
output_file = File(desc="output file", exists=True)
class Average(CommandLine):
"""Average a number of MINC files.
Examples
--------
>>> from nipype.interfaces.minc import Average
>>> from nipype.interfaces.minc.testdata import nonempty_minc_data
>>> files = [nonempty_minc_data(i) for i in range(3)]
>>> average = Average(input_files=files, output_file='/tmp/tmp.mnc')
>>> average.run() # doctest: +SKIP
"""
input_spec = AverageInputSpec
output_spec = AverageOutputSpec
_cmd = "mincaverage"
class BlobInputSpec(CommandLineInputSpec):
input_file = File(
desc="input file to blob",
exists=True,
mandatory=True,
argstr="%s",
position=-2,
)
output_file = File(
desc="output file",
genfile=True,
argstr="%s",
position=-1,
name_source=["input_file"],
hash_files=False,
name_template="%s_blob.mnc",
)
trace = traits.Bool(
desc="compute the trace (approximate growth and shrinkage) -- FAST",
argstr="-trace",
)
determinant = traits.Bool(
desc="compute the determinant (exact growth and shrinkage) -- SLOW",
argstr="-determinant",
)
translation = traits.Bool(
desc="compute translation (structure displacement)", argstr="-translation"
)
magnitude = traits.Bool(
desc="compute the magnitude of the displacement vector", argstr="-magnitude"
)
class BlobOutputSpec(TraitedSpec):
output_file = File(desc="output file", exists=True)
class Blob(CommandLine):
"""Calculate blobs from minc deformation grids.
Examples
--------
>>> from nipype.interfaces.minc import Blob
>>> from nipype.interfaces.minc.testdata import minc2Dfile
>>> blob = Blob(input_file=minc2Dfile, output_file='/tmp/tmp.mnc', trace=True)
>>> blob.run() # doctest: +SKIP
"""
input_spec = BlobInputSpec
output_spec = BlobOutputSpec
_cmd = "mincblob"
class CalcInputSpec(CommandLineInputSpec):
_xor_input_files = ("input_files", "filelist")
input_files = InputMultiPath(