@@ -1316,39 +1316,45 @@ def init_anat_ribbon_wf(name='anat_ribbon_wf'):
1316
1316
return workflow
1317
1317
1318
1318
1319
- def init_resample_midthickness_wf (
1319
+ def init_resample_surfaces_wf (
1320
+ surfaces : list [str ],
1320
1321
grayord_density : ty .Literal ['91k' , '170k' ],
1321
- name : str = 'resample_midthickness_wf ' ,
1322
+ name : str = 'resample_surfaces_wf ' ,
1322
1323
):
1323
1324
"""
1324
- Resample subject midthickness surface to specified density.
1325
+ Resample subject surfaces surface to specified density.
1325
1326
1326
1327
Workflow Graph
1327
1328
.. workflow::
1328
1329
:graph2use: colored
1329
1330
:simple_form: yes
1330
1331
1331
- from smriprep.workflows.surfaces import init_resample_midthickness_wf
1332
- wf = init_resample_midthickness_wf(grayord_density="91k")
1332
+ from smriprep.workflows.surfaces import init_resample_surfaces_wf
1333
+ wf = init_resample_surfaces_wf(
1334
+ surfaces=['white', 'pial', 'midthickness'],
1335
+ grayord_density='91k',
1336
+ )
1333
1337
1334
1338
Parameters
1335
1339
----------
1336
- grayord_density : :obj:`str`
1340
+ surfaces : :class:`list` of :class:`str`
1341
+ Names of surfaces (e.g., ``'white'``) to resample. Both hemispheres will be resampled.
1342
+ grayord_density : :class:`str`
1337
1343
Either `91k` or `170k`, representing the total of vertices or *grayordinates*.
1338
- name : :obj :`str`
1339
- Unique name for the subworkflow (default: ``"resample_midthickness_wf "``)
1344
+ name : :class :`str`
1345
+ Unique name for the subworkflow (default: ``"resample_surfaces_wf "``)
1340
1346
1341
1347
Inputs
1342
1348
------
1343
- midthickness
1344
- GIFTI surface mesh corresponding to the midthickness surface
1349
+ ``<surface>``
1350
+ Left and right GIFTIs for each surface name passed to ``surfaces``
1345
1351
sphere_reg_fsLR
1346
1352
GIFTI surface mesh corresponding to the subject's fsLR registration sphere
1347
1353
1348
1354
Outputs
1349
1355
-------
1350
- midthickness
1351
- GIFTI surface mesh corresponding to the midthickness surface, resampled to fsLR
1356
+ ``<surface>``
1357
+ Left and right GIFTI surface mesh corresponding to the input surface, resampled to fsLR
1352
1358
"""
1353
1359
import templateflow .api as tf
1354
1360
from niworkflows .engine .workflows import LiterateWorkflow as Workflow
@@ -1358,11 +1364,19 @@ def init_resample_midthickness_wf(
1358
1364
fslr_density = '32k' if grayord_density == '91k' else '59k'
1359
1365
1360
1366
inputnode = pe .Node (
1361
- niu .IdentityInterface (fields = ['midthickness' , 'sphere_reg_fsLR' ]),
1367
+ niu .IdentityInterface (fields = [* surfaces , 'sphere_reg_fsLR' ]),
1362
1368
name = 'inputnode' ,
1363
1369
)
1364
1370
1365
- outputnode = pe .Node (niu .IdentityInterface (fields = ['midthickness_fsLR' ]), name = 'outputnode' )
1371
+ outputnode = pe .Node (
1372
+ niu .IdentityInterface (fields = [f'{ surf } _fsLR' for surf in surfaces ]), name = 'outputnode'
1373
+ )
1374
+
1375
+ surface_list = pe .Node (
1376
+ niu .Merge (len (surfaces ), ravel_inputs = True ),
1377
+ name = 'surface_list' ,
1378
+ run_without_submitting = True ,
1379
+ )
1366
1380
1367
1381
resampler = pe .MapNode (
1368
1382
SurfaceResample (method = 'BARYCENTRIC' ),
@@ -1380,15 +1394,30 @@ def init_resample_midthickness_wf(
1380
1394
extension = '.surf.gii' ,
1381
1395
)
1382
1396
)
1397
+ # Order matters. Iterate over surfaces, then hemis to get L R L R L R
1398
+ for _surf in surfaces
1383
1399
for hemi in ['L' , 'R' ]
1384
1400
]
1385
1401
1402
+ surface_groups = pe .Node (
1403
+ niu .Split (splits = [2 ] * len (surfaces )),
1404
+ name = 'surface_groups' ,
1405
+ run_without_submitting = True ,
1406
+ )
1407
+
1386
1408
workflow .connect ([
1409
+ (inputnode , surface_list , [
1410
+ ((surf , _sorted_by_basename ), f'in{ i } ' )
1411
+ for i , surf in enumerate (surfaces , start = 1 )
1412
+ ]),
1387
1413
(inputnode , resampler , [
1388
- ('midthickness' , 'surface_in' ),
1389
- ('sphere_reg_fsLR' , 'current_sphere' ),
1414
+ (('sphere_reg_fsLR' , _repeat , len (surfaces )), 'current_sphere' ),
1415
+ ]),
1416
+ (surface_list , resampler , [('out' , 'surface_in' )]),
1417
+ (resampler , surface_groups , [('surface_out' , 'inlist' )]),
1418
+ (surface_groups , outputnode , [
1419
+ (f'out{ i } ' , f'{ surf } _fsLR' ) for i , surf in enumerate (surfaces , start = 1 )
1390
1420
]),
1391
- (resampler , outputnode , [('surface_out' , 'midthickness_fsLR' )]),
1392
1421
]) # fmt:skip
1393
1422
1394
1423
return workflow
@@ -1678,3 +1707,7 @@ def _select_seg(in_files, segmentation):
1678
1707
if segmentation in fl :
1679
1708
return fl
1680
1709
raise FileNotFoundError (f'No segmentation containing "{ segmentation } " was found.' )
1710
+
1711
+
1712
+ def _repeat (seq : list , count : int ) -> list :
1713
+ return seq * count
0 commit comments