20
20
import warnings
21
21
import os
22
22
23
- from ..base import TraitedSpec , File , traits , isdefined , CommandLineInputSpec
24
- from .base import get_custom_path , NiftyRegCommand
23
+ from ..base import TraitedSpec , File , traits , isdefined
24
+ from .base import get_custom_path , NiftyRegCommand , NiftyRegCommandInputSpec
25
25
from ...utils .filemanip import split_filename
26
26
27
27
28
28
warn = warnings .warn
29
29
warnings .filterwarnings ('always' , category = UserWarning )
30
30
31
31
32
- class RegResampleInputSpec (CommandLineInputSpec ):
32
+ class RegResampleInputSpec (NiftyRegCommandInputSpec ):
33
33
""" Input Spec for RegResample. """
34
34
# Input reference file
35
35
ref_file = File (exists = True ,
@@ -53,7 +53,8 @@ class RegResampleInputSpec(CommandLineInputSpec):
53
53
desc = 'Type of output' )
54
54
55
55
# Output file name
56
- out_file = File (genfile = True ,
56
+ out_file = File (name_source = ['flo_file' ],
57
+ name_template = '%s' ,
57
58
argstr = '%s' ,
58
59
position = - 1 ,
59
60
desc = 'The output filename of the transformed image' )
@@ -80,10 +81,6 @@ class RegResampleInputSpec(CommandLineInputSpec):
80
81
estimating the PSF [0]'
81
82
psf_alg = traits .Enum (0 , 1 , argstr = '-psf_alg %d' , desc = desc )
82
83
83
- # Set the number of omp thread to use
84
- omp_core_val = traits .Int (desc = 'Number of openmp thread to use' ,
85
- argstr = '-omp %d' )
86
-
87
84
88
85
class RegResampleOutputSpec (TraitedSpec ):
89
86
""" Output Spec for RegResample. """
@@ -109,9 +106,9 @@ class RegResample(NiftyRegCommand):
109
106
>>> node.inputs.trans_file = 'warpfield.nii'
110
107
>>> node.inputs.inter_val = 'LIN'
111
108
>>> node.inputs.omp_core_val = 4
112
- >>> node.cmdline # doctest: +ELLIPSIS + ALLOW_UNICODE
109
+ >>> node.cmdline # doctest: +ALLOW_UNICODE
113
110
'reg_resample -flo im2.nii -inter 1 -omp 4 -ref im1.nii -trans \
114
- warpfield.nii -res .../ im2_res.nii.gz'
111
+ warpfield.nii -res im2_res.nii.gz'
115
112
116
113
"""
117
114
_cmd = get_custom_path ('reg_resample' )
@@ -126,15 +123,13 @@ def _format_arg(self, name, spec, value):
126
123
else :
127
124
return super (RegResample , self )._format_arg (name , spec , value )
128
125
129
- def _gen_filename (self , name ):
130
- if name == 'out_file' :
131
- return self ._gen_fname (self .inputs .flo_file ,
132
- suffix = '_%s' % self .inputs .type ,
133
- ext = '.nii.gz' )
134
- return None
126
+ def _overload_extension (self , value , name = None ):
127
+ path , base , _ = split_filename (value )
128
+ suffix = self .inputs .type
129
+ return os .path .join (path , '{0}_{1}.nii.gz' .format (base , suffix ))
135
130
136
131
137
- class RegJacobianInputSpec (CommandLineInputSpec ):
132
+ class RegJacobianInputSpec (NiftyRegCommandInputSpec ):
138
133
""" Input Spec for RegJacobian. """
139
134
# Reference file name
140
135
desc = 'Reference/target file (required if specifying CPP transformations.'
@@ -151,13 +146,11 @@ class RegJacobianInputSpec(CommandLineInputSpec):
151
146
argstr = '-%s' ,
152
147
position = - 2 ,
153
148
desc = 'Type of jacobian outcome' )
154
- out_file = File (genfile = True ,
149
+ out_file = File (name_source = ['trans_file' ],
150
+ name_template = '%s' ,
155
151
desc = 'The output jacobian determinant file name' ,
156
152
argstr = '%s' ,
157
153
position = - 1 )
158
- # Set the number of omp thread to use
159
- omp_core_val = traits .Int (desc = 'Number of openmp thread to use' ,
160
- argstr = '-omp %i' )
161
154
162
155
163
156
class RegJacobianOutputSpec (TraitedSpec ):
@@ -180,24 +173,22 @@ class RegJacobian(NiftyRegCommand):
180
173
>>> node.inputs.ref_file = 'im1.nii'
181
174
>>> node.inputs.trans_file = 'warpfield.nii'
182
175
>>> node.inputs.omp_core_val = 4
183
- >>> node.cmdline # doctest: +ELLIPSIS + ALLOW_UNICODE
176
+ >>> node.cmdline # doctest: +ALLOW_UNICODE
184
177
'reg_jacobian -omp 4 -ref im1.nii -trans warpfield.nii -jac \
185
- .../ warpfield_jac.nii.gz'
178
+ warpfield_jac.nii.gz'
186
179
187
180
"""
188
181
_cmd = get_custom_path ('reg_jacobian' )
189
182
input_spec = RegJacobianInputSpec
190
183
output_spec = RegJacobianOutputSpec
191
184
192
- def _gen_filename (self , name ):
193
- if name == 'out_file' :
194
- return self ._gen_fname (self .inputs .trans_file ,
195
- suffix = '_%s' % self .inputs .type ,
196
- ext = '.nii.gz' )
197
- return None
185
+ def _overload_extension (self , value , name = None ):
186
+ path , base , _ = split_filename (value )
187
+ suffix = self .inputs .type
188
+ return os .path .join (path , '{0}_{1}.nii.gz' .format (base , suffix ))
198
189
199
190
200
- class RegToolsInputSpec (CommandLineInputSpec ):
191
+ class RegToolsInputSpec (NiftyRegCommandInputSpec ):
201
192
""" Input Spec for RegTools. """
202
193
# Input image file
203
194
in_file = File (exists = True ,
@@ -276,10 +267,6 @@ class RegToolsInputSpec(CommandLineInputSpec):
276
267
desc = desc ,
277
268
argstr = '-smoG %f %f %f' )
278
269
279
- # Set the number of omp thread to use
280
- omp_core_val = traits .Int (desc = 'Number of openmp thread to use' ,
281
- argstr = '-omp %i' )
282
-
283
270
284
271
class RegToolsOutputSpec (TraitedSpec ):
285
272
""" Output Spec for RegTools. """
@@ -312,7 +299,7 @@ class RegTools(NiftyRegCommand):
312
299
_suffix = '_tools'
313
300
314
301
315
- class RegAverageInputSpec (CommandLineInputSpec ):
302
+ class RegAverageInputSpec (NiftyRegCommandInputSpec ):
316
303
""" Input Spec for RegAverage. """
317
304
avg_files = traits .List (File (exist = True ),
318
305
position = 1 ,
@@ -424,10 +411,11 @@ def _gen_filename(self, name):
424
411
if isdefined (self .inputs .avg_lts_files ):
425
412
return self ._gen_fname (self ._suffix , ext = '.txt' )
426
413
elif isdefined (self .inputs .avg_files ):
427
- _ , _ , ext = split_filename (self .inputs .avg_files [0 ])
428
- if ext not in ['.nii' , '.nii.gz' , '.hdr' , '.img' , '.img.gz' ]:
429
- return self ._gen_fname (self ._suffix , ext = ext )
414
+ _ , _ , _ext = split_filename (self .inputs .avg_files [0 ])
415
+ if _ext not in ['.nii' , '.nii.gz' , '.hdr' , '.img' , '.img.gz' ]:
416
+ return self ._gen_fname (self ._suffix , ext = _ext )
430
417
return self ._gen_fname (self ._suffix , ext = '.nii.gz' )
418
+
431
419
return None
432
420
433
421
@property
@@ -440,7 +428,7 @@ def cmdline(self):
440
428
return '%s --cmd_file %s' % (self .cmd , reg_average_cmd )
441
429
442
430
443
- class RegTransformInputSpec (CommandLineInputSpec ):
431
+ class RegTransformInputSpec (NiftyRegCommandInputSpec ):
444
432
""" Input Spec for RegTransform. """
445
433
ref1_file = File (exists = True ,
446
434
desc = 'The input reference/target image' ,
@@ -584,15 +572,10 @@ class RegTransformInputSpec(CommandLineInputSpec):
584
572
argstr = '%s' ,
585
573
desc = 'transformation file to write' )
586
574
587
- # Set the number of omp thread to use
588
- omp_core_val = traits .Int (desc = 'Number of openmp thread to use' ,
589
- argstr = '-omp %i' )
590
-
591
575
592
576
class RegTransformOutputSpec (TraitedSpec ):
593
577
""" Output Spec for RegTransform. """
594
- desc = 'Output File (transformation in any format)'
595
- out_file = File (exists = True , desc = desc )
578
+ out_file = File (desc = 'Output File (transformation in any format)' )
596
579
597
580
598
581
class RegTransform (NiftyRegCommand ):
@@ -679,7 +662,7 @@ def _list_outputs(self):
679
662
return outputs
680
663
681
664
682
- class RegMeasureInputSpec (CommandLineInputSpec ):
665
+ class RegMeasureInputSpec (NiftyRegCommandInputSpec ):
683
666
""" Input Spec for RegMeasure. """
684
667
# Input reference file
685
668
ref_file = File (exists = True ,
@@ -695,12 +678,10 @@ class RegMeasureInputSpec(CommandLineInputSpec):
695
678
mandatory = True ,
696
679
argstr = '-%s' ,
697
680
desc = 'Measure of similarity to compute' )
698
- out_file = File (genfile = True ,
681
+ out_file = File (name_source = ['flo_file' ],
682
+ name_template = '%s' ,
699
683
argstr = '-out %s' ,
700
684
desc = 'The output text file containing the measure' )
701
- # Set the number of omp thread to use
702
- omp_core_val = traits .Int (desc = 'Number of openmp thread to use' ,
703
- argstr = '-omp %i' )
704
685
705
686
706
687
class RegMeasureOutputSpec (TraitedSpec ):
@@ -723,17 +704,15 @@ class RegMeasure(NiftyRegCommand):
723
704
>>> node.inputs.flo_file = 'im2.nii'
724
705
>>> node.inputs.measure_type = 'lncc'
725
706
>>> node.inputs.omp_core_val = 4
726
- >>> node.cmdline # doctest: +ELLIPSIS + ALLOW_UNICODE
727
- 'reg_measure -flo im2.nii -lncc -omp 4 -out .../ im2_lncc.txt -ref im1.nii'
707
+ >>> node.cmdline # doctest: +ALLOW_UNICODE
708
+ 'reg_measure -flo im2.nii -lncc -omp 4 -out im2_lncc.txt -ref im1.nii'
728
709
729
710
"""
730
711
_cmd = get_custom_path ('reg_measure' )
731
712
input_spec = RegMeasureInputSpec
732
713
output_spec = RegMeasureOutputSpec
733
714
734
- def _gen_filename (self , name ):
735
- if name == 'out_file' :
736
- return self ._gen_fname (self .inputs .flo_file ,
737
- suffix = '_%s' % self .inputs .measure_type ,
738
- ext = '.txt' )
739
- return None
715
+ def _overload_extension (self , value , name = None ):
716
+ path , base , _ = split_filename (value )
717
+ suffix = self .inputs .measure_type
718
+ return os .path .join (path , '{0}_{1}.txt' .format (base , suffix ))
0 commit comments