Skip to content

Commit dbec0d9

Browse files
committed
fix: doctest modules
1 parent a75ee8a commit dbec0d9

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

sdcflows/workflows/fit/syn.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,17 @@ def _warp_dir(intuple, nlevels=3):
621621
Example
622622
-------
623623
>>> _warp_dir(("epi.nii.gz", {"PhaseEncodingDirection": "i-"}))
624-
[[1, 0, 0], [1, 0, 0], [1, 0, 0]]
624+
[[1, 0.1, 0.1], [1, 0.1, 0.1], [1, 0.1, 0.1]]
625625
626626
>>> _warp_dir(("epi.nii.gz", {"PhaseEncodingDirection": "j-"}), nlevels=2)
627-
[[0, 1, 0], [0, 1, 0]]
627+
[[0.1, 1, 0.1], [0.1, 1, 0.1]]
628628
629629
"""
630630
pe = intuple[1]["PhaseEncodingDirection"][0]
631631
return nlevels * [[1 if pe == ax else 0.1 for ax in "ijk"]]
632632

633633

634-
def _extract_field(in_file, epi_meta, in_mask=None):
634+
def _extract_field(in_file, epi_meta, in_mask=None, demean=True):
635635
"""
636636
Extract the nonzero component of the deformation field estimated by ANTs.
637637
@@ -640,7 +640,9 @@ def _extract_field(in_file, epi_meta, in_mask=None):
640640
>>> nii = nb.load(
641641
... _extract_field(
642642
... ["field.nii.gz"],
643-
... ("epi.nii.gz", {"PhaseEncodingDirection": "j-", "TotalReadoutTime": 0.005}))
643+
... ("epi.nii.gz", {"PhaseEncodingDirection": "j-", "TotalReadoutTime": 0.005}),
644+
... demean=False,
645+
... )
644646
... )
645647
>>> nii.shape
646648
(10, 10, 10)
@@ -668,13 +670,13 @@ def _extract_field(in_file, epi_meta, in_mask=None):
668670
if ["PhaseEncodingDirection"][0] in "ij":
669671
data *= -1.0 # ITK/ANTs is an LPS system, flip direction
670672

671-
if in_mask is None:
672-
mask = np.ones_like(data, dtype=bool)
673-
else:
674-
mask = np.asanyarray(nb.load(in_mask).dataobj, dtype=bool)
675-
676-
# De-mean the result
677-
data -= np.median(data[mask])
673+
if demean:
674+
mask = (
675+
np.ones_like(data, dtype=bool) if in_mask is None
676+
else np.asanyarray(nb.load(in_mask).dataobj, dtype=bool)
677+
)
678+
# De-mean the result
679+
data -= np.median(data[mask])
678680

679681
out_file = Path(fname_presuffix(Path(in_file[0]).name, suffix="_fieldmap"))
680682
nii = nb.Nifti1Image(data, fieldnii.affine, None)

0 commit comments

Comments
 (0)