Skip to content

Commit 4f3723b

Browse files
committed
STY: black; adapt flake8 rules
1 parent 5bea3f1 commit 4f3723b

File tree

12 files changed

+73
-172
lines changed

12 files changed

+73
-172
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ max-line-length = 99
33
doctests = False
44
exclude=*build/
55
ignore =
6+
E203
67
W503
78
per-file-ignores =
89
**/__init__.py : F401

smriprep/__about__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626

2727
from ._version import __version__
2828

29-
__copyright__ = (
30-
"Copyright 2019, Center for Reproducible Neuroscience, Stanford University"
31-
)
29+
__copyright__ = "Copyright 2019, Center for Reproducible Neuroscience, Stanford University"
3230
__credits__ = [
3331
"Oscar Esteban",
3432
"Chris Gorgolewski",

smriprep/cli/run.py

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ def check_deps(workflow):
3737
return sorted(
3838
(node.interface.__class__.__name__, node.interface._cmd)
3939
for node in workflow._get_all_nodes()
40-
if (
41-
hasattr(node.interface, "_cmd")
42-
and which(node.interface._cmd.split()[0]) is None
43-
)
40+
if (hasattr(node.interface, "_cmd") and which(node.interface._cmd.split()[0]) is None)
4441
)
4542

4643

@@ -85,9 +82,7 @@ def get_parser():
8582
)
8683

8784
# optional arguments
88-
parser.add_argument(
89-
"--version", action="version", version=f"smriprep v{__version__}"
90-
)
85+
parser.add_argument("--version", action="version", version=f"smriprep v{__version__}")
9186

