Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Mathias Goncalves <goncalves.mathias@gmail.com>
  • Loading branch information
effigies and mgxd authored Oct 26, 2023
1 parent 26d141f commit 0d09cc0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
2 changes: 2 additions & 0 deletions fmriprep/interfaces/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ async def resample_series_async(

semaphore = asyncio.Semaphore(max_concurrent)

# Order F ensures individual volumes are contiguous in memory
# Also matches NIfTI, making final save more efficient
out_array = np.zeros(coordinates.shape[1:] + data.shape[-1:], dtype=output_dtype, order='F')

tasks = [
Expand Down
84 changes: 43 additions & 41 deletions fmriprep/workflows/bold/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
def init_bold_volumetric_resample_wf(
*,
metadata: dict,
fieldmap_id: ty.Optional[str] = None,
fieldmap_id: str | None = None,
omp_nthreads: int = 1,
name: str = 'bold_volumetric_resample_wf',
) -> pe.Workflow:
Expand Down Expand Up @@ -84,46 +84,48 @@ def init_bold_volumetric_resample_wf(
(resample, outputnode, [('out_file', 'bold_file')]),
]) # fmt:skip

if fieldmap_id:
fmap_select = pe.Node(
KeySelect(fields=["fmap_ref", "fmap_coeff"], key=fieldmap_id),
name="fmap_select",
run_without_submitting=True,
)
distortion_params = pe.Node(
DistortionParameters(metadata=metadata),
name="distortion_params",
run_without_submitting=True,
)
fmap2target = pe.Node(niu.Merge(2), name='fmap2target')
inverses = pe.Node(niu.Function(function=_gen_inverses), name='inverses')

fmap_recon = pe.Node(ReconstructFieldmap(), name="fmap_recon")

workflow.connect([
(inputnode, fmap_select, [
("fmap_ref", "fmap_ref"),
("fmap_coeff", "fmap_coeff"),
("fmap_id", "keys"),
]),
(inputnode, distortion_params, [('bold_file', 'in_file')]),
(inputnode, fmap2target, [('boldref2fmap_xfm', 'in1')]),
(gen_ref, fmap_recon, [('out_file', 'target_ref_file')]),
(boldref2target, fmap2target, [('out', 'in2')]),
(boldref2target, inverses, [('out', 'inlist')]),
(fmap_select, fmap_recon, [
("fmap_coeff", "in_coeffs"),
("fmap_ref", "fmap_ref_file"),
]),
(fmap2target, fmap_recon, [('out', 'transforms')]),
(inverses, fmap_recon, [('out', 'inverse')]),
# Inject fieldmap correction into resample node
(distortion_params, resample, [
("readout_time", "ro_time"),
("pe_direction", "pe_dir"),
]),
(fmap_recon, resample, [('out_file', 'fieldmap')]),
]) # fmt:skip
if not fieldmap_id:
return workflow

fmap_select = pe.Node(
KeySelect(fields=["fmap_ref", "fmap_coeff"], key=fieldmap_id),
name="fmap_select",
run_without_submitting=True,
)
distortion_params = pe.Node(
DistortionParameters(metadata=metadata),
name="distortion_params",
run_without_submitting=True,
)
fmap2target = pe.Node(niu.Merge(2), name='fmap2target')
inverses = pe.Node(niu.Function(function=_gen_inverses), name='inverses')

fmap_recon = pe.Node(ReconstructFieldmap(), name="fmap_recon")

workflow.connect([
(inputnode, fmap_select, [
("fmap_ref", "fmap_ref"),
("fmap_coeff", "fmap_coeff"),
("fmap_id", "keys"),
]),
(inputnode, distortion_params, [('bold_file', 'in_file')]),
(inputnode, fmap2target, [('boldref2fmap_xfm', 'in1')]),
(gen_ref, fmap_recon, [('out_file', 'target_ref_file')]),
(boldref2target, fmap2target, [('out', 'in2')]),
(boldref2target, inverses, [('out', 'inlist')]),
(fmap_select, fmap_recon, [
("fmap_coeff", "in_coeffs"),
("fmap_ref", "fmap_ref_file"),
]),
(fmap2target, fmap_recon, [('out', 'transforms')]),
(inverses, fmap_recon, [('out', 'inverse')]),
# Inject fieldmap correction into resample node
(distortion_params, resample, [
("readout_time", "ro_time"),
("pe_direction", "pe_dir"),
]),
(fmap_recon, resample, [('out_file', 'fieldmap')]),
]) # fmt:skip

return workflow

Expand Down

0 comments on commit 0d09cc0

Please sign in to comment.