Skip to content

Commit

Permalink
Merge pull request #207 from nipreps/fix/multiple-field-apply
Browse files Browse the repository at this point in the history
FIX: Make sure the VSM is not modified when accessing it
  • Loading branch information
oesteban authored May 10, 2021
2 parents c34e81b + 5866a24 commit 01c5a4b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
6 changes: 1 addition & 5 deletions sdcflows/interfaces/bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ def _run_interface(self, runtime):
pe_dir = [pe_dir[0]] * n_inputs

for fname, pe, ro in zip(self.inputs.in_target, pe_dir, ro_time):
xfm.fit(fname)

# Generate warpfield
warp_name = filename(fname, suffix="_xfm")
xfm.to_displacements(ro_time=ro, pe_dir=pe).to_filename(warp_name)
Expand Down Expand Up @@ -443,7 +441,5 @@ def _fix_topup_fieldcoeff(in_coeff, fmap_ref, refpe_reversed=False, out_file=Non
coeffnii.header.set_qform(coeffnii.header.get_qform(coded=False), code=0)
coeffnii.header.set_sform(newaff, code=1)

# If the reference is reversed encoded, flip the displacements
coeffs = (1.0 - 2.0 * refpe_reversed) * np.asanyarray(coeffnii.dataobj)
coeffnii.__class__(coeffs, newaff, header).to_filename(out_file)
coeffnii.__class__(coeffnii.dataobj, newaff, header).to_filename(out_file)
return out_file
4 changes: 2 additions & 2 deletions sdcflows/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def apply(
"""
# Ensure the vsm has been computed
self.fit(spatialimage)
vsm = self.shifts.get_fdata()
vsm = self.shifts.get_fdata().copy()

# Reverse shifts if reversed blips
if pe_dir.endswith("-"):
Expand Down Expand Up @@ -164,7 +164,7 @@ def to_displacements(self, ro_time, pe_dir):
from nibabel.orientations import io_orientation

# Generate warp field
data = self.shifts.get_fdata(dtype="float32")
data = self.shifts.get_fdata(dtype="float32").copy()
pe_axis = "ijk".index(pe_dir[0])
pe_sign = -1.0 if pe_dir.endswith("-") else 1.0
pe_size = self.shifts.header.get_zooms()[pe_axis]
Expand Down
5 changes: 3 additions & 2 deletions sdcflows/workflows/fit/pepolar.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def init_topup_wf(

brainextraction_wf = init_brainextraction_wf()

def _getpe(in_meta):
def _getfirstpe(in_meta):
if isinstance(in_meta, list):
in_meta = in_meta[0]
return in_meta["PhaseEncodingDirection"]
Expand All @@ -144,7 +144,7 @@ def _getpe(in_meta):
(readout_time, topup, [("readout_time", "readout_times")]),
(concat_blips, topup, [("out_file", "in_file")]),
(flatten, fix_coeff, [(("out_data", _front), "fmap_ref"),
(("out_meta", _getpe), "pe_dir")]),
(("out_meta", _getfirstpe), "pe_dir")]),
(topup, fix_coeff, [("out_fieldcoef", "in_coeff")]),
(topup, outputnode, [("out_jacs", "jacobians"),
("out_mats", "xfms")]),
Expand All @@ -168,6 +168,7 @@ def _getpe(in_meta):
from ...interfaces.bspline import ApplyCoeffsField

unwarp = pe.Node(ApplyCoeffsField(), name="unwarp")
unwarp.interface._always_run = True

def _getpe(inlist):
if isinstance(inlist, dict):
Expand Down

0 comments on commit 01c5a4b

Please sign in to comment.