9287
g_bids = parser.add_argument_group("Options for filtering BIDS queries")
9388
g_bids.add_argument(
@@ -137,18 +132,15 @@ def get_parser():
137132
g_perfm.add_argument(
138133
"--low-mem",
139134
action="store_true",
140-
help="attempt to reduce memory usage (will increase disk usage "
141-
"in working directory)",
135+
help="attempt to reduce memory usage (will increase disk usage " "in working directory)",
142136
)
143137
g_perfm.add_argument(
144138
"--use-plugin",
145139
action="store",
146140
default=None,
147141
help="nipype plugin configuration file",
148142
)
149-
g_perfm.add_argument(
150-
"--boilerplate", action="store_true", help="generate boilerplate only"
151-
)
143+
g_perfm.add_argument("--boilerplate", action="store_true", help="generate boilerplate only")
152144
g_perfm.add_argument(
153145
"-v",
154146
"--verbose",
@@ -276,8 +268,7 @@ def get_parser():
276268
"--stop-on-first-crash",
277269
action="store_true",
278270
default=False,
279-
help="Force stopping on first crash, even if a work directory"
280-
" was specified.",
271+
help="Force stopping on first crash, even if a work directory" " was specified.",
281272
)
282273
g_other.add_argument(
283274
"--notrack",
@@ -395,22 +386,16 @@ def _warn_redirect(message, category, filename, lineno, file=None, line=None):
395386
from niworkflows.utils.misc import _copy_any
396387

397388
dseg_tsv = str(api.get("fsaverage", suffix="dseg", extension=[".tsv"]))
398-
_copy_any(
399-
dseg_tsv, str(Path(output_dir) / "smriprep" / "desc-aseg_dseg.tsv")
400-
)
401-
_copy_any(
402-
dseg_tsv, str(Path(output_dir) / "smriprep" / "desc-aparcaseg_dseg.tsv")
403-
)
389+
_copy_any(dseg_tsv, str(Path(output_dir) / "smriprep" / "desc-aseg_dseg.tsv"))
390+
_copy_any(dseg_tsv, str(Path(output_dir) / "smriprep" / "desc-aparcaseg_dseg.tsv"))
404391
logger.log(25, "sMRIPrep finished without errors")
405392
finally:
406393
from niworkflows.reports import generate_reports
407394
from ..utils.bids import write_derivative_description, write_bidsignore
408395

409396
logger.log(25, "Writing reports for participants: %s", ", ".join(subject_list))
410397
# Generate reports phase
411-
errno += generate_reports(
412-
subject_list, output_dir, run_uuid, packagename="smriprep"
413-
)
398+
errno += generate_reports(subject_list, output_dir, run_uuid, packagename="smriprep")
414399
write_derivative_description(bids_dir, str(Path(output_dir) / "smriprep"))
415400
write_bidsignore(Path(output_dir) / "smriprep")
416401
sys.exit(int(errno > 0))
@@ -458,13 +443,9 @@ def build_workflow(opts, retval):
458443
# First check that bids_dir looks like a BIDS folder
459444
bids_dir = opts.bids_dir.resolve()
460445
layout = BIDSLayout(str(bids_dir), validate=False)
461-
subject_list = collect_participants(
462-
layout, participant_label=opts.participant_label
463-
)
446+
subject_list = collect_participants(layout, participant_label=opts.participant_label)
464447

465-
bids_filters = (
466-
json.loads(opts.bids_filter_file.read_text()) if opts.bids_filter_file else None
467-
)
448+
bids_filters = json.loads(opts.bids_filter_file.read_text()) if opts.bids_filter_file else None
468449

469450
# Load base plugin_settings from file if --use-plugin
470451
if opts.use_plugin is not None:
@@ -552,9 +533,7 @@ def build_workflow(opts, retval):
552533
if opts.reports_only:
553534
from niworkflows.reports import generate_reports
554535

555-
logger.log(
556-
25, "Running --reports-only on participants %s", ", ".join(subject_list)
557-
)
536+
logger.log(25, "Running --reports-only on participants %s", ", ".join(subject_list))
558537
if opts.run_uuid is not None:
559538
run_uuid = opts.run_uuid
560539
retval["return_code"] = generate_reports(
@@ -644,9 +623,7 @@ def build_workflow(opts, retval):
644623
except (FileNotFoundError, CalledProcessError, TimeoutExpired):
645624
logger.warning("Could not generate CITATION.tex file:\n%s", " ".join(cmd))
646625
else:
647-
copyfile(
648-
pkgrf("smriprep", "data/boilerplate.bib"), str(log_dir / "CITATION.bib")
649-
)
626+
copyfile(pkgrf("smriprep", "data/boilerplate.bib"), str(log_dir / "CITATION.bib"))
650627
return retval
651628

652629

smriprep/interfaces/cifti.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ class _GenerateDScalarInputSpec(TraitedSpec):
1616
usedefault=True,
1717
desc="CIFTI surface target space",
1818
)
19-
grayordinates = traits.Enum(
20-
"91k", "170k", usedefault=True, desc="Final CIFTI grayordinates"
21-
)
19+
grayordinates = traits.Enum("91k", "170k", usedefault=True, desc="Final CIFTI grayordinates")
2220
scalar_surfs = traits.List(
2321
File(exists=True),
2422
mandatory=True,
@@ -36,11 +34,11 @@ class GenerateDScalar(SimpleInterface):
3634
"""
3735
Generate a HCP-style CIFTI-2 image from scalar surface files.
3836
"""
37+
3938
input_spec = _GenerateDScalarInputSpec
4039
output_spec = _GenerateDScalarOutputSpec
4140

4241
def _run_interface(self, runtime):
43-
4442
surface_labels, metadata = _prepare_cifti(self.inputs.grayordinates)
4543
self._results["out_file"] = _create_cifti_image(
4644
self.inputs.scalar_surfs,
@@ -87,14 +85,14 @@ def _prepare_cifti(grayordinates: str) -> ty.Tuple[list, dict]:
8785
"surface-den": "32k",
8886
"tf-res": "02",
8987
"grayords": "91,282",
90-
"res-mm": "2mm"
88+
"res-mm": "2mm",
9189
},
9290
"170k": {
9391
"surface-den": "59k",
9492
"tf-res": "06",
9593
"grayords": "170,494",
96-
"res-mm": "1.6mm"
97-
}
94+
"res-mm": "1.6mm",
95+
},
9896
}
9997
if grayordinates not in grayord_key:
10098
raise NotImplementedError(f"Grayordinates {grayordinates} is not supported.")
@@ -129,7 +127,7 @@ def _prepare_cifti(grayordinates: str) -> ty.Tuple[list, dict]:
129127
"SpatialReference": {
130128
"CIFTI_STRUCTURE_CORTEX_LEFT": surfaces_url % "L",
131129
"CIFTI_STRUCTURE_CORTEX_RIGHT": surfaces_url % "R",
132-
}
130+
},
133131
}
134132
return surface_labels, metadata
135133

