Skip to content

Commit

Permalink
FIX: Switch to mode of central 90% of value range
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Feb 14, 2020
1 parent 88dd7ad commit 5472fcb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sdcflows/interfaces/fmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,18 +661,19 @@ def _delta_te(in_values, te1=None, te2=None):

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

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

# Second mode (idx 1) if first node (idx 0) is minimum, else first
idx = int(modes[0] == data.min())
# Find the mode ignoring outliers on the far max/min, to allow for junk outside the FoV
fudge = 0.05 * (dmax - dmin)
mode = stats.mode(data[(data > dmin + fudge) & (data < dmax - fudge)])[0][0]

# Center data around 0.0
data -= modes[idx]
data -= mode

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

0 comments on commit 5472fcb

Please sign in to comment.