Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions nibabies/data/FreeSurferLabelRemappings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"173": 16,
"174": 16,
"175": 16,

"500": 53,
"501": 53,
"502": 53,
"503": 53,
"504": 53,
"505": 53,
"506": 53,
"507": 53,
"508": 53,

"550": 17,
"551": 17,
"552": 17,
"553": 17,
"554": 17,
"555": 17,
"556": 17,
"557": 17,
"558": 17
}
115 changes: 0 additions & 115 deletions nibabies/interfaces/nibabel.py

This file was deleted.

73 changes: 0 additions & 73 deletions nibabies/interfaces/tests/test_nibabel.py

This file was deleted.

3 changes: 1 addition & 2 deletions nibabies/workflows/anatomical/brain_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ def init_infant_brain_extraction_wf(
from nipype.interfaces.ants import N4BiasFieldCorrection, ImageMath

# niworkflows
from niworkflows.interfaces.nibabel import ApplyMask, Binarize, IntensityClip
from niworkflows.interfaces.nibabel import ApplyMask, Binarize, IntensityClip, BinaryDilation
from niworkflows.interfaces.fixes import (
FixHeaderRegistration as Registration,
FixHeaderApplyTransforms as ApplyTransforms,
)
from templateflow.api import get as get_template

from ...interfaces.nibabel import BinaryDilation
from ...utils.misc import cohort_by_months

# handle template specifics
Expand Down
3 changes: 1 addition & 2 deletions nibabies/workflows/anatomical/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def init_coregistration_wf(
FixHeaderRegistration as Registration,
FixHeaderApplyTransforms as ApplyTransforms,
)
from niworkflows.interfaces.nibabel import ApplyMask, Binarize
from ...interfaces.nibabel import BinaryDilation
from niworkflows.interfaces.nibabel import ApplyMask, Binarize, BinaryDilation

workflow = pe.Workflow(name)

Expand Down
57 changes: 11 additions & 46 deletions nibabies/workflows/bold/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def init_subcortical_rois_wf(*, name="subcortical_rois_wf"):
Subcortical ROIs in `MNI152NLin6Asym` space
"""
from templateflow.api import get as get_template
from niworkflows.interfaces.nibabel import MapLabels

# TODO: Implement BOLD refinement once InfantFS outputs subj/mri/wmparc.mgz
# The code is found at
Expand Down Expand Up @@ -68,6 +69,13 @@ def init_subcortical_rois_wf(*, name="subcortical_rois_wf"):
# name="applywarp_std"
# )

map_labels = pe.Node(
MapLabels(
mappings_file=resource_filename("nibabies", "data/FreeSurferLabelRemappings.json")
),
name='map_labels',
)

subcortical_labels = resource_filename(
"nibabies", "data/FreeSurferSubcorticalLabelTableLut.txt"
)
Expand All @@ -78,7 +86,8 @@ def init_subcortical_rois_wf(*, name="subcortical_rois_wf"):

# fmt: off
workflow.connect([
(inputnode, refine_bold_rois, [("MNIInfant_aseg", "in_file")]),
(inputnode, map_labels, [("MNIInfant_aseg", "in_file")]),
(map_labels, refine_bold_rois, [("out_file", "in_file")]),
# (applywarp_tpl, refine_std_rois, [("out_file", "in_file")]),
(refine_bold_rois, outputnode, [("out_file", "MNIInfant_rois")]),
])
Expand Down Expand Up @@ -119,7 +128,7 @@ def init_subcortical_mni_alignment_wf(*, vol_sigma=0.8, name="subcortical_mni_al
Volume file containing all labels
"""
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from ...interfaces.nibabel import MergeROIs
from niworkflows.interfaces.nibabel import MergeROIs
from ...interfaces.workbench import (
CiftiCreateDenseTimeseries,
CiftiCreateLabel,
Expand Down Expand Up @@ -350,47 +359,3 @@ def format_agg_rois(rois):

"""
return rois[0], rois[1:], ("-add %s " * (len(rois) - 1)).strip()


def drop_labels(in_file):
"""Drop non-subcortical labels"""
from pathlib import Path
import nibabel as nb
import numpy as np
from niworkflows.interfaces.cifti import _reorient_image

# FreeSurfer LUT values
expected_labels = {
8,
10,
11,
12,
13,
16,
17,
18,
26,
28,
47,
49,
50,
51,
52,
53,
54,
58,
60,
}
img = _reorient_image(nb.load(in_file), orientation="LAS")
hdr = img.header
data = np.asanyarray(img.dataobj).astype("int16")
hdr.set_data_dtype("int16")
labels = np.unique(data)

for label in labels:
if label not in expected_labels:
data[data == label] = 0

out_file = str(Path("ROIs.nii.gz").absolute())
img.__class__(data, img.affine, header=hdr).to_filename(out_file)
return out_file
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ install_requires =
nibabel >= 3.0.1
nipype >= 1.5.1
nitime
niworkflows ~= 1.4.0
niworkflows ~= 1.5.0
numpy >= 1.16.5
pybids >= 0.12.1
sdcflows ~= 2.0.7
sdcflows ~= 2.0.12
smriprep ~= 0.8.1
templateflow >= 0.6.0
test_requires =
Expand Down