2
2
import os
3
3
from glob import glob
4
4
from ...external .due import BibTeX
5
+ from ...utils .imagemanip import copy_header as _copy_header
5
6
from ...utils .filemanip import split_filename , copyfile , which , fname_presuffix
6
7
from ..base import TraitedSpec , File , traits , InputMultiPath , OutputMultiPath , isdefined
7
8
from .base import ANTSCommand , ANTSCommandInputSpec
@@ -235,7 +236,6 @@ def _gen_filename(self, name):
235
236
_ , name , ext = split_filename (self .inputs .intensity_images [0 ])
236
237
output = name + "_labeled" + ext
237
238
return output
238
- return None
239
239
240
240
def _list_outputs (self ):
241
241
outputs = self ._outputs ().get ()
@@ -538,24 +538,15 @@ def _list_outputs(self):
538
538
539
539
# Fix headers
540
540
if self .inputs .copy_header :
541
- self ._copy_header (outputs ["output_image" ])
541
+ _copy_header (self .inputs .input_image , outputs ["output_image" ],
542
+ keep_dtype = False )
542
543
543
544
if self ._out_bias_file :
544
545
outputs ["bias_image" ] = os .path .abspath (self ._out_bias_file )
545
546
if self .inputs .copy_header :
546
- self . _copy_header (outputs ["bias_image" ])
547
+ _copy_header (self . inputs . input_image , outputs ["bias_image" ])
547
548
return outputs
548
549
549
- def _copy_header (self , fname ):
550
- """Copy header from input image to an output image."""
551
- import nibabel as nb
552
-
553
- in_img = nb .load (self .inputs .input_image )
554
- out_img = nb .load (fname , mmap = False )
555
- new_img = out_img .__class__ (out_img .get_fdata (), in_img .affine , in_img .header )
556
- new_img .set_data_dtype (out_img .get_data_dtype ())
557
- new_img .to_filename (fname )
558
-
559
550
560
551
class CorticalThicknessInputSpec (ANTSCommandInputSpec ):
561
552
dimension = traits .Enum (
@@ -1500,55 +1491,44 @@ def _format_arg(self, opt, spec, val):
1500
1491
self .inputs .exclusion_image [ii ],
1501
1492
)
1502
1493
)
1503
- retval = " " .join (retval )
1504
- elif opt == "patch_radius" :
1505
- retval = "-p {0}" .format (self ._format_xarray (val ))
1506
- elif opt == "search_radius" :
1507
- retval = "-s {0}" .format (self ._format_xarray (val ))
1508
- elif opt == "out_label_fusion" :
1509
- if isdefined (self .inputs .out_intensity_fusion_name_format ):
1510
- if isdefined (self .inputs .out_label_post_prob_name_format ):
1511
- if isdefined (self .inputs .out_atlas_voting_weight_name_format ):
1512
- retval = "-o [{0}, {1}, {2}, {3}]" .format (
1513
- self .inputs .out_label_fusion ,
1514
- self .inputs .out_intensity_fusion_name_format ,
1515
- self .inputs .out_label_post_prob_name_format ,
1516
- self .inputs .out_atlas_voting_weight_name_format ,
1517
- )
1518
- else :
1519
- retval = "-o [{0}, {1}, {2}]" .format (
1520
- self .inputs .out_label_fusion ,
1521
- self .inputs .out_intensity_fusion_name_format ,
1522
- self .inputs .out_label_post_prob_name_format ,
1523
- )
1494
+ return " " .join (retval )
1495
+ if opt == "patch_radius" :
1496
+ return "-p {0}" .format (self ._format_xarray (val ))
1497
+ if opt == "search_radius" :
1498
+ return "-s {0}" .format (self ._format_xarray (val ))
1499
+ if opt == "out_label_fusion" :
1500
+ args = [self .inputs .out_label_fusion ]
1501
+ for option in (
1502
+ self .inputs .out_intensity_fusion_name_format ,
1503
+ self .inputs .out_label_post_prob_name_format ,
1504
+ self .inputs .out_atlas_voting_weight_name_format
1505
+ ):
1506
+ if isdefined (option ):
1507
+ args .append (option )
1524
1508
else :
1525
- retval = "-o [{0}, {1}]" .format (
1526
- self .inputs .out_label_fusion ,
1527
- self .inputs .out_intensity_fusion_name_format ,
1528
- )
1529
- else :
1530
- retval = "-o {0}" .format (self .inputs .out_label_fusion )
1531
- elif opt == "out_intensity_fusion_name_format" :
1532
- retval = ""
1509
+ break
1510
+ if len (args ) == 1 :
1511
+ return " " .join (("-o" , args [0 ]))
1512
+ return "-o [{}]" .format (", " .join (args ))
1513
+ if opt == "out_intensity_fusion_name_format" :
1533
1514
if not isdefined (self .inputs .out_label_fusion ):
1534
- retval = "-o {0}" .format (self .inputs .out_intensity_fusion_name_format )
1535
- elif opt == "atlas_image" :
1536
- atlas_image_cmd = " " .join (
1515
+ return "-o {0}" .format (self .inputs .out_intensity_fusion_name_format )
1516
+ return ""
1517
+ if opt == "atlas_image" :
1518
+ return " " .join (
1537
1519
[
1538
1520
"-g [{0}]" .format (", " .join ("'%s'" % fn for fn in ai ))
1539
1521
for ai in self .inputs .atlas_image
1540
1522
]
1541
1523
)
1542
- retval = atlas_image_cmd
1543
- elif opt == "target_image" :
1544
- target_image_cmd = " " .join (
1524
+ if opt == "target_image" :
1525
+ return " " .join (
1545
1526
[
1546
1527
"-t [{0}]" .format (", " .join ("'%s'" % fn for fn in ai ))
1547
1528
for ai in self .inputs .target_image
1548
1529
]
1549
1530
)
1550
- retval = target_image_cmd
1551
- elif opt == "atlas_segmentation_image" :
1531
+ if opt == "atlas_segmentation_image" :
1552
1532
if len (val ) != len (self .inputs .atlas_image ):
1553
1533
raise ValueError (
1554
1534
"Number of specified segmentations should be identical to the number "
@@ -1557,14 +1537,10 @@ def _format_arg(self, opt, spec, val):
1557
1537
)
1558
1538
)
1559
1539
1560
- atlas_segmentation_image_cmd = " " .join (
1540
+ return " " .join (
1561
1541
["-l {0}" .format (fn ) for fn in self .inputs .atlas_segmentation_image ]
1562
1542
)
1563
- retval = atlas_segmentation_image_cmd
1564
- else :
1565
-
1566
- return super (AntsJointFusion , self )._format_arg (opt , spec , val )
1567
- return retval
1543
+ return super (AntsJointFusion , self )._format_arg (opt , spec , val )
1568
1544
1569
1545
def _list_outputs (self ):
1570
1546
outputs = self ._outputs ().get ()
@@ -1805,8 +1781,6 @@ def _gen_filename(self, name):
1805
1781
output = name + "_warped_white_matter" + ext
1806
1782
return output
1807
1783
1808
- return None
1809
-
1810
1784
def _format_arg (self , opt , spec , val ):
1811
1785
if opt == "segmentation_image" :
1812
1786
newval = "[{0},{1},{2}]" .format (
0 commit comments