Skip to content

Commit f4a2966

Browse files
committed
FIX: Switch to mode of central 90% of value range
1 parent a3b908f commit f4a2966

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

sdcflows/interfaces/fmap.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,18 +661,19 @@ 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 import stats
664665
im = nb.load(in_file)
665666
data = im.get_fdata(dtype='float32')
666667
hdr = im.header.copy()
667668

668-
vals, counts = np.unique(data, return_counts=True)
669-
modes = vals[np.argsort(counts)[::-1]]
669+
dmin, dmax = data.min(), data.max()
670670

671-
# Second mode (idx 1) if first node (idx 0) is minimum, else first
672-
idx = int(modes[0] == data.min())
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]
673674

674675
# Center data around 0.0
675-
data -= modes[idx]
676+
data -= mode
676677

677678
# Provide a less opaque error if we still can't figure it out
678679
neg = data < 0

0 commit comments

Comments
 (0)