smriprep/interfaces/freesurfer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class MRIsConvertData(fs.utils.MRIsConvert):
263263
Wraps mris_convert to automatically select the correct ?h.white surface if
264264
passed a file from the subject's surf/ directory
265265
"""
266+
266267
input_spec = _MRIsConvertDataInputSpec
267268

268269
def _gen_filename(self, name):

smriprep/interfaces/templateflow.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@
3939
class _TemplateFlowSelectInputSpec(BaseInterfaceInputSpec):
4040
template = traits.Str("MNI152NLin2009cAsym", mandatory=True, desc="Template ID")
4141
atlas = InputMultiObject(traits.Str, desc="Specify an atlas")
42-
cohort = InputMultiObject(
43-
traits.Either(traits.Str, traits.Int), desc="Specify a cohort"
44-
)
45-
resolution = InputMultiObject(
46-
traits.Int, desc="Specify a template resolution index"
47-
)
42+
cohort = InputMultiObject(traits.Either(traits.Str, traits.Int), desc="Specify a cohort")
43+
resolution = InputMultiObject(traits.Int, desc="Specify a template resolution index")
4844
template_spec = traits.DictStrAny(
4945
{"atlas": None, "cohort": None}, usedefault=True, desc="Template specifications"
5046
)
@@ -135,10 +131,9 @@ def _run_interface(self, runtime):
135131

136132
self._results["t1w_file"] = tf.get(name[0], desc=None, suffix="T1w", **specs)
137133

138-
self._results["brain_mask"] = (
139-
tf.get(name[0], desc="brain", suffix="mask", **specs)
140-
or tf.get(name[0], label="brain", suffix="mask", **specs)
141-
)
134+
self._results["brain_mask"] = tf.get(
135+
name[0], desc="brain", suffix="mask", **specs
136+
) or tf.get(name[0], label="brain", suffix="mask", **specs)
142137
return runtime
143138

144139

smriprep/utils/bids.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ def _normalize_q(query, space=None):
101101
query["to"] = output_spaces
102102
return query
103103

104-
queries = [
105-
_normalize_q(q, space=None) for q in spec["queries"]["baseline"].values()
106-
]
104+
queries = [_normalize_q(q, space=None) for q in spec["queries"]["baseline"].values()]
107105

108106
queries += [
109107
_normalize_q(q, space=s)

smriprep/workflows/anatomical.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ def init_anat_preproc_wf(
232232
)
233233

234234
inputnode = pe.Node(
235-
niu.IdentityInterface(
236-
fields=["t1w", "t2w", "roi", "flair", "subjects_dir", "subject_id"]
237-
),
235+
niu.IdentityInterface(fields=["t1w", "t2w", "roi", "flair", "subjects_dir", "subject_id"]),
238236
name="inputnode",
239237
)
240238

@@ -263,27 +261,22 @@ def init_anat_preproc_wf(
263261
if existing_derivatives is not None:
264262
LOGGER.log(
265263
25,
266-
"Anatomical workflow will reuse prior derivatives found in the "
267-
"output folder (%s).",
264+
"Anatomical workflow will reuse prior derivatives found in the output folder (%s).",
268265
output_dir,
269266
)
270267
desc += """
271268
Anatomical preprocessing was reused from previously existing derivative objects.\n"""
272269
workflow.__desc__ = desc
273270

274271
templates = existing_derivatives.pop("template")
275-
templatesource = pe.Node(
276-
niu.IdentityInterface(fields=["template"]), name="templatesource"
277-
)
272+
templatesource = pe.Node(niu.IdentityInterface(fields=["template"]), name="templatesource")
278273
templatesource.iterables = [("template", templates)]
279274
outputnode.inputs.template = templates
280275

281276
for field, value in existing_derivatives.items():
282277
setattr(outputnode.inputs, field, value)
283278

284-
anat_reports_wf.inputs.inputnode.source_file = [
285-
existing_derivatives["t1w_preproc"]
286-
]
279+
anat_reports_wf.inputs.inputnode.source_file = [existing_derivatives["t1w_preproc"]]
287280

288281
stdselect = pe.Node(
289282
KeySelect(fields=["std_preproc", "std_mask"], keys=templates),
@@ -322,11 +315,7 @@ def init_anat_preproc_wf(
322315
desc += """\
323316
with `N4BiasFieldCorrection` [@n4], distributed with ANTs {ants_ver} \
324317
[@ants, RRID:SCR_004757]"""
325-
desc += (
326-
".\n"
327-
if num_t1w > 1
328-
else ", and used as T1w-reference throughout the workflow.\n"
329-
)
318+
desc += ".\n" if num_t1w > 1 else ", and used as T1w-reference throughout the workflow.\n"
330319

331320
desc += """\
332321
The T1w-reference was then skull-stripped with a *Nipype* implementation of
@@ -357,9 +346,7 @@ def init_anat_preproc_wf(
357346
contrast="T1w",
358347
)
359348

