Skip to content

Commit 758dbcc

Browse files
committed
ENH: Add workbench interfaces
1 parent 93732b0 commit 758dbcc

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

nibabies/interfaces/workbench.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,3 +1570,114 @@ class CreateSignedDistanceVolume(WBCommand):
15701570
input_spec = CreateSignedDistanceVolumeInputSpec
15711571
output_spec = CreateSignedDistanceVolumeOutputSpec
15721572
_cmd = "wb_command -create-signed-distance-volume"
1573+
1574+
1575+
class SurfaceAverageInputSpec(CommandLineInputSpec):
1576+
out_file = File(
1577+
name_template="averaged.surf.gii",
1578+
position=0,
1579+
desc="output file",
1580+
)
1581+
surfaces = InputMultiObject(
1582+
traits.Either(
1583+
File(exists=True),
1584+
traits.Tuple(File(exists=True), traits.Float),
1585+
),
1586+
argstr="%s",
1587+
position=3,
1588+
desc="Surface, or surface and weighted average tuple, to include in the average",
1589+
)
1590+
1591+
1592+
class SurfaceAverageOutputSpec(TraitedSpec):
1593+
out_file = File(desc="The output averaged surface")
1594+
# stddev_metric = File(desc="The output metric for 3D sample standard deviation")
1595+
# uncert_metric = File(desc="The output metric for uncertainty")
1596+
1597+
1598+
class SurfaceAverage(WBCommand):
1599+
"""
1600+
AVERAGE SURFACE FILES TOGETHER
1601+
wb_command -surface-average
1602+
<surface-out> - output - the output averaged surface
1603+
1604+
[-stddev] - compute 3D sample standard deviation
1605+
<stddev-metric-out> - output - the output metric for 3D sample
1606+
standard deviation
1607+
1608+
[-uncertainty] - compute caret5 'uncertainty'
1609+
<uncert-metric-out> - output - the output metric for uncertainty
1610+
1611+
[-surf] - repeatable - specify a surface to include in the average
1612+
<surface> - a surface file to average
1613+
1614+
[-weight] - specify a weighted average
1615+
<weight> - the weight to use (default 1)
1616+
1617+
The 3D sample standard deviation is computed as
1618+
'sqrt(sum(squaredlength(xyz - mean(xyz)))/(n - 1))'.
1619+
1620+
Uncertainty is a legacy measure used in caret5, and is computed as
1621+
'sum(length(xyz - mean(xyz)))/n'.
1622+
1623+
When weights are used, the 3D sample standard deviation treats them as
1624+
reliability weights.
1625+
"""
1626+
1627+
input_spec = SurfaceAverageInputSpec
1628+
output_spec = SurfaceAverageOutputSpec
1629+
_cmd = "wb_command -surface-average"
1630+
1631+
def _format_arg(self, name, trait_spec, value):
1632+
if name == 'surfaces':
1633+
cmd = []
1634+
for val in value:
1635+
if len(val) == 2:
1636+
cmd.append(f"{val[0]} -weight {val[-1]}")
1637+
else:
1638+
cmd.append(val)
1639+
return '-surf ' + ' -surf '.join(cmd)
1640+
return super()._format_arg(name, trait_spec, value)
1641+
1642+
def _list_output(self):
1643+
outputs = self.output_spec().get()
1644+
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
1645+
return outputs
1646+
1647+
1648+
class SurfaceVertexAreasInputSpec(CommandLineInputSpec):
1649+
in_file = File(
1650+
exists=True,
1651+
mandatory=True,
1652+
position=0,
1653+
argstr="%s",
1654+
desc="Input surface",
1655+
)
1656+
out_file = File(
1657+
name_template="%s_va.shape",
1658+
name_source="in_file",
1659+
keep_extension=True,
1660+
position=1,
1661+
argstr="%s",
1662+
desc="Output vertex areas",
1663+
)
1664+
1665+
1666+
class SurfaceVertexAreasOutputSpec(TraitedSpec):
1667+
out_file = File(desc="Output vertex areas")
1668+
1669+
1670+
class SurfaceVertexAreas(WBCommand):
1671+
"""
1672+
MEASURE SURFACE AREA EACH VERTEX IS RESPONSIBLE FOR
1673+
wb_command -surface-vertex-areas
1674+
<surface> - the surface to measure
1675+
<metric> - output - the output metric
1676+
1677+
Each vertex gets one third of the area of each triangle it is a part of.
1678+
Units are mm^2.
1679+
"""
1680+
1681+
input_spec = SurfaceVertexAreasInputSpec
1682+
output_spec = SurfaceVertexAreasOutputSpec
1683+
_cmd = "wb_command -surface-vertex-areas"

0 commit comments

Comments
 (0)