@@ -1316,39 +1316,45 @@ def init_anat_ribbon_wf(name='anat_ribbon_wf'):
13161316 return workflow
13171317
13181318
1319- def init_resample_midthickness_wf (
1319+ def init_resample_surfaces_wf (
1320+ surfaces : list [str ],
13201321 grayord_density : ty .Literal ['91k' , '170k' ],
1321- name : str = 'resample_midthickness_wf ' ,
1322+ name : str = 'resample_surfaces_wf ' ,
13221323):
13231324 """
1324- Resample subject midthickness surface to specified density.
1325+ Resample subject surfaces surface to specified density.
13251326
13261327 Workflow Graph
13271328 .. workflow::
13281329 :graph2use: colored
13291330 :simple_form: yes
13301331
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+ )
13331337
13341338 Parameters
13351339 ----------
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`
13371343 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 "``)
13401346
13411347 Inputs
13421348 ------
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``
13451351 sphere_reg_fsLR
13461352 GIFTI surface mesh corresponding to the subject's fsLR registration sphere
13471353
13481354 Outputs
13491355 -------
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
13521358 """
13531359 import templateflow .api as tf
13541360 from niworkflows .engine .workflows import LiterateWorkflow as Workflow
@@ -1358,11 +1364,19 @@ def init_resample_midthickness_wf(
13581364 fslr_density = '32k' if grayord_density == '91k' else '59k'
13591365
13601366 inputnode = pe .Node (
1361- niu .IdentityInterface (fields = ['midthickness' , 'sphere_reg_fsLR' ]),
1367+ niu .IdentityInterface (fields = [* surfaces , 'sphere_reg_fsLR' ]),
13621368 name = 'inputnode' ,
13631369 )
13641370
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+ )
13661380
13671381 resampler = pe .MapNode (
13681382 SurfaceResample (method = 'BARYCENTRIC' ),
@@ -1380,15 +1394,30 @@ def init_resample_midthickness_wf(
13801394 extension = '.surf.gii' ,
13811395 )
13821396 )
1397+ # Order matters. Iterate over surfaces, then hemis to get L R L R L R
1398+ for _surf in surfaces
13831399 for hemi in ['L' , 'R' ]
13841400 ]
13851401
1402+ surface_groups = pe .Node (
1403+ niu .Split (splits = [2 ] * len (surfaces )),
1404+ name = 'surface_groups' ,
1405+ run_without_submitting = True ,
1406+ )
1407+
13861408 workflow .connect ([
1409+ (inputnode , surface_list , [
1410+ ((surf , _sorted_by_basename ), f'in{ i } ' )
1411+ for i , surf in enumerate (surfaces , start = 1 )
1412+ ]),
13871413 (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 )
13901420 ]),
1391- (resampler , outputnode , [('surface_out' , 'midthickness_fsLR' )]),
13921421 ]) # fmt:skip
13931422
13941423 return workflow
@@ -1678,3 +1707,7 @@ def _select_seg(in_files, segmentation):
16781707 if segmentation in fl :
16791708 return fl
16801709 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