@@ -1513,6 +1513,80 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
1513
1513
return outputs
1514
1514
1515
1515
1516
+ class ClipLevelInputSpec (CommandLineInputSpec ):
1517
+ in_file = File (desc = 'input file to 3dClipLevel' ,
1518
+ argstr = '%s' ,
1519
+ position = - 1 ,
1520
+ mandatory = True ,
1521
+ exists = True )
1522
+
1523
+ mfrac = traits .Float (desc = 'Use the number ff instead of 0.50 in the algorithm' ,
1524
+ argstr = '-mfrac %s' ,
1525
+ position = 2 )
1526
+
1527
+ doall = traits .Bool (desc = 'Apply the algorithm to each sub-brick separately' ,
1528
+ argstr = '-doall' ,
1529
+ position = 3 ,
1530
+ xor = ('grad' ))
1531
+
1532
+ grad = traits .File (desc = 'also compute a \' gradual\' clip level as a function of voxel position, and output that to a dataset' ,
1533
+ argstr = '-grad %s' ,
1534
+ position = 3 ,
1535
+ xor = ('doall' ))
1536
+
1537
+
1538
+ class ClipLevelOutputSpec (TraitedSpec ):
1539
+ clip_val = traits .Float (desc = 'output' )
1540
+
1541
+
1542
+ class ClipLevel (AFNICommandBase ):
1543
+ """Compute maximum and/or minimum voxel values of an input dataset
1544
+
1545
+ For complete details, see the `3dClipLevel Documentation.
1546
+ <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dClipLevel.html>`_
1547
+
1548
+ Examples
1549
+ ========
1550
+
1551
+ >>> from nipype.interfaces.afni import preprocess
1552
+ >>> cliplevel = preprocess.ClipLevel()
1553
+ >>> cliplevel.inputs.in_file = 'anatomical.nii'
1554
+ >>> res = cliplevel.run() # doctest: +SKIP
1555
+
1556
+ """
1557
+ _cmd = '3dClipLevel'
1558
+ input_spec = ClipLevelInputSpec
1559
+ output_spec = ClipLevelOutputSpec
1560
+
1561
+ def aggregate_outputs (self , runtime = None , needed_outputs = None ):
1562
+
1563
+ outputs = self ._outputs ()
1564
+
1565
+ outfile = os .path .join (os .getcwd (), 'stat_result.json' )
1566
+
1567
+ if runtime is None :
1568
+ try :
1569
+ clip_val = load_json (outfile )['stat' ]
1570
+ except IOError :
1571
+ return self .run ().outputs
1572
+ else :
1573
+ clip_val = []
1574
+ for line in runtime .stdout .split ('\n ' ):
1575
+ if line :
1576
+ values = line .split ()
1577
+ if len (values ) > 1 :
1578
+ clip_val .append ([float (val ) for val in values ])
1579
+ else :
1580
+ clip_val .extend ([float (val ) for val in values ])
1581
+
1582
+ if len (clip_val ) == 1 :
1583
+ clip_val = clip_val [0 ]
1584
+ save_json (outfile , dict (stat = clip_val ))
1585
+ outputs .clip_val = clip_val
1586
+
1587
+ return outputs
1588
+
1589
+
1516
1590
class ROIStatsInputSpec (CommandLineInputSpec ):
1517
1591
in_file = File (desc = 'input file to 3dROIstats' ,
1518
1592
argstr = '%s' ,
0 commit comments