@@ -1453,6 +1453,188 @@ def _format_arg(self, name, spec, value):
14531453 return super (LocalBistat , self )._format_arg (name , spec , value )
14541454
14551455
1456+ class LocalstatInputSpec (AFNICommandInputSpec ):
1457+ in_file = File (
1458+ exists = True ,
1459+ mandatory = True ,
1460+ argstr = '%s' ,
1461+ position = - 1 ,
1462+ desc = 'input dataset' )
1463+ neighborhood = traits .Either (
1464+ traits .Tuple (traits .Enum ('SPHERE' , 'RHDD' , 'TOHD' ), traits .Float ()),
1465+ traits .Tuple (traits .Enum ('RECT' ), traits .Tuple (traits .Float (),
1466+ traits .Float (),
1467+ traits .Float ())),
1468+ mandatory = True ,
1469+ desc = 'The region around each voxel that will be extracted for '
1470+ 'the statistics calculation. Possible regions are: '
1471+ '\' SPHERE\' , \' RHDD\' (rhombic dodecahedron), \' TOHD\' '
1472+ '(truncated octahedron) with a given radius in mm or '
1473+ '\' RECT\' (rectangular block) with dimensions to specify in mm.' ,
1474+ argstr = "-nbhd '%s(%s)'" )
1475+ _stat_names = ['mean' , 'stdev' , 'var' , 'cvar' , 'median' , 'MAD' , 'min' ,
1476+ 'max' , 'absmax' , 'num' , 'sum' , 'FWHM' , 'FWHMbar' , 'rank' ,
1477+ 'frank' , 'P2skew' , 'ALL' , 'mMP2s' , 'mmMP2s' ]
1478+ stat = InputMultiObject (
1479+ traits .Either (
1480+ traits .Enum (_stat_names ),
1481+ traits .Tuple (traits .Enum ('perc' ),
1482+ traits .Tuple (traits .Float , traits .Float , traits .Float ))),
1483+ mandatory = True ,
1484+ desc = 'statistics to compute. Possible names are :'
1485+ ' * mean = average of the values'
1486+ ' * stdev = standard deviation'
1487+ ' * var = variance (stdev*stdev)'
1488+ ' * cvar = coefficient of variation = stdev/fabs(mean)'
1489+ ' * median = median of the values'
1490+ ' * MAD = median absolute deviation'
1491+ ' * min = minimum'
1492+ ' * max = maximum'
1493+ ' * absmax = maximum of the absolute values'
1494+ ' * num = number of the values in the region:'
1495+ ' with the use of -mask or -automask,'
1496+ ' the size of the region around any given'
1497+ ' voxel will vary; this option lets you'
1498+ ' map that size. It may be useful if you'
1499+ ' plan to compute a t-statistic (say) from'
1500+ ' the mean and stdev outputs.'
1501+ ' * sum = sum of the values in the region:'
1502+ ' * FWHM = compute (like 3dFWHM) image smoothness'
1503+ ' inside each voxel\' s neighborhood. Results'
1504+ ' are in 3 sub-bricks: FWHMx, FHWMy, and FWHMz.'
1505+ ' Places where an output is -1 are locations'
1506+ ' where the FWHM value could not be computed'
1507+ ' (e.g., outside the mask).'
1508+ ' * FWHMbar= Compute just the average of the 3 FWHM values'
1509+ ' (normally would NOT do this with FWHM also).'
1510+ ' * perc:P0:P1:Pstep = '
1511+ ' Compute percentiles between P0 and P1 with a '
1512+ ' step of Pstep.'
1513+ ' Default P1 is equal to P0 and default P2 = 1'
1514+ ' * rank = rank of the voxel\' s intensity'
1515+ ' * frank = rank / number of voxels in neighborhood'
1516+ ' * P2skew = Pearson\' s second skewness coefficient'
1517+ ' 3 * (mean - median) / stdev '
1518+ ' * ALL = all of the above, in that order '
1519+ ' (except for FWHMbar and perc).'
1520+ ' * mMP2s = Exactly the same output as:'
1521+ ' median, MAD, P2skew'
1522+ ' but it a little faster'
1523+ ' * mmMP2s = Exactly the same output as:'
1524+ ' mean, median, MAD, P2skew'
1525+ 'More than one option can be used.' ,
1526+ argstr = '-stat %s...' )
1527+ mask_file = traits .File (
1528+ exists = True ,
1529+ desc = 'Mask image file name. Voxels NOT in the mask will not be used '
1530+ 'in the neighborhood of any voxel. Also, a voxel NOT in the '
1531+ 'mask will have its statistic(s) computed as zero (0) unless '
1532+ 'the parameter \' nonmask\' is set to true.' ,
1533+ argstr = '-mask %s' )
1534+ automask = traits .Bool (
1535+ desc = 'Compute the mask as in program 3dAutomask.' ,
1536+ argstr = '-automask' )
1537+ nonmask = traits .Bool (
1538+ desc = 'Voxels not in the mask WILL have their local statistics '
1539+ 'computed from all voxels in their neighborhood that ARE in '
1540+ 'the mask.'
1541+ ' * For instance, this option can be used to compute the '
1542+ ' average local white matter time series, even at non-WM '
1543+ ' voxels.' ,
1544+ argstr = '-use_nonmask' )
1545+ reduce_grid = traits .Either (
1546+ traits .Float ,
1547+ traits .Tuple (traits .Float , traits .Float , traits .Float ),
1548+ argstr = '-reduce_grid %s' ,
1549+ desc = 'Compute output on a grid that is reduced by the specified '
1550+ 'factors. If a single value is passed, output is resampled '
1551+ 'to the specified isotropic grid. Otherwise, the 3 inputs '
1552+ 'describe the reduction in the X, Y, and Z directions. This '
1553+ 'option speeds up computations at the expense of resolution. '
1554+ 'It should only be used when the nbhd is quite large with '
1555+ 'respect to the input\' s resolution, and the resultant stats '
1556+ 'are expected to be smooth.' )
1557+ reduce_restore_grid = traits .Either (
1558+ traits .Float ,
1559+ traits .Tuple (traits .Float , traits .Float , traits .Float ),
1560+ argstr = '-reduce_restore_grid %s' ,
1561+ desc = 'Like reduce_grid, but also resample output back to input'
1562+ 'grid.' )
1563+ reduce_max_vox = traits .Float (
1564+ argstr = '-reduce_max_vox %s' ,
1565+ desc = 'Like reduce_restore_grid, but automatically set Rx Ry Rz so'
1566+ 'that the computation grid is at a resolution of nbhd/MAX_VOX'
1567+ 'voxels.' )
1568+ grid_rmode = traits .Enum (
1569+ 'NN' ,
1570+ 'Li' ,
1571+ 'Cu' ,
1572+ 'Bk' ,
1573+ argstr = 'grid_rmode %s' ,
1574+ desc = 'Interpolant to use when resampling the output with the'
1575+ 'reduce_restore_grid option. The resampling method string '
1576+ 'RESAM should come from the set {\' NN\' , \' Li\' , \' Cu\' , '
1577+ '\' Bk\' }. These stand for \' Nearest Neighbor\' , \' Linear\' , '
1578+ '\' Cubic\' , and \' Blocky\' interpolation, respectively.' )
1579+ quiet = traits .Bool (
1580+ argstr = '-quiet' ,
1581+ desc = 'Stop the highly informative progress reports.' )
1582+ overwrite = traits .Bool (
1583+ desc = 'overwrite output file if it already exists' ,
1584+ argstr = '-overwrite' )
1585+ out_file = traits .File (
1586+ desc = 'Output dataset.' ,
1587+ argstr = '-prefix %s' ,
1588+ name_source = 'in_file' ,
1589+ name_template = '%s_localstat' ,
1590+ keep_extension = True ,
1591+ position = 0 )
1592+
1593+
1594+ class Localstat (AFNICommand ):
1595+ """3dLocalstat - computes statistics at each voxel,
1596+ based on a local neighborhood of that voxel.
1597+ For complete details, see the `3dLocalstat Documentation.
1598+ <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dLocalstat.html>`_
1599+
1600+ Examples
1601+ ========
1602+
1603+ >>> from nipype.interfaces import afni
1604+ >>> localstat = afni.Localstat()
1605+ >>> localstat.inputs.in_file = 'bold.nii.gz'
1606+ >>> localstat.inputs.mask_file = 'label-WM_desc-eroded_roi.nii.gz'
1607+ >>> localstat.inputs.neighborhood = ('SPHERE', 45)
1608+ >>> localstat.inputs.stat = 'mean'
1609+ >>> localstat.inputs.nonmask=True
1610+ >>> localstat.inputs.outputtype = 'NIFTI_GZ'
1611+ >>> localstat.cmdline
1612+ "3dLocalstat -prefix bold_localstat.nii.gz \
1613+ -mask label-WM_desc-eroded_roi.nii.gz \
1614+ -nbhd 'SPHERE(45.0)' \
1615+ -use_nonmask \
1616+ -stat mean \
1617+ bold.nii.gz"
1618+ >>> wmlocal = localstat.run() # doctest: +SKIP
1619+
1620+ """
1621+
1622+ _cmd = '3dLocalstat'
1623+ input_spec = LocalstatInputSpec
1624+ output_spec = AFNICommandOutputSpec
1625+
1626+ def _format_arg (self , name , spec , value ):
1627+ if name == 'neighborhood' and value [0 ] == 'RECT' :
1628+ value = ('RECT' , '%s,%s,%s' % value [1 ])
1629+ if name == 'stat' :
1630+ value = ['perc:%s:%s:%s' % v [1 ] if len (v ) == 2 else v for v in value ]
1631+ if name == 'reduce_grid' or name == 'reduce_restore_grid' :
1632+ if len (value ) == 3 :
1633+ value = '%s %s %s' % value
1634+
1635+ return super (Localstat , self )._format_arg (name , spec , value )
1636+
1637+
14561638class MaskToolInputSpec (AFNICommandInputSpec ):
14571639 in_file = File (
14581640 desc = 'input file or files to 3dmask_tool' ,
0 commit comments