360-
anat_validate = pe.Node(
361-
ValidateImage(), name="anat_validate", run_without_submitting=True
362-
)
349+
anat_validate = pe.Node(ValidateImage(), name="anat_validate", run_without_submitting=True)
363350

364351
# 2. Brain-extraction and INU (bias field) correction.
365352
if skull_strip_mode == "auto":

smriprep/workflows/base.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ def init_smriprep_wf(
193193
for node in single_subject_wf._get_all_nodes():
194194
node.config = deepcopy(single_subject_wf.config)
195195
if freesurfer:
196-
smriprep_wf.connect(
197-
fsdir, "subjects_dir", single_subject_wf, "inputnode.subjects_dir"
198-
)
196+
smriprep_wf.connect(fsdir, "subjects_dir", single_subject_wf, "inputnode.subjects_dir")
199197
else:
200198
smriprep_wf.add_nodes([single_subject_wf])
201199

@@ -360,13 +358,9 @@ def init_single_subject_wf(
360358
Path(output_dir) / "smriprep", subject_id, std_spaces, freesurfer
361359
)
362360

363-
inputnode = pe.Node(
364-
niu.IdentityInterface(fields=["subjects_dir"]), name="inputnode"
365-
)
361+
inputnode = pe.Node(niu.IdentityInterface(fields=["subjects_dir"]), name="inputnode")
366362

367-
bidssrc = pe.Node(
368-
BIDSDataGrabber(subject_data=subject_data, anat_only=True), name="bidssrc"
369-
)
363+
bidssrc = pe.Node(BIDSDataGrabber(subject_data=subject_data, anat_only=True), name="bidssrc")
370364

371365
bids_info = pe.Node(
372366
BIDSInfo(bids_dir=layout.root), name="bids_info", run_without_submitting=True

smriprep/workflows/norm.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ def init_anat_norm_wf(
137137
ants_ver=ANTsInfo.version() or "(version unknown)",
138138
targets="%s standard space%s"
139139
% (
140-
defaultdict(
141-
"several".format, {1: "one", 2: "two", 3: "three", 4: "four"}
142-
)[ntpls],
140+
defaultdict("several".format, {1: "one", 2: "two", 3: "three", 4: "four"})[ntpls],
143141
"s" * (ntpls != 1),
144142
),
145143
targets_id=", ".join(templates),
@@ -230,9 +228,7 @@ def init_anat_norm_wf(
230228
std_dseg = pe.Node(ApplyTransforms(interpolation="MultiLabel"), name="std_dseg")
231229

232230
std_tpms = pe.MapNode(
233-
ApplyTransforms(
234-
dimension=3, default_value=0, float=True, interpolation="Gaussian"
235-
),
231+
ApplyTransforms(dimension=3, default_value=0, float=True, interpolation="Gaussian"),
236232
iterfield=["input_image"],
237233
name="std_tpms",
238234
)

0 commit comments

Comments
 (0)