Skip to content

Commit dc296de

Browse files
committed
Lint
1 parent 19677a1 commit dc296de

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

sdcflows/workflows/fit/pepolar.py

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
echo-planar imaging (EPI) references """
3434
_PEPOLAR_METHOD = "PEB/PEPOLAR (phase-encoding based / PE-POLARity)"
3535

36+
3637
def init_topup_wf(
3738
grid_reference=0,
3839
omp_nthreads=1,
@@ -92,7 +93,11 @@ def init_topup_wf(
9293

9394
from ...interfaces.bspline import TOPUPCoeffReorient
9495
from ...interfaces.epi import GetReadoutTime, SortPEBlips
95-
from ...interfaces.utils import PadSlices, ReorientImageAndMetadata, UniformGrid
96+
from ...interfaces.utils import (
97+
PadSlices,
98+
ReorientImageAndMetadata,
99+
UniformGrid,
100+
)
96101
from ...utils.misc import front as _front
97102
from ..ancillary import init_brainextraction_wf
98103

@@ -101,7 +106,9 @@ def init_topup_wf(
101106
{_PEPOLAR_DESC} with `topup` (@topup; FSL {TOPUP().version}).
102107
"""
103108

104-
inputnode = pe.Node(niu.IdentityInterface(fields=INPUT_FIELDS), name="inputnode")
109+
inputnode = pe.Node(
110+
niu.IdentityInterface(fields=INPUT_FIELDS), name="inputnode"
111+
)
105112
outputnode = pe.Node(
106113
niu.IdentityInterface(
107114
fields=[
@@ -139,19 +146,23 @@ def init_topup_wf(
139146
SortPEBlips(), name="sort_pe_blips", run_without_submitting=True
140147
)
141148
# Merge into one 4D file
142-
concat_blips = pe.Node(MergeSeries(affine_tolerance=1e-4), name="concat_blips")
149+
concat_blips = pe.Node(
150+
MergeSeries(affine_tolerance=1e-4), name="concat_blips"
151+
)
143152
# Pad dimensions so that they meet TOPUP's expectations
144153
pad_blip_slices = pe.Node(PadSlices(), name="pad_blip_slices")
145154
# Run 3dVolReg between runs: uses RobustAverage for consistency and to generate
146155
# debugging artifacts (typically, one wants to look at the average across uncorrected runs)
147-
setwise_avg = pe.Node(RobustAverage(num_threads=omp_nthreads), name="setwise_avg")
156+
setwise_avg = pe.Node(
157+
RobustAverage(num_threads=omp_nthreads), name="setwise_avg"
158+
)
148159
# The core of the implementation
149160
# Feed the input images in LAS orientation, so FSL does not run funky reorientations
150-
to_las = pe.Node(ReorientImageAndMetadata(target_orientation="LAS"), name="to_las")
161+
to_las = pe.Node(
162+
ReorientImageAndMetadata(target_orientation="LAS"), name="to_las"
163+
)
151164
topup = pe.Node(
152-
TOPUP(
153-
config=str(data.load(f"flirtsch/b02b0{'_quick' * sloppy}.cnf"))
154-
),
165+
TOPUP(config=str(data.load(f"flirtsch/b02b0{'_quick' * sloppy}.cnf"))),
155166
name="topup",
156167
)
157168
# "Generalize" topup coefficients and store them in a spatially-correct NIfTI file
@@ -160,7 +171,9 @@ def init_topup_wf(
160171
)
161172

162173
# Average the output
163-
ref_average = pe.Node(RobustAverage(num_threads=omp_nthreads), name="ref_average")
174+
ref_average = pe.Node(
175+
RobustAverage(num_threads=omp_nthreads), name="ref_average"
176+
)
164177

165178
# Sophisticated brain extraction of fMRIPrep
166179
brainextraction_wf = init_brainextraction_wf()
@@ -238,10 +251,8 @@ def init_topup_wf(
238251

239252

240253
def init_3dQwarp_wf(
241-
omp_nthreads=1,
242-
debug=False,
243-
sloppy=False,
244-
name="pepolar_estimate_wf"):
254+
omp_nthreads=1, debug=False, sloppy=False, name="pepolar_estimate_wf"
255+
):
245256
"""
246257
Create the PEPOLAR field estimation workflow based on AFNI's ``3dQwarp``.
247258
@@ -251,8 +262,8 @@ def init_3dQwarp_wf(
251262
``3dQwarp`` is used to generate a displacement field and correct
252263
the reference image. The workflow also returns an estimated fieldmap,
253264
which is the result of converting the displacement field to a fieldmap
254-
and then regularizing it with a bspline field. This means that the unwarped
255-
image is in general not what one would get by reconstructing the fieldmap
265+
and then regularizing it with a bspline field. This means that the unwarped
266+
image is in general not what one would get by reconstructing the fieldmap
256267
from fmap_coeff and warping the in_data.
257268
258269
Workflow Graph
@@ -276,11 +287,11 @@ def init_3dQwarp_wf(
276287
------
277288
in_data : :obj:`list` of :obj:`str`
278289
A list of two EPI files, the first of which will be taken as reference.
279-
The reference PhaseEncodingDirection should match the value for
290+
The reference PhaseEncodingDirection should match the value for
280291
in_reference.
281292
metadata : :obj:`list` of :obj:`dict`
282-
A list with length matching the length of in_data. Each element should be a
283-
dict with keys that are strings and values of any type. One key should be
293+
A list with length matching the length of in_data. Each element should be a
294+
dict with keys that are strings and values of any type. One key should be
284295
PhaseEncodingDirection and the values should be BIDS-valid codings.
285296
286297
Outputs
@@ -301,7 +312,9 @@ def init_3dQwarp_wf(
301312
"""
302313
from nipype.interfaces import afni
303314
from niworkflows.func.util import init_enhance_and_skullstrip_bold_wf
304-
from niworkflows.interfaces.fixes import FixHeaderRegistration as Registration
315+
from niworkflows.interfaces.fixes import (
316+
FixHeaderRegistration as Registration,
317+
)
305318
from niworkflows.interfaces.freesurfer import StructuralReference
306319
from niworkflows.interfaces.header import CopyHeader
307320

@@ -316,7 +329,6 @@ def init_3dQwarp_wf(
316329
from ...interfaces.utils import ConvertWarp, Flatten
317330
from ...utils.misc import front, last
318331

319-
320332
workflow = Workflow(name=name)
321333
workflow.__desc__ = f"""{_PEPOLAR_DESC} \
322334
with `3dQwarp` (@afni; AFNI {''.join(['%02d' % v for v in afni.Info().version() or []])}).
@@ -329,13 +341,15 @@ def init_3dQwarp_wf(
329341
outputnode = pe.Node(
330342
niu.IdentityInterface(
331343
fields=[
332-
"fmap",
333-
"fmap_ref",
334-
"fmap_mask",
335-
"fmap_coeff",
344+
"fmap",
345+
"fmap_ref",
346+
"fmap_mask",
347+
"fmap_coeff",
336348
"method",
337-
"out_warps"]),
338-
name="outputnode"
349+
"out_warps",
350+
]
351+
),
352+
name="outputnode",
339353
)
340354
outputnode.inputs.method = _PEPOLAR_METHOD
341355

@@ -347,7 +361,9 @@ def init_3dQwarp_wf(
347361

348362
flatten = pe.Node(Flatten(), name="flatten")
349363
sort_pe = pe.Node(
350-
niu.Function(function=_sorted_pe, output_names=["sorted", "qwarp_args"]),
364+
niu.Function(
365+
function=_sorted_pe, output_names=["sorted", "qwarp_args"]
366+
),
351367
name="sort_pe",
352368
run_without_submitting=True,
353369
)
@@ -499,11 +515,14 @@ def _sorted_pe(inlist):
499515
elif pe[0] == ref_pe[0]:
500516
out_opp.append(d)
501517
else:
502-
raise ValueError("Cannot handle orthogonal PE encodings.")
518+
msg = "Cannot handle orthogonal PE encodings."
519+
raise ValueError(msg)
503520

504521
return (
505522
[out_ref, out_opp],
506-
{"i": "-noYdis -noZdis", "j": "-noXdis -noZdis", "k": "-noXdis -noYdis"}[
507-
ref_pe[0]
508-
],
523+
{
524+
"i": "-noYdis -noZdis",
525+
"j": "-noXdis -noZdis",
526+
"k": "-noXdis -noYdis",
527+
}[ref_pe[0]],
509528
)

sdcflows/workflows/fit/tests/test_pepolar.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929

3030

3131
@pytest.mark.skipif(os.getenv("TRAVIS") == "true", reason="this is TravisCI")
32-
@pytest.mark.skipif(os.getenv("GITHUB_ACTIONS") == "true", reason="this is GH Actions")
33-
@pytest.mark.parametrize("ds", ("ds001771", "HCP101006"))
34-
@pytest.mark.parametrize("workflow", ("topup", "3dQwarp"))
32+
@pytest.mark.skipif(
33+
os.getenv("GITHUB_ACTIONS") == "true", reason="this is GH Actions"
34+
)
35+
@pytest.mark.parametrize("ds", ["ds001771", "HCP101006"])
36+
@pytest.mark.parametrize("workflow", ["topup", "3dQwarp"])
3537
def test_pepolar_wf(tmpdir, bids_layouts, workdir, outdir, ds, workflow):
3638
"""Test preparation workflow."""
3739
layout = bids_layouts[ds]

0 commit comments

Comments
 (0)