Skip to content

Commit

Permalink
Merge pull request #168 from oesteban/fix/fieldmap-reportlet
Browse files Browse the repository at this point in the history
FIX: Cleanup annoying isolated dots in reportlets + new tests
  • Loading branch information
oesteban authored Dec 29, 2020
2 parents 94dd55a + 7e0b626 commit f4421e9
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ out/**/*
out/
tools/**/*
tools
.DS_Store

# CI, etc.
.circleci/**/*
Expand All @@ -49,4 +50,5 @@ tools
.readthedocs.yml
.travis.yml
.zenodo.json
CONTRIBUTING.md
CONTRIBUTING.md

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ venv.bak/

# mypy
.mypy_cache/

# Mac OSX
.DS_Store
2 changes: 1 addition & 1 deletion sdcflows/interfaces/reportlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _generate_report(self):
break

if isdefined(self.inputs.moving):
movnii = load_img(self.inputs.moving)
movnii = rotate_affine(load_img(self.inputs.moving), rot=canonical_r)

contour_nii = mask_nii = None
if isdefined(self.inputs.mask):
Expand Down
30 changes: 30 additions & 0 deletions sdcflows/interfaces/tests/test_reportlets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Test the fieldmap reportlets."""
from pathlib import Path
import pytest
from ..reportlets import FieldmapReportlet
from ...utils.epimanip import epi_mask


@pytest.mark.parametrize("mask", [True, False])
@pytest.mark.parametrize("apply_mask", [True, False])
def test_FieldmapReportlet(tmpdir, outdir, testdata_dir, mask, apply_mask):
"""Generate one reportlet."""
tmpdir.chdir()

if not outdir:
outdir = Path.cwd()

report = FieldmapReportlet(
reference=str(testdata_dir / "epi.nii.gz"),
moving=str(testdata_dir / "epi.nii.gz"),
fieldmap=str(testdata_dir / "topup-field.nii.gz"),
out_report=str(
outdir / f"test-fieldmap{'-masked' * mask}{'-zeroed' * apply_mask}.svg"
),
apply_mask=apply_mask,
)

if mask:
report.inputs.mask = epi_mask(str(testdata_dir / "epi.nii.gz"))

report.run()
1 change: 0 additions & 1 deletion sdcflows/interfaces/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_ConvertWarp(tmpdir, shape):
)
def test_Xeoblique(tmpdir, angles, oblique):
"""Exercise De/Reoblique interfaces."""

tmpdir.chdir()

affine = nb.affines.from_matvec(nb.eulerangles.euler2mat(*angles))
Expand Down
1 change: 1 addition & 0 deletions sdcflows/utils/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@pytest.mark.parametrize("retval", [None, 10])
def test_get_free_mem(monkeypatch, retval):
"""Test the get_free_mem utility."""

def mock_func():
if retval is None:
raise ImportError
Expand Down
5 changes: 3 additions & 2 deletions sdcflows/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ def coolwarm_transparent(max_alpha=0.7, opaque_perc=30, transparent_perc=8):
midpoint = cmap.N // 2 + 1
_10perc = (cmap.N * transparent_perc) // 100
# Set alpha
alpha = np.ones(cmap.N) * max_alpha
alpha[midpoint - _10perc : midpoint + _10perc] = 0
alpha = np.zeros(cmap.N)
alpha[:_20perc] = max_alpha
alpha[-_20perc:] = max_alpha
alpha[_20perc : midpoint - _10perc - 1] = np.linspace(
max_alpha, 0, len(alpha[_20perc : midpoint - _10perc - 1])
)
Expand Down

0 comments on commit f4421e9

Please sign in to comment.