Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several warnings #364

Merged
merged 11 commits into from
Dec 8, 2023
12 changes: 6 additions & 6 deletions aslprep/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def build_workflow(config_file, retval):

# Called with reports only
if config.execution.reports_only:
from pkg_resources import resource_filename as pkgrf
from aslprep.data import load as load_data

build_log.log(25, "Running --reports-only on participants %s", ", ".join(subject_list))
retval["return_code"] = generate_reports(
subject_list,
config.execution.aslprep_dir,
config.execution.run_uuid,
config=pkgrf("aslprep", "data/reports-spec.yml"),
config=load_data.readable("reports-spec.yml"),
tsalo marked this conversation as resolved.
Show resolved Hide resolved
packagename="aslprep",
)
return retval
Expand Down Expand Up @@ -150,14 +150,14 @@ def build_boilerplate(config_file, workflow):
from shutil import copyfile
from subprocess import CalledProcessError, TimeoutExpired, check_call

from pkg_resources import resource_filename as pkgrf
from aslprep.data import load as load_data

# Generate HTML file resolving citations
cmd = [
"pandoc",
"-s",
"--bibliography",
pkgrf("aslprep", "data/boilerplate.bib"),
load_data.readable("boilerplate.bib"),
tsalo marked this conversation as resolved.
Show resolved Hide resolved
"--filter",
"pandoc-citeproc",
"--metadata",
Expand All @@ -178,7 +178,7 @@ def build_boilerplate(config_file, workflow):
"pandoc",
"-s",
"--bibliography",
pkgrf("aslprep", "data/boilerplate.bib"),
load_data.readable("boilerplate.bib"),
"--natbib",
str(citation_files["md"]),
"-o",
Expand All @@ -190,4 +190,4 @@ def build_boilerplate(config_file, workflow):
except (FileNotFoundError, CalledProcessError, TimeoutExpired):
config.loggers.cli.warning("Could not generate CITATION.tex file:\n%s", " ".join(cmd))
else:
copyfile(pkgrf("aslprep", "data/boilerplate.bib"), citation_files["bib"])
copyfile(load_data.readable("boilerplate.bib"), citation_files["bib"])
tsalo marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions aslprep/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
traits,
)
from niworkflows.interfaces.bids import DerivativesDataSink as BaseDerivativesDataSink
from pkg_resources import resource_filename as pkgrf

from aslprep import config
from aslprep.data import load as load_data

# NOTE: Modified for aslprep's purposes
aslprep_spec = loads(Path(pkgrf("aslprep", "data/aslprep_bids_config.json")).read_text())
aslprep_spec = loads(Path(load_data.readable("aslprep_bids_config.json")).read_text())
bids_config = Config.load("bids")
deriv_config = Config.load("derivatives")

Expand Down
3 changes: 3 additions & 0 deletions aslprep/interfaces/parcellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def _run_interface(self, runtime):
standardize=False,
strategy="sum",
resampling_target=None, # they should be in the same space/resolution already
keep_masked_labels=True,
)
sum_masker_unmasked = NiftiLabelsMasker(
labels_img=atlas,
Expand All @@ -103,6 +104,7 @@ def _run_interface(self, runtime):
standardize=False,
strategy="sum",
resampling_target=None, # they should be in the same space/resolution already
keep_masked_labels=True,
)
n_voxels_in_masked_parcels = sum_masker_masked.fit_transform(atlas_img_bin)
n_voxels_in_parcels = sum_masker_unmasked.fit_transform(atlas_img_bin)
Expand Down Expand Up @@ -150,6 +152,7 @@ def _run_interface(self, runtime):
smoothing_fwhm=None,
standardize=False,
resampling_target=None, # they should be in the same space/resolution already
keep_masked_labels=True,
)

# Use nilearn for time_series
Expand Down
3 changes: 2 additions & 1 deletion aslprep/interfaces/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ def _run_interface(self, runtime):
fig, ax = plt.subplots(figsize=(16, 8))
sns.despine(ax=ax, bottom=True, left=True)
sns.boxenplot(
x="Tissue Type",
y="CBF\n(mL/100 g/min)",
data=df,
width=0.6,
showfliers=True,
palette={"GM": "#1b60a5", "WM": "#2da467", "CSF": "#9d8f25"},
hue="Tissue Type",
legend=False,
ax=ax,
)
fig.tight_layout()
Expand Down
4 changes: 2 additions & 2 deletions aslprep/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import pytest
from fmriprep.reports.core import generate_reports
from nipype import config as nipype_config
from pkg_resources import resource_filename as pkgrf

from aslprep.cli.parser import parse_args
from aslprep.cli.workflow import build_boilerplate, build_workflow
from aslprep.data import load as load_data
from aslprep.tests.utils import (
check_generated_files,
download_test_data,
Expand Down Expand Up @@ -414,7 +414,7 @@ def _run_and_generate(test_name, participant_label, parameters, out_dir):
[participant_label],
out_dir,
config.execution.run_uuid,
config=pkgrf("aslprep", "data/reports-spec.yml"),
config=load_data.readable("reports-spec.yml"),
tsalo marked this conversation as resolved.
Show resolved Hide resolved
packagename="aslprep",
)

Expand Down
7 changes: 4 additions & 3 deletions aslprep/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
from pathlib import Path
from tempfile import mkdtemp

