Skip to content

Commit 4941bf0

Browse files
DimitriPapadopouloseffigies
authored andcommitted
STY: Use f-strings where possible
As suggested by `pyupgrade --py38-plus`: https://github.com/asottile/pyupgrade#f-strings
1 parent 9d278a2 commit 4941bf0

File tree

16 files changed

+39
-43
lines changed

16 files changed

+39
-43
lines changed

niworkflows/interfaces/bids.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,12 @@ def _run_interface(self, runtime):
269269

270270
if self._require_t1w and not bids_dict['t1w']:
271271
raise FileNotFoundError(
272-
"No T1w images found for subject sub-{}".format(self.inputs.subject_id)
272+
f"No T1w images found for subject sub-{self.inputs.subject_id}"
273273
)
274274

275275
if self._require_funcs and not bids_dict["bold"]:
276276
raise FileNotFoundError(
277-
"No functional images found for subject sub-{}".format(
278-
self.inputs.subject_id
279-
)
277+
f"No functional images found for subject sub-{self.inputs.subject_id}"
280278
)
281279

282280
for imtype in ["bold", "t2w", "flair", "fmap", "sbref", "roi", "pet", "asl"]:

niworkflows/interfaces/cifti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,6 @@ def _create_cifti_image(
400400
img.set_data_dtype(bold_img.get_data_dtype())
401401
img.nifti_header.set_intent("NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES")
402402

403-
out_file = "{}.dtseries.nii".format(split_filename(bold_file)[1])
403+
out_file = f"{split_filename(bold_file)[1]}.dtseries.nii"
404404
ci.save(img, out_file)
405405
return Path.cwd() / out_file

niworkflows/interfaces/confounds.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def spike_regressors(
319319
spikes = np.zeros((max(indices) + 1, len(mask)))
320320
for i, m in enumerate(sorted(mask)):
321321
spikes[m, i] = 1
322-
header = ["{:s}{:02d}".format(header_prefix, vol) for vol in range(len(mask))]
322+
header = [f"{header_prefix}{vol:02d}" for vol in range(len(mask))]
323323
spikes = pd.DataFrame(data=spikes, columns=header)
324324
if concatenate:
325325
return pd.concat((data, spikes), axis=1)
@@ -360,7 +360,7 @@ def temporal_derivatives(order, variables, data):
360360
variables_deriv[0] = variables
361361
order = set(order) - set([0])
362362
for o in order:
363-
variables_deriv[o] = ["{}_derivative{}".format(v, o) for v in variables]
363+
variables_deriv[o] = [f"{v}_derivative{o}" for v in variables]
364364
data_deriv[o] = np.tile(np.nan, data[variables].shape)
365365
data_deriv[o][o:, :] = np.diff(data[variables], n=o, axis=0)
366366
variables_deriv = reduce(operator.add, variables_deriv.values())
@@ -403,7 +403,7 @@ def exponential_terms(order, variables, data):
403403
variables_exp[1] = variables
404404
order = set(order) - set([1])
405405
for o in order:
406-
variables_exp[o] = ["{}_power{}".format(v, o) for v in variables]
406+
variables_exp[o] = [f"{v}_power{o}" for v in variables]
407407
data_exp[o] = data[variables] ** o
408408
variables_exp = reduce(operator.add, variables_exp.values())
409409
data_exp = pd.DataFrame(

niworkflows/interfaces/fixes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
6868
_copyxform(
6969
self.inputs.reference_image,
7070
os.path.abspath(self._gen_filename("output_image")),
71-
message="%s (niworkflows v%s)" % (self.__class__.__name__, __version__),
71+
message=f"{self.__class__.__name__} (niworkflows v{__version__})",
7272
)
7373
return runtime
7474

@@ -110,7 +110,7 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
110110
_copyxform(
111111
self.inputs.fixed_image[0],
112112
os.path.abspath(out_file),
113-
message="%s (niworkflows v%s)" % (self.__class__.__name__, __version__),
113+
message=f"{self.__class__.__name__} (niworkflows v{__version__})",
114114
)
115115

116116
# Inverse transform
@@ -119,7 +119,7 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
119119
_copyxform(
120120
self.inputs.moving_image[0],
121121
os.path.abspath(out_file),
122-
message="%s (niworkflows v%s)" % (self.__class__.__name__, __version__),
122+
message=f"{self.__class__.__name__} (niworkflows v{__version__})",
123123
)
124124

125125
return runtime

niworkflows/interfaces/freesurfer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def medial_wall_to_nan(in_file, subjects_dir, den=None, newpath=None):
552552
if target_subject.startswith("fsaverage"):
553553
cortex = nb.freesurfer.read_label(
554554
os.path.join(
555-
subjects_dir, target_subject, "label", "{}.cortex.label".format(fn[:2])
555+
subjects_dir, target_subject, "label", f"{fn[:2]}.cortex.label"
556556
)
557557
)
558558
medial = np.delete(np.arange(len(func.darrays[0].data)), cortex)
@@ -578,7 +578,7 @@ def mri_info(fname, argument):
578578
import subprocess as sp
579579
import numpy as np
580580

581-
cmd_info = "mri_info --%s %s" % (argument, fname)
581+
cmd_info = f"mri_info --{argument} {fname}"
582582
proc = sp.Popen(cmd_info, stdout=sp.PIPE, shell=True)
583583
data = bytearray(proc.stdout.read())
584584
mstring = np.fromstring(data.decode("utf-8"), sep="\n")

niworkflows/interfaces/header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def _run_interface(self, runtime):
315315
Analyses of this dataset MAY BE INVALID.
316316
</p>
317317
"""
318-
snippet = '<h3 class="elem-title">%s</h3>\n%s\n' % (warning_txt, description)
318+
snippet = f'<h3 class="elem-title">{warning_txt}</h3>\n{description}\n'
319319
# Store new file and report
320320
img.to_filename(out_fname)
321321
with open(out_report, "w") as fobj:

niworkflows/interfaces/nibabel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def _run_interface(self, runtime):
432432
self.inputs.moving_image,
433433
fov_mask=self.inputs.fov_mask,
434434
force_xform_code=self.inputs.xform_code,
435-
message="%s (niworkflows v%s)" % (self.__class__.__name__, __version__),
435+
message=f"{self.__class__.__name__} (niworkflows v{__version__})",
436436
newpath=runtime.cwd,
437437
)
438438
return runtime

niworkflows/interfaces/tests/test_bids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def test_ReadSidecarJSON_connection(testdata_dir, field):
652652
"derivatives, subjects_dir",
653653
[
654654
(os.getenv("FREESURFER_HOME"), "subjects"),
655-
("/tmp", "%s/%s" % (os.getenv("FREESURFER_HOME"), "subjects")),
655+
("/tmp", "{}/{}".format((os.getenv("FREESURFER_HOME"), "subjects"))),
656656
],
657657
)
658658
def test_fsdir_noaction(derivatives, subjects_dir):

niworkflows/interfaces/utility.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ def _check_len(self, name, new):
201201
if name in self._fields:
202202
if isinstance(new, str) or len(new) < 1:
203203
raise ValueError(
204-
'Trying to set an invalid value (%s) for input "%s"' % (new, name)
204+
f'Trying to set an invalid value ({new}) for input "{name}"'
205205
)
206206

207207
if len(new) != len(self.inputs.keys):
208208
raise ValueError(
209-
'Length of value (%s) for input field "%s" does not match '
210-
"the length of the indexing list." % (new, name)
209+
f'Length of value ({new}) for input field "{name}" '
210+
"does not match the length of the indexing list."
211211
)
212212

213213
def _run_interface(self, runtime):

niworkflows/reports/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def _load_config(self, config):
303303
self.out_dir = self.out_dir / self.packagename
304304

305305
if self.subject_id is not None:
306-
self.root = self.root / "sub-{}".format(self.subject_id)
306+
self.root = self.root / f"sub-{self.subject_id}"
307307

308308
if "template_path" in settings:
309309
self.template_path = config.parent / settings["template_path"]
@@ -371,7 +371,7 @@ def index(self, config):
371371

372372
# Populate errors section
373373
error_dir = (
374-
self.out_dir / "sub-{}".format(self.subject_id) / "log" / self.run_uuid
374+
self.out_dir / f"sub-{self.subject_id}" / "log" / self.run_uuid
375375
)
376376
if error_dir.is_dir():
377377
from ..utils.misc import read_crashfile

0 commit comments

Comments
 (0)