From d518851270237a6f5a7acf08070d6ce63074ec09 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Wed, 27 Sep 2023 10:47:32 -0400 Subject: [PATCH] FIX: Mask fieldmap before fitting spline field Previously, we fit a spline field to the within-mask portion of a fieldmap, which could lead to large peaks outside the mask. Applying the mask to the reconstructed field can produce discontinuities in resampling. Instead of attempting to attenuate the peaks outside the mask in a smooth way, we set the fit values outside the mask to zero, and let the spline fit find a smooth field. In practice, we've found that even fields with large peaks on the edge of the mask are well fit by this method. --- sdcflows/interfaces/bspline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdcflows/interfaces/bspline.py b/sdcflows/interfaces/bspline.py index 9219ddf7fd..235cc50077 100644 --- a/sdcflows/interfaces/bspline.py +++ b/sdcflows/interfaces/bspline.py @@ -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_hstack( @@ -214,7 +215,7 @@ def _run_interface(self, runtime): 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