Skip to content

Commit 6d2974c

Browse files
committed
Merge branch 'maint/1.0.x'
2 parents bb7d3ec + 03d02e1 commit 6d2974c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
1.0.5 (February 14, 2020)
2+
=========================
3+
Bug-fix release.
4+
5+
* FIX: Center phase maps around central mode, avoiding FoV-related outliers (#89)
6+
17
1.1.0 (February 3, 2020)
28
========================
39
This is a nominal release that enables downstream tools to depend on both

sdcflows/interfaces/fmap.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,19 +661,31 @@ def _delta_te(in_values, te1=None, te2=None):
661661

662662
def au2rads(in_file, newpath=None):
663663
"""Convert the input phase difference map in arbitrary units (a.u.) to rads."""
664-
from scipy.stats import mode
664+
from scipy import stats
665665
im = nb.load(in_file)
666666
data = im.get_fdata(dtype='float32')
667667
hdr = im.header.copy()
668668

669-
# First center data around 0.0.
670-
data -= mode(data, axis=None)[0][0]
669+
dmin, dmax = data.min(), data.max()
670+
671+
# Find the mode ignoring outliers on the far max/min, to allow for junk outside the FoV
672+
fudge = 0.05 * (dmax - dmin)
673+
mode = stats.mode(data[(data > dmin + fudge) & (data < dmax - fudge)])[0][0]
674+
675+
# Center data around 0.0
676+
data -= mode
677+
678+
# Provide a less opaque error if we still can't figure it out
679+
neg = data < 0
680+
pos = data > 0
681+
if not (neg.any() and pos.any()):
682+
raise ValueError("Could not find an appropriate mode to center phase values around")
671683

672684
# Scale lower tail
673-
data[data < 0] = - np.pi * data[data < 0] / data[data < 0].min()
685+
data[neg] = - np.pi * data[neg] / data[neg].min()
674686

675687
# Scale upper tail
676-
data[data > 0] = np.pi * data[data > 0] / data[data > 0].max()
688+
data[pos] = np.pi * data[pos] / data[pos].max()
677689

678690
# Offset to 0 - 2pi
679691
data += np.pi

0 commit comments

Comments
 (0)