Skip to content

Commit 09818d7

Browse files
committed
MAINT: Bring fsLR surface resampling in line with current smriprep
1 parent 9acda6b commit 09818d7

File tree

4 files changed

+81
-23
lines changed

4 files changed

+81
-23
lines changed

nibabies/workflows/anatomical/apply.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
from smriprep.workflows.surfaces import (
1212
init_hcp_morphometrics_wf,
1313
init_morph_grayords_wf,
14-
init_resample_midthickness_wf,
14+
init_resample_surfaces_wf,
1515
init_surface_derivatives_wf,
1616
)
1717

1818
from nibabies import config
1919
from nibabies.workflows.anatomical.outputs import init_ds_seg_wf
20-
from nibabies.workflows.anatomical.surfaces import init_resample_midthickness_dhcp_wf
20+
from nibabies.workflows.anatomical.surfaces import init_resample_surfaces_dhcp_wf
2121

2222
if ty.TYPE_CHECKING:
2323
from niworkflows.utils.spaces import SpatialReferences
@@ -57,6 +57,8 @@ def init_infant_anat_apply_wf(
5757
'sulc',
5858
'template',
5959
'thickness',
60+
'white',
61+
'pial',
6062
'midthickness',
6163
reg_sphere,
6264
# template workflow inputs
@@ -185,17 +187,28 @@ def init_infant_anat_apply_wf(
185187
if cifti_output:
186188
hcp_morphometrics_wf = init_hcp_morphometrics_wf(omp_nthreads=omp_nthreads)
187189
if recon_method == 'mcribs':
188-
resample_midthickness_wf = init_resample_midthickness_dhcp_wf(
189-
grayord_density=cifti_output
190+
resample_surfaces_wf = init_resample_surfaces_dhcp_wf(
191+
surfaces=['white', 'pial', 'midthickness'],
192+
grayord_density=cifti_output,
190193
)
191194
else:
192-
resample_midthickness_wf = init_resample_midthickness_wf(
193-
grayord_density=cifti_output
195+
resample_surfaces_wf = init_resample_surfaces_wf(
196+
surfaces=['white', 'pial', 'midthickness'], grayord_density=cifti_output
194197
)
195198
morph_grayords_wf = init_morph_grayords_wf(
196199
grayord_density=cifti_output, omp_nthreads=omp_nthreads
197200
)
198201

202+
ds_fsLR_surfaces_wf = init_ds_surfaces_wf(
203+
output_dir=output_dir,
204+
surfaces=['white', 'pial', 'midthickness'],
205+
entities={
206+
'space': 'dhcpAsym' if recon_method == 'mcribs' else 'fsLR',
207+
'density': '32k' if cifti_output == '91k' else '59k',
208+
},
209+
name='ds_fsLR_surfaces_wf',
210+
)
211+
199212
ds_grayord_metrics_wf = init_ds_grayord_metrics_wf(
200213
bids_root=bids_root,
201214
output_dir=output_dir,
@@ -213,7 +226,9 @@ def init_infant_anat_apply_wf(
213226
(surface_derivatives_wf, hcp_morphometrics_wf, [
214227
('outputnode.curv', 'inputnode.curv'),
215228
]),
216-
(inputnode, resample_midthickness_wf, [
229+
(inputnode, resample_surfaces_wf, [
230+
('white', 'inputnode.white'),
231+
('pial', 'inputnode.pial'),
217232
('midthickness', 'inputnode.midthickness'),
218233
(reg_sphere, 'inputnode.sphere_reg_fsLR'),
219234
]),
@@ -230,12 +245,20 @@ def init_infant_anat_apply_wf(
230245
(hcp_morphometrics_wf, outputnode, [
231246
('outputnode.roi', 'roi'),
232247
]),
233-
(resample_midthickness_wf, morph_grayords_wf, [
248+
(resample_surfaces_wf, morph_grayords_wf, [
234249
('outputnode.midthickness_fsLR', 'inputnode.midthickness_fsLR'),
235250
]),
236-
(resample_midthickness_wf, outputnode, [
251+
(inputnode, ds_fsLR_surfaces_wf, [
252+
('anat_valid_list', 'inputnode.source_files'),
253+
]),
254+
(resample_surfaces_wf, outputnode, [
237255
('outputnode.midthickness_fsLR', 'midthickness_fsLR'),
238256
]),
257+
(resample_surfaces_wf, ds_fsLR_surfaces_wf, [
258+
('outputnode.white_fsLR', 'inputnode.white'),
259+
('outputnode.pial_fsLR', 'inputnode.pial'),
260+
('outputnode.midthickness_fsLR', 'inputnode.midthickness'),
261+
]),
239262
(inputnode, ds_grayord_metrics_wf, [
240263
('anat_valid_list', 'inputnode.source_files'),
241264
]),

nibabies/workflows/anatomical/surfaces.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,10 @@ def init_make_midthickness_wf(
415415
return workflow
416416

417417

418-
def init_resample_midthickness_dhcp_wf(
418+
def init_resample_surfaces_dhcp_wf(
419+
surfaces: list[str],
419420
grayord_density: ty.Literal['91k', '170k'],
420-
name: str = 'resample_midthickness_wf',
421+
name: str = 'resample_surfaces_dhcp_wf',
421422
):
422423
"""
423424
Resample subject midthickness surface to specified density.
@@ -427,20 +428,20 @@ def init_resample_midthickness_dhcp_wf(
427428
:graph2use: colored
428429
:simple_form: yes
429430
430-
from nibabies.workflows.anatomical.surfaces import init_resample_midthickness_wf
431-
wf = init_resample_midthickness_wf(grayord_density="91k")
431+
from nibabies.workflows.anatomical.surfaces import init_resample_surfaces_dhcp_wf
432+
wf = init_resample_surfaces_dhcp_wf(surfaces=['white', grayord_density='91k')
432433
433434
Parameters
434435
----------
435436
grayord_density : :obj:`str`
436437
Either `91k` or `170k`, representing the total of vertices or *grayordinates*.
437438
name : :obj:`str`
438-
Unique name for the subworkflow (default: ``"resample_midthickness_wf"``)
439+
Unique name for the subworkflow (default: ``"resample_surfaces_dhcp_wf``)
439440
440441
Inputs
441442
------
442-
midthickness
443-
GIFTI surface mesh corresponding to the midthickness surface
443+
``<surface>``
444+
Left and right GIFTIs for each surface name passed to ``surfaces``
444445
sphere_reg_fsLR
445446
GIFTI surface mesh corresponding to the subject's fsLR registration sphere
446447
@@ -454,11 +455,19 @@ def init_resample_midthickness_dhcp_wf(
454455
fslr_density = '32k' if grayord_density == '91k' else '59k'
455456

456457
inputnode = pe.Node(
457-
niu.IdentityInterface(fields=['midthickness', 'sphere_reg_fsLR']),
458+
niu.IdentityInterface(fields=[*surfaces, 'sphere_reg_fsLR']),
458459
name='inputnode',
459460
)
460461

461-
outputnode = pe.Node(niu.IdentityInterface(fields=['midthickness_fsLR']), name='outputnode')
462+
outputnode = pe.Node(
463+
niu.IdentityInterface(fields=[f'{surf}_fsLR' for surf in surfaces]), name='outputnode'
464+
)
465+
466+
surface_list = pe.Node(
467+
niu.Merge(len(surfaces), ravel_inputs=True),
468+
name='surface_list',
469+
run_without_submitting=True,
470+
)
462471

463472
resampler = pe.MapNode(
464473
SurfaceResample(method='BARYCENTRIC'),
@@ -477,20 +486,45 @@ def init_resample_midthickness_dhcp_wf(
477486
extension='.surf.gii',
478487
)
479488
)
489+
# Order matters. Iterate over surfaces, then hemis to get L R L R L R
490+
for _surf in surfaces
480491
for hemi in ['L', 'R']
481492
]
482493

494+
surface_groups = pe.Node(
495+
niu.Split(splits=[2] * len(surfaces)),
496+
name='surface_groups',
497+
run_without_submitting=True,
498+
)
499+
483500
workflow.connect([
501+
(inputnode, surface_list, [
502+
((surf, _sorted_by_basename), f'in{i}')
503+
for i, surf in enumerate(surfaces, start=1)
504+
]),
484505
(inputnode, resampler, [
485-
('midthickness', 'surface_in'),
486-
('sphere_reg_fsLR', 'current_sphere'),
506+
(('sphere_reg_fsLR', _repeat, len(surfaces)), 'current_sphere'),
507+
]),
508+
(surface_list, resampler, [('out', 'surface_in')]),
509+
(resampler, surface_groups, [('surface_out', 'inlist')]),
510+
(surface_groups, outputnode, [
511+
(f'out{i}', f'{surf}_fsLR') for i, surf in enumerate(surfaces, start=1)
487512
]),
488-
(resampler, outputnode, [('surface_out', 'midthickness_fsLR')]),
489513
]) # fmt:skip
490514

491515
return workflow
492516

493517

518+
def _sorted_by_basename(inlist):
519+
from os.path import basename
520+
521+
return sorted(inlist, key=lambda x: str(basename(x)))
522+
523+
524+
def _repeat(seq: list, count: int) -> list:
525+
return seq * count
526+
527+
494528
def _parent(p):
495529
from pathlib import Path
496530

nibabies/workflows/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ def init_single_subject_wf(
513513
('outputnode.anat_dseg', 'inputnode.anat_dseg'),
514514
('outputnode.anat_tpms', 'inputnode.anat_tpms'),
515515
('outputnode.fsnative2anat_xfm', 'inputnode.fsnative2anat_xfm'),
516+
('outputnode.white', 'inputnode.white'),
517+
('outputnode.pial', 'inputnode.pial'),
516518
('outputnode.midthickness', 'inputnode.midthickness'),
517519
(f'outputnode.{reg_sphere}', f'inputnode.{reg_sphere}'),
518520
('outputnode.sulc', 'inputnode.sulc'),

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ dependencies = [
3434
"pybids >= 0.15.0",
3535
"requests",
3636
"sdcflows >= 2.10.0",
37-
# "smriprep >= 0.16.1",
38-
"smriprep @ git+https://github.com/nipreps/smriprep.git@dev-nibabies",
37+
"smriprep >= 0.17.0",
3938
"tedana >= 23.0.2",
4039
"templateflow >= 24.2.0",
4140
"toml",

0 commit comments

Comments
 (0)