Skip to content

Commit

Permalink
enh: address comments from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Mathias Goncalves <[email protected]>
  • Loading branch information
oesteban and mgxd committed Aug 16, 2023
1 parent ea12e7f commit 6e3de3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
14 changes: 7 additions & 7 deletions sdcflows/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ def fit(
projected_reference, _ = ensure_positive_cosines(projected_reference)

# Approximate only if the coordinate systems are not aligned
finest_coeffs = listify(self.coeffs)[-1]
coeffs = listify(self.coeffs)
approx &= not np.allclose(
np.linalg.norm(
np.cross(
finest_coeffs.affine[:-1, :-1].T,
coeffs[-1].affine[:-1, :-1].T,
target_reference.affine[:-1, :-1].T,
),
axis=1,
Expand All @@ -310,26 +310,26 @@ def fit(
)

weights = []
coeffs = []
if approx:
from sdcflows.utils.tools import deoblique_and_zooms

# Generate a sampling reference on the fieldmap's space that fully covers
# the target_reference's grid.
projected_reference = deoblique_and_zooms(
listify(self.coeffs)[-1],
coeffs[-1],
target_reference,
)

# Generate tensor-product B-Spline weights
for level in listify(self.coeffs):
coeffs_data = []
for level in coeffs:
wmat = grid_bspline_weights(target_reference, level)
weights.append(wmat)
coeffs.append(level.get_fdata(dtype="float32").reshape(-1))
coeffs_data.append(level.get_fdata(dtype="float32").reshape(-1))

# Reconstruct the fieldmap (in Hz) from coefficients
fmap = np.zeros(projected_reference.shape[:3], dtype="float32")
fmap = (np.squeeze(np.hstack(coeffs).T) @ sparse_vstack(weights)).reshape(
fmap = (np.squeeze(np.hstack(coeffs_data).T) @ sparse_vstack(weights)).reshape(
fmap.shape
)

Expand Down
14 changes: 0 additions & 14 deletions sdcflows/workflows/apply/correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ def init_unwarp_wf(*, free_mem=None, omp_nthreads=1, debug=False, name="unwarp_w
the target EPI reference image, after applying unwarping.
corrected_mask
a fast mask calculated from the corrected EPI reference.
fieldmap_ref
the actual B\ :sub:`0` inhomogeneity map (also called *fieldmap*)
interpolated from the B-Spline coefficients into the reference EPI's
grid, given in Hz units.
No motion is taken into account.
fieldwarp_ref
the displacements field interpolated from the B-Spline coefficients
and scaled by the appropriate parameters (readout time of the EPI
target and voxel size along PE).
No motion is taken into account.
"""
from niworkflows.interfaces.images import RobustAverage
Expand Down Expand Up @@ -113,8 +103,6 @@ def init_unwarp_wf(*, free_mem=None, omp_nthreads=1, debug=False, name="unwarp_w
"corrected",
"corrected_ref",
"corrected_mask",
"fieldwarp_ref",
"fieldmap_ref",
]
),
name="outputnode",
Expand Down Expand Up @@ -161,8 +149,6 @@ def init_unwarp_wf(*, free_mem=None, omp_nthreads=1, debug=False, name="unwarp_w
(average, brainextraction_wf, [("out_file", "inputnode.in_file")]),
(merge, outputnode, [("out_file", "corrected")]),
(resample, outputnode, [("out_field", "fieldmap")]),
# (resample_ref, outputnode, [("out_field", "fieldmap_ref")]),
# TODO - take reference from brainextraction workflow
(brainextraction_wf, outputnode, [
("outputnode.out_file", "corrected_ref"),
("outputnode.out_mask", "corrected_mask"),
Expand Down

0 comments on commit 6e3de3a

Please sign in to comment.