Skip to content

Commit

Permalink
MAINT: Purge remaining pkg_resource uses
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Jan 29, 2024
1 parent 7cbb35a commit 42997bf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
10 changes: 3 additions & 7 deletions nibabies/workflows/anatomical/brain_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""Baby brain extraction from T2w images."""
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from pkg_resources import resource_filename as pkgr_fn


def init_infant_brain_extraction_wf(
Expand Down Expand Up @@ -79,16 +78,15 @@ def init_infant_brain_extraction_wf(
from nipype.interfaces.ants import ImageMath, N4BiasFieldCorrection
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from niworkflows.interfaces.fixes import FixHeaderRegistration as Registration

# niworkflows
from niworkflows.interfaces.nibabel import (
ApplyMask,
Binarize,
BinaryDilation,
IntensityClip,
)

from ...utils.misc import cohort_by_months
from nibabies.data import load as load_data
from nibabies.utils.misc import cohort_by_months

Check warning on line 89 in nibabies/workflows/anatomical/brain_extraction.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/brain_extraction.py#L88-L89

Added lines #L88 - L89 were not covered by tests

# handle template specifics
template_specs = template_specs or {}
Expand Down Expand Up @@ -138,9 +136,7 @@ def init_infant_brain_extraction_wf(
# Set up initial spatial normalization
ants_params = "testing" if sloppy else "precise"
norm = pe.Node(
Registration(
from_file=pkgr_fn("nibabies.data", f"antsBrainExtraction_{ants_params}.json")
),
Registration(from_file=load_data(f"antsBrainExtraction_{ants_params}.json")),
name="norm",
n_procs=omp_nthreads,
mem_gb=mem_gb,
Expand Down
9 changes: 3 additions & 6 deletions nibabies/workflows/anatomical/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
from nipype.interfaces import utility as niu
from nipype.interfaces.ants.segmentation import JointFusion
from nipype.pipeline import engine as pe
from niworkflows.data import load as load_nwf
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from niworkflows.interfaces.fixes import FixHeaderRegistration as Registration
from niworkflows.interfaces.nibabel import MapLabels
from pkg_resources import resource_filename as pkgr_fn
from smriprep.utils.misc import apply_lut as _apply_bids_lut
from smriprep.workflows.anatomical import (
_aseg_to_three,
_probseg_fast2bids,
_split_segments,
)

from ...config import DEFAULT_MEMORY_MIN_GB
from nibabies.config import DEFAULT_MEMORY_MIN_GB


def init_anat_segmentations_wf(
Expand Down Expand Up @@ -104,9 +103,7 @@ def init_anat_segmentations_wf(
ants_params = "testing" if sloppy else "precise"
# Register to each subject space
norm = pe.MapNode(
Registration(
from_file=pkgr_fn("niworkflows.data", f"antsBrainExtraction_{ants_params}.json")
),
Registration(from_file=load_nwf(f"antsBrainExtraction_{ants_params}.json")),
name="norm",
iterfield=["moving_image"],
n_procs=omp_nthreads,
Expand Down
16 changes: 7 additions & 9 deletions nibabies/workflows/bold/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from pkg_resources import resource_filename

from ...interfaces.workbench import VolumeLabelImport
from nibabies.data import load as load_data
from nibabies.interfaces.workbench import VolumeLabelImport


def init_subcortical_rois_wf(*, name="subcortical_rois_wf"):
Expand Down Expand Up @@ -70,17 +70,15 @@ def init_subcortical_rois_wf(*, name="subcortical_rois_wf"):
# )

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

subcortical_labels = resource_filename(
"nibabies", "data/FreeSurferSubcorticalLabelTableLut.txt"
)
refine_bold_rois = pe.Node(
VolumeLabelImport(label_list_file=subcortical_labels, discard_others=True),
VolumeLabelImport(
label_list_file=load_data("FreeSurferSubcorticalLabelTableLut.txt"),
discard_others=True,
),
name="refine_bold_rois",
)

Expand Down
6 changes: 3 additions & 3 deletions nibabies/workflows/bold/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import logging
import os

import pkg_resources as pkgr
from nipype.interfaces import c3, fsl
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe

from ...config import DEFAULT_MEMORY_MIN_GB
from nibabies.config import DEFAULT_MEMORY_MIN_GB
from nibabies.data import load as load_data

LOGGER = logging.getLogger("nipype.workflow")

Expand Down Expand Up @@ -793,7 +793,7 @@ def init_fsl_bbr_wf(use_bbr, bold2t1w_dof, bold2t1w_init, sloppy=False, name="fs
else:
# Should mostly be hit while building docs
LOGGER.warning("FSLDIR unset - using packaged BBR schedule")
flt_bbr.inputs.schedule = pkgr.resource_filename("fmriprep", "data/flirtsch/bbr.sch")
flt_bbr.inputs.schedule = load_data("flirtsch/bbr.sch")

Check warning on line 796 in nibabies/workflows/bold/registration.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/bold/registration.py#L796

Added line #L796 was not covered by tests

# fmt: off
workflow.connect([
Expand Down

0 comments on commit 42997bf

Please sign in to comment.