from pkg_resources import resource_filename as pkgrf
from toml import loads

from aslprep.data import load as load_data


@contextmanager
def mock_config():
Expand All @@ -40,7 +41,7 @@ def mock_config():
if not _old_fs:
os.environ["FREESURFER_HOME"] = mkdtemp()

filename = Path(pkgrf("aslprep", "tests/data/config.toml"))
filename = Path(load_data("../tests/data/config.toml"))
settings = loads(filename.read_text())
for sectionname, configs in settings.items():
if sectionname != "environment":
Expand All @@ -52,7 +53,7 @@ def mock_config():
config.init_spaces()

config.execution.work_dir = Path(mkdtemp())
config.execution.bids_dir = Path(pkgrf("aslprep", "tests/data/ds000240")).absolute()
config.execution.bids_dir = Path(load_data.readable("../tests/data/ds000240")).absolute()
config.execution.aslprep_dir = Path(mkdtemp())
config.execution.init()

Expand Down
13 changes: 6 additions & 7 deletions aslprep/utils/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_atlas_names(subset):


def get_atlas_nifti(atlas_name):
"""Select atlas by name from aslprep/data using pkgrf.
"""Select atlas by name from aslprep/data using aslprep.data.load.

All atlases are in MNI space.

Expand All @@ -72,7 +72,7 @@ def get_atlas_nifti(atlas_name):
"""
from os.path import isfile, join

from pkg_resources import resource_filename as pkgrf
from aslprep.data import load as load_data

if "4S" in atlas_name or atlas_name in ("Glasser", "Gordon"):
# 1 mm3 atlases
Expand All @@ -88,11 +88,10 @@ def get_atlas_nifti(atlas_name):
atlas_labels_file = join("/AtlasPack", tsv_fname)
atlas_metadata_file = f"/AtlasPack/tpl-MNI152NLin6Asym_atlas-{atlas_name}_dseg.json"
else:
atlas_file = pkgrf("aslprep", f"data/atlases/{atlas_fname}")
atlas_labels_file = pkgrf("aslprep", f"data/atlases/{tsv_fname}")
atlas_metadata_file = pkgrf(
"aslprep",
f"data/atlases/tpl-MNI152NLin6Asym_atlas-{atlas_name}_dseg.json",
atlas_file = load_data.readable(f"atlases/{atlas_fname}")
atlas_labels_file = load_data.readable(f"atlases/{tsv_fname}")
atlas_metadata_file = load_data.readable(
f"atlases/tpl-MNI152NLin6Asym_atlas-{atlas_name}_dseg.json",
)

if not (isfile(atlas_file) and isfile(atlas_labels_file) and isfile(atlas_metadata_file)):
Expand Down
2 changes: 1 addition & 1 deletion aslprep/utils/cbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def _scrubcbf(cbf_ts, gm, wm, csf, mask, wfun="huber", thresh=0.7):
X[:, 0] = gm.flatten()[gm.flatten() >= (0)] * idxx
X[:, 1] = wm.flatten()[wm.flatten() >= (0)] * idxx
A = (mean_cbf.flatten()[idxx >= 0]) * idxx
c = np.linalg.lstsq(X, A)[0]
c = np.linalg.lstsq(X, A, rcond=None)[0]
Globalpriorfull = c[0] * gm.flatten() + c[1] * wm.flatten()
Globalprior = Globalpriorfull[mask.flatten() == 1]
localprior = 0
Expand Down
2 changes: 1 addition & 1 deletion aslprep/workflows/asl/cbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def init_parcellate_cbf_wf(
atlas_name_grabber.inputs.subset = "all"
workflow.connect([(atlas_name_grabber, outputnode, [("atlas_names", "atlas_names")])])

# get atlases via pkgrf
# get atlases via aslprep.data.load
atlas_file_grabber = pe.MapNode(
niu.Function(
input_names=["atlas_name"],
Expand Down
8 changes: 4 additions & 4 deletions docs/workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ CBF Computation in native space

import json
from pathlib import Path
from pkg_resources import resource_filename as pkgrf

from aslprep.data import load as load_data
from aslprep.workflows.asl.cbf import init_cbf_wf

bids_dir = Path(pkgrf("aslprep", "tests/data/ds000240")).absolute()
bids_dir = Path(load_data.readable("../tests/data/ds000240")).absolute()
nii_file = bids_dir / "sub-01" / "perf"/ "sub-01_asl.nii.gz"
metadata_file = bids_dir / "sub-01" / "perf"/ "sub-01_asl.json"
with open(metadata_file) as f:
Expand Down Expand Up @@ -614,11 +614,11 @@ Quality control measures
:simple_form: yes

from pathlib import Path
from pkg_resources import resource_filename as pkgrf

from aslprep.data import load as load_data
from aslprep.workflows.asl.qc import init_cbf_confounds_wf

bids_dir = Path(pkgrf("aslprep", "tests/data/ds000240")).absolute()
bids_dir = Path(load_data.readable("../tests/data/ds000240")).absolute()
asl_file = bids_dir / "sub-01" / "perf"/ "sub-01_asl.nii.gz"
metadata = bids_dir / "sub-01" / "perf"/ "sub-01_asl.json"

Expand Down
Loading