Skip to content

Commit

Permalink
Merge pull request #398 from effigies/bp/2.5.x/396
Browse files Browse the repository at this point in the history
FIX: Mask fieldmap before fitting spline field [backport gh-396]
  • Loading branch information
effigies authored Nov 9, 2023
2 parents cd5b091 + dcee2d8 commit c592658
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sdcflows/interfaces/bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def _run_interface(self, runtime):
center = np.mean(data[mask])

data -= center
data[~mask] = 0

# 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 All @@ -210,7 +211,7 @@ def _run_interface(self, runtime):
# Fit the model
model = lm.Ridge(alpha=self.inputs.ridge_alpha, fit_intercept=False, solver='lsqr')
for attempt in range(3):
model.fit(colmat[mask.reshape(-1), :], data[mask])
model.fit(colmat, data.reshape(-1))
extreme = np.abs(model.coef_).max()
LOGGER.debug(f"Model fit attempt {attempt}: max(|coeffs|) = {extreme}")
# Normal values seem to be ~1e2, bad ~1e8. May want to tweak this if
Expand Down

0 comments on commit c592658

Please sign in to comment.