Skip to content

Commit

Permalink
FIX: Recenter data when reloaded for generating debug maps
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Apr 21, 2023
1 parent 2cb9770 commit 03b9e8a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sdcflows/interfaces/bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,20 @@ def _run_interface(self, runtime):
)

# Recenter the fieldmap
center = 0
if self.inputs.recenter == "mode":
from scipy.stats import mode

# Handle pre- and post-1.9 mode behavior.
# squeeze can be dropped when the minimum version reaches 1.9
# Will become: data -= mode(data[mask], keepdims=False).mode
data -= np.squeeze(mode(data[mask]).mode)
center = np.squeeze(mode(data[mask]).mode)
elif self.inputs.recenter == "median":
data -= np.median(data[mask])
center = np.median(data[mask])
elif self.inputs.recenter == "mean":
data -= np.mean(data[mask])
center = np.mean(data[mask])

data -= center

# Calculate collocation matrix from (possibly resized) image and knot grids
colmat = sparse_vstack(grid_bspline_weights(fmapnii, grid) for grid in bs_grids).T.tocsr()
Expand Down Expand Up @@ -228,7 +231,7 @@ def _run_interface(self, runtime):
if need_resize:
fmapnii = nb.load(self.inputs.in_data)
fmapnii = nb.as_closest_canonical(fmapnii)
data = fmapnii.get_fdata(dtype="float32")
data = fmapnii.get_fdata(dtype="float32") - center
if masknii is not None:
masknii = nb.load(self.inputs.in_mask)
masknii = nb.as_closest_canonical(masknii)
Expand Down

0 comments on commit 03b9e8a

Please sign in